To reopen a closed project, in the Package Explorer view, select the closed project and click on the Project menu and select Open Project. Once the project is open its content can be edited using the Eclipse user interface.
Eclipse shows hidden files in the "Navigator" view. You can add that via Window->Show View->Navigator. With Eclipse 4.14 for Mac OS X: Window > Navigation > Show View Menu > Filters ans Customization, then after just uncheck .
Press Alt + - to open the system menu, and then press C to close the view.
To close a project, select the project select then go to Project menu and select close project.
Don't forget Ctrl+Shift+L, which displays a list of all the keyboard shortcut combinations (just in case you forget any of those listed here).
Seems that nobody mentioned Ctrl-2 L (assign to new local variable) and Ctrl-2 F (assign to a new field), these ones have changed how I write code.
Previously, I was typing, say (| is cursor location):
Display display = new |
and then I pushed Ctrl-Space to complete the constructor call. Now I type:
new Display()|
and press Ctrl-2 L, which results in:
Display display = new Display()|
This really speeds things up. (Ctrl-2 F does the same, but assigns to a new field rather than a new variable.)
Another good shortcut is Ctrl-2 R: rename in file. It is much faster than rename refactoring (Alt-Shift-R) when renaming things like local variables.
Actually I went to Keys customization preference page and assigned all sorts of additional quick fixes to Ctrl-2-something. For example I now press Ctrl-2 J to split/join variable declaration, Ctrl-2 C to extract an inner class into top-level, Ctrl-2 T to add throws declaration to the function, etc. There are tons of assignable quick fixes, go pick your favourite ones and assign them to Ctrl-2 shortcuts.
Another favourite of mine in my “npe” template, defined as:
if (${arg:localVar} == null)
throw new ${exception:link(NullPointerException,IllegalArgumentException)}("${arg:localVar} is null");
This allows me to quickly add null argument checks at the start of every function (especially ones that merely save the argument into a field or add it into a collection, especially constructors), which is great for detecting bugs early.
See more useful templates at www.tarantsov.com/eclipse/templates/. I won't list them all here because there are many, and because I often add new ones.
A few code completion tricks:
This is how I add fields.
If you have no constructors yet, add one. (Ctrl-Space anywhere in a class declaration, pick the first proposal.)
Add an argument (| is cursor position):
public class MyClass {
public MyClass(int something|) {
}
}
Press Ctrl-1, choose “assign to a new field”. You get:
public class MyClass {
private final Object something;
public MyClass(Object something) {
this.something = something;
}
}
Add a null-pointer check if appropriate (see “npe” template above):
public class MyClass {
private final Object something;
public MyClass(Object something) {
npe|
this.something = something;
}
}
Hit Ctrl-Space, get:
public class MyClass {
private final Object something;
public MyClass(Object something) {
if (something == null)
throw new NullPointerException("something is null");
this.something = something;
}
}
A great time saver!
ctrl-shift-r and its buddy, ctrl-shift-t, to open a resource or type, respectively. Resources includes all files in your open projects (including non-java files), and types includes java types either in your projects, or in a library included in the projects.
Crtl+1 is my favorite. The quick fixes for the red-squiggles.
It is also located in the Edit Menu -> Quick Fix.
Ctrl+Shift+O to organize imports, which will format them nicely, remove unneeded imports, and add missing imports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With