How to find forward reference in eclipse? - java

Is there any way by which I can find out all classes which implement a particular interface?
For example, if I have a interface as follows:
public interface myIntFac{}
I want to find all classes inside current project that implement this interface. How can I find it out in Eclipse?

At the interface level, you can use (assuming the cursor in on the interface)
CTRL+T to show the Quick Type Hierarchy
F4 to Open Type Hierarchy
At the method level, if you hover a method while holding down the control key, a pop-up box gives you the following choices:
Open Declaration
Open Implementation
(source: eclipse.org)
And from anywhere, you can use:
CTRL+SHIFT+H to open the Open Type Hierarchy pop-up and search for any type/interface.

Place your cursor on the interface, and try Ctrl-T.

Put your cursor in myIntFac and press F4 to show the type hierarchy as a separate window, or Ctrl-T to show it as a pop-up. Personally I like the "separate window" approach as it makes it easier to browse, refocus on a different type etc - but if you only want to show the hierarchy very briefly, the pop-up is good too.

Related

The code behind filesystem.normalize

I'm new to Java and OOP. I have a strange disorder that makes me extremely curious how things work. So I copied this code that use normalize() and I'm trying to get the source code of it but all I found is
public abstract String normalize(String path);
In:
FileSystem.java file
Of course, know what it does. But I'm curious how and why i cant find the code behind it.
Thank you
Michal
If you are using an IDE (like Eclipse), you can use it to find the concrete implementations of that method.
In Eclipse:
Ctrl + Shift + T and type java.io.FileSystem; click "OK"
Hover over the normalize method name. A menu will appear like below.
Click "Open Implementation"
If there is more than one implementation available, you will see a list. Click on the one you want to open.
If there is only one, then that single implementation will be opened automatically.

Shortcut to see class hierarchy in Eclipse

I have one query that is I am using eclipse and I have imported the project and as usual in a project there are 30 to 40 packages and each package contains set of classes , Now say in package named A I have a class Named abc and in later subpackages ,let say in package named W i have extended and override some of the methods of that class(abc) and construct a new class named def which extend the parent class abc, now please let me let me know I have opened the parent class abc in eclipse is there any shortcut through which I can find out which subclasses in later package overrides it's method and which subclasses are extending it..!
Yes: When your cursor is on the class name (as in: public class A|bc), you can press Ctrl+T to see the inheritance hierarchy of Abc.
If you press CTRL-T twice, it will show you the supertype hierarchy, which also includes any Interfaces that your class implements. Occasionally very useful.
Also,
Right click on the file in the project explorer -> Open type hierarchy.
Same works for right click on the class name in editor window.
Shortcut is F4.
Also, apart from worthy shortcut that Aaron posted, you can also do this: -
Go to Windows -> Show Views -> Open Outline view (If not found - go to Others)
It will open an Outline View which shows your class hierarchy of your current class

How to view class package type and parameters in IntelliJ?

When hovering your mouse over a Class or variable, how come I don't see any information on the type of the class?
Is this not a feature in IntelliJ?
For example, in vs.net, if I mouse over any variable or class it will popup and tell me what namespace that belongs to etc.
And when I am using a method of a class, it also tells me the different overloads for the method (like types for each parameter, and a list of all the overloads).
This must be a feature in IntelliJ, I just don't know how to get it.
Can someone please clear this up?
Also, how can I tidy up the formatting of a page?
It doesn't work on hover yet, please star/vote the issue.
You need to use keyboard shortcuts for quick documentation pop-up or parameter info pop-up (Ctrl+Q and Ctrl+P with default Windows keymap, F1 and Cmd+P with default OS X 10.5+ keymap).
Code | Reformat Code... is the answer to your second question.
Formatting: Code -> Reformat (shortcut: Ctrl-Alt-L)
Hover doesn't produce the kind of information I'd like either. You can get info with Ctrl-Q ("Quick Help") in Windows or F1 in OS X, which will show where it's from and what it is, with most stuff in the popup window linked up in a reasonable way.
That popup view can also be pinned and/or docked; I often have it docked on the bottom.

How to get eclipse to go to the ONLY implementation of an interface's method?

If I'm in an interface and pointing to a method name, what can I do to quickly go to the ONLY implementation of that method?
Using Eclipse 3.6.
F3 is the typical "go to implementation". For interfaces that go to the interface definition.
Instead use Ctrl + T to see all implementations of the interface definition. You can then easily go to the one you want with the arrow keys and Enter. I believe that the first one is automatically selected so that Ctrl-T + Enter will do what you need.
I just checked this on my Eclipse 3.6 install: Hold control (command on Mac), hover over the method name and select "Open Implementation".
You may assign a keyboard shortcut to this action by using Window > Preferences > General > Keys and searching for "Open Implementation".
In the keymap (General > Keys) search for "open implementation" and map it to whatever you want. I chose Ctrl + Shift + I. Make sure you select "Editing Java Source" in the When box. I tested it, and having the cursor over the method name and pressing Ctrl + Shift + I took me directly to the implementation instead of showing the hierarchy that you get with Ctrl + T.
Also you can see an answer to a nearly identical question for other options:
In eclipse, ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly to that implementation?
If someone still need this information nowadays (Eclipse version 2022), to jump into interface method definition starting from an #Override method, now in Eclipse you can see on the left, next to the method signature, a little white triangle. By clicking on that you will jump to the implemented interface method. here an image of the little triangle
Oterwise, if you are on a interface method definition and you need to jump to one of the implementations, you must use CTRL+T shortcut to see the list of available implementations and than click on one of them.

Search by Implementation class in eclipse

Can one search by the implementation or its methods in eclipse? It would be really useful.
An example is given below.
public interface Foo {
public void method();
}
public class FooImpl implements Foo {
// I should be able to select this and search and it should
// show the whoever called Foo.method
public void method() {
}
}
If you see a method, called from interface, then just position mouse cursor over it, press ctrl and you see menu with options "Open Declaration | Open Implementation". In your case press "Open Implementation".
In case this method is implemented by many classes you will get a popup with "Types implementing or defining...". Quite nice feature :)
UPDATE: according to your example... If I understood it right, then when you select method, press ctrl+shift+G and you see all places where this method is called.
Select "Foo" in the editor -> right-click -> Open Type Hierarchy (or F4). The "Type Hierarchy" View will open -> On this View, click the icon for the function "Show the Sub-Type Hierarchy" (or "Show All Inherited Members").
Eclipse will show all the Child classes.
Another method is mentioned in this post. Instead of using CTRL+H or CTRL+SHIFT+G you can use CTRL+T to open a pop-up in place instead of a new Eclipse tab as the other methods do.
You can use default search option. Access it by pressing CTRL+H. Go to Java search tab. Here you can write method name and search for it.

Categories