Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Highlighting all derived data members

Is there any editor for Java that is capable of highlighting all inherited members? It seems to be a very useful feature to aid in understanding the structure of the derived class that accesses members of the base class(es). I'm personally using Intellij-IDEA and if you are aware of any way to that there, please do share. All other editors are welcome!

For example you can sometimes see the following scenario (and please do not consider this example serious).

class A {
    ...
    protected int a;
    protected int x;
    ...
}

class B extends A {
    ...
    protected int b;
    void isntThatCoolIfSomeoneOverridesA() {
        a = b;
        x = b * b;
    }
    ...
}

UPDATE: extended the example

The usage of a and x in class B needs to be highlighted, because both are the inherited data members of class A.

like image 682
Leonid Avatar asked May 27 '11 18:05

Leonid


3 Answers

Eclipse:

It is possible to highlight invocations of inherited methods, but not for fields. You may turn this on in Preferences dialog, under Java -> Editor -> Syntax Coloring. In elements list view, choose Java -> Inherited method invocations, check Enable and edit how it should be highlighted.

like image 162
OndroMih Avatar answered Nov 12 '22 18:11

OndroMih


NetBeans: Right-click -> Navigate -> Inspect hieararchy
You can also switch the logic - top-down or bottom-up

Non-editor options:

  • JavaDoc - see the TREE link
  • Also check JBoss Tattletale.
like image 1
Ondra Žižka Avatar answered Nov 12 '22 19:11

Ondra Žižka


IntelliJ:

If the classes are defined in the same source file, the normal variable highlighting does this. You can highlight on demand using Search -> Highlight Usages in File. Alternatively, enable Settings -> Editor -> Highlight usages of element at caret) to always highlight the element in which the editor caret is placed.

Search -> Find Usages is often more useful, as it searches a scope (typically the project sources) for usages of a variable, field, member, class ...

like image 1
jackrabbit Avatar answered Nov 12 '22 18:11

jackrabbit