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.
Related
Through Maven, I have the source code and JavaDoc both downloaded for libraries used by my code.
I want to select a class name called in my code in the IntelliJ code editor, and then ask IntelliJ to show me the source code for that particular class.
Bonus: Show the JavaDoc for that class.
I thought F1 key would do this, but no so.
If a keyboard shortcut is required, please indicate the macOS version as well as the PC version if known.
Hold Command key, hover mouse, and click
On a Mac, hold down the Command key. Notice as you move the mouse pointer, the class names change to blue underscored text like an old-school web page link. Click that retro-link while holding down Command.
I am guessing, per comment by Justice, that on a PC you would hold down Control key while hovering/clicking.
No need to select the class name.
Before, no keys pressed
After, pressing Command while hovering mouse pointer
Click the apparent link to open the local copy of class source code.
This approach worked on IntelliJ 2018.1 on macOS Sierra.
Pressing CTRL+N will open a text box where you can search for the class by name, and then open it, regardless of whether it's a class that's part of your project's sources or a library you use. If you have the library's source downloaded, IntelliJ IDEA will show you that instead of the decompiled binary of the class.
COMMAND+B is used to show source code after selecting the class or interface for IntelliJ Users.
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.
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)
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.
A friend is just starting to learn Java, using IntelliJ.
He asks how can he set up some template so creating a new project will contain a default main class.
Currently, when he creates a new project, it has no source files, and he has to add a Run/Debug application configuration manually, and then select the main class.
I don't know if Settings->File Templates is what you have in mind, but I'll point it out just in case.
You can easily create a class and add a main method by typing "psvm " and filling in the method body. You run it by right clicking on the class and selecting "Run". It's automatically be added to your Run/Config list, you just have to save it to make it permanent.
But my gut feeling is that IntelliJ has no such a feature for reading somebody's mind about a "default main class", nor should it.
In the resources tree, right click on the class you want to be main and there should be item in the context menu like "Create main for xyz".