How to find which classes implement a particular interface in Eclipse? - java

I have an application as JAR file with many dependencies. For some reason I need to decompile one of the libraries and open it up with Eclipse. For a given interface in the project, is there a way to find the class(s) that implements it? It may be the case that the interface was implemented in other library that I didn't decompile yet. Is it possible to do this for this kind of classes?

Right-click on the interface, and choose "Open type hierarchy". Then click on "Show the subtype hierarchy".

Try Ctrl+T after selecting the classname; should work in Java Perspective.

You can "Show Type Hierarchy" on the item (Right Click to choose this option or press F4 when the item is highlighted)*.
However, this will list only items in those projects that are referred ("dependent"). Not in others.
So if you have decompiled a jar, and there is another jar that you have not decompiled, then the implementations (of the interface) in that jar will not be listed.
Also, say you have decompiled a jar as a project and there is another project that is referring to the jar, and not the decompiled project, implementations in that will also not be listed.
So you will have to decompile all jars and add them as projects (and add references via "Java Build Path") to make sure all the implementations in the jars of your choice are listed.
* Quick type Hierarchy, ctrl + T will show a similar structure in a tooltip/autocomplete kind of panel. But the complete type hierarchy is more useful for the type of analysis you are intending to do.

There is radio-button "Implementors" in Java Search.

Or right-click and select Quick Type Hierarchy for a pulldown menu of extending interfaces and implementing classes.

Ctrl + H (Search Option) Open Java Search perspective and, enter the interface name, click Implementors radio button and you will find which classes implement a particular interface. Same as answer from stackexchanger above

Select the class name, then 'F4' in Eclipse (Windows environment)

Related

Eclipse interface link to open related files

This is not a code-related, but a pure IDE work efficiency question.
Is there any Eclipse plugin or built-in feature to provide "links" (shortcuts) to open other relevant .java files in the current project (or any files for that matter) from within a file.
To be more specific, here is an example of what I want to do:
I added new functionality to a class called MyClass in my project.
I also have a unit test file for that class called MyClassTest within another "test" project under a parent project.
Now I want to jump to MyClassTest.java and add new unit tests.
I'm lazy so I don't want to browse with the mouse in the Project Explorer (too many packages) and don't want to press Ctrl+Shift+T and type the class name.
I want some sort of shortcut planted in MyClass.java (or even a side panel window) which when clicked, opens MyClassTest.java for me.
This can be useful for the programmer to "link" related files (.xml, .java, .jsp) so he/she can open them quicker.
The MoreUnit plugin solves exactly this problem for unit tests. You press Ctrl-J while in a class to jump to its test class (and vice versa).
It even simplifies the process of creating the test class in the first place, with naming conventions and method stubs.
Typically in your described scenario I will right click on the "MyClass" (the text name in source) and go "References -> Workspace". This will show me all other "related" classes referring to MyClass. I can then double click on any of them to open which have appeared in the bottom search tab.
This also works great on methods to find out who is using the method in a particular class.
You can make the "Open type" dialog work more easily in this case, if you have selected the name of the current class before opening the dialog. Your current class name is then already filled in.
Then hit End or Cursor right in the open type dialog to remove the selection, type T (for Test) and hit Enter to open the test class.

Eclipse Hotkey to quickly locate a package

It's like "Ctrl-shift-T" combination, but for package name instead of class name. I have a project with lots of hierarchy package, and when I need to add a new class, it's hard to find the right one.
I think there must be some way in Eclipse to quickly navigate to a package. Does anyone know about this thing?
1) Open Eclipse->windows->Preferecnces->General->Keys
2) Find the Entry Goto Package
3) If not configured, configure it witha key config like Cntrl+Shift+G it should be in the In Windows type. Now Click Ok..
4) Get your work done with that key combination
I don't think there is a standard way of doing this. As a hint I could propose using:
Ctrl+Shift+T together with wildcards.
Suppose we have the same class in two different packages:
com.mycompany.myapp.foo.bar.MyClass
and
com.mycompany.myapp.baz.bar.MyClass
using: *baz*.MyClass inside Open Type window will do the trick (open the second class inside Eclipse editor).
Now assuming you have Link with editor option enabled, now whenever you press Ctrl+Shift+N to create a new class, your package will be filled automatically from the resource previously opened.

How do I open an included java class(for example JButton) in IntelliJ IDEA 10?

I want to be able to open up the JButton class and see the code inside it. The reason is because I want to override one of the methods, but I want to make sure I include all the functionality that that method normally has. Also, it'd be a good way to learn. I know I can do it when I've had errors by clicking on the class in the error messages. But any ideas on how to bring it up normally?
Go To | Class (Ctrl+N), type JButton (Include non-project classes checkbox will be enabled automatically if no such classes are found in your project).
If you already have JButton usage in your code, you can navigate to its source using Ctrl+B while the caret is on it.
Of course you need sources attached to the JSDK, but it should be fine by default (as JSDK installation has sources on most platforms). If you are on Mac, you will have to download them separately and attach to the JSDK configuration in File | Project Structure | SDKs.
If you have sources just press Ctrl+B on JButton, if you have no, download sources, add to configuration of project and press the same combination
Download the Java Source code here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
Also don't forget about the super keyword which you can use to interact with the extended class
You need to download the Java source code. If you're using Java 1.6, for example, you can go here to get it. Unzip it somewhere on your local disk.
When I need to look at the source code of a Java class I then navigate to the source class and drag it into my IDE.
If you want to ensure you get all the functionality of the original method, call the original method as part of your method. Using super gives you a reference to the overridden method, e.g. super.overridden();. Don't just copy the Java source into your method.

How to import existing project into Workplace in Eclipse?

I am trying to follow Eclipse instructions to create a Hello World SWT application. I have the following instruction:
Import the SWT project from the main
menu via File > Import..., and select
Existing Projects into Workspace.
Specify the archive file you
downloaded and click Finish. This will
create the org.eclipse.swt project
which we will need to compile and run
the application.
I have troubles with that. In the "File" menu I see "Import...". When I click the "Import...", I do not see "Existing Project into Workspace". Instead of that I see "Select an import source:" after which I see a text field. After that I see a field with the following folders: General, CVS, Run/Debug, Tasks, Team, XML.
Can anybody help me with that, pleas?
You need to expand General.
If you expand the 'General' node (folder) you will see 'Existing projects into workspace' as an option. Select that and click on Next.
Eclipse has the wonderful search functionality on most of its important screens. Even if you don't know where exactly it is, you can type it and it appears. In this case type "Existing" into the text field above the list and you'll see what you are looking for.

Eclipse package explorer have different icons for each file type: interfaces, abstract classes, etc

Does anyone know of an eclipse plugin that changes the file icon used by the package explorer to something that indicates type? It would be handy if the icon looked different for interfaces, abstract classes, enum, and concrete classes.
You can enable a feature in Eclipse similar to what you are describing. Open Window > Preferences > General > Appearance > Label Decorations. Then check the box for Java Type Indicator. I do not know of any plug-ins that give you more control.

Categories