RSS Feed for This PostCurrent Article

Useful Eclipse Shortcuts II

Quick Assist (Ctrl+1)

  • Create getter and setters: Available on fields.
  • Extract to method: Available on expressions and statements.
  • Extract to local variable without replacing all occurrences: Available on expressions.
  • Use StringBuilder for string concatenation: Available on string concatenations.
    • StringBuilder is used in Java projects with a 1.5 or higher compliance, StringBuffer is used in projects with a lower compliance.
  • Use MessageFormat for string concatenation: Similar to convert to StringBuilder, MessageFormat is used to replace string concatenations.
  • Instead of typing an assignment, start with the expression that will be assigned. Now use Ctrl+1 (Edit > Quick Fix) and choose ‘Assign statement to new local variable‘ and Quick Assist will guess a variable name for you.



Fix Code Indentation

  • A useful feature is Source > Correct Indentation or Ctrl+I. Select the code where the indents are incorrect and invoke the action. If nothing is selected, the action indents the current line.


Quick Source and Refactoring

  • The refactoring and source actions can be accessed via a quick menu. Select the element to be manipulated in the Java editor or in a Java view and press Alt+Shift+S for the quick source menu, Alt+Shift+T for the quick refactoring menu and Alt+Shift+Z for the surround with menu.



Source Clean Up

Source > Clean Up… helps fixing multiple problems at once and helps to establish a consistent code style. For instance, you can:

  • convert all for loops to enhanced for loops where possible.
  • mark all overriding methods in a whole project with an @Override annotation.
  • organize imports
  • format your code
  • remove unnecessary code

Clean Ups are organized in Clean Up profiles. A profile can be attached to the workspace or to individual projects. Project settings can be shared in a team through a version control system. It is also possible to export and import each profile.


Quick Type Hierarchy

Find out which are the possible receivers of a virtual call using the Quick Type Hierarchy. Place the cursor inside the method call and press Ctrl+T (Navigate > Quick Type Hierarchy). The view shows all types that implement the method with a full icon.


Sort Members

You can Sort Members of a Java compilation unit or a set of compilation units according to a category order defined in the  Java > Appearance > Members Sort Order preference page. You’ll find the action under Source > Sort Members.

Trackback URL

Sorry, comments for this entry are closed at this time.