Eclipse Tips and tricks

In a few days, Eclipse Juno will be released. This changes the version number from 3.7 (Indigo) to 4.2 (Juno) and introduces several interesting changes. I scanned through the Trips and tricks section of the Java development user guide and found several interesting points to increase productivity. Not every change is only available in Eclipse Juno, however, these are the ones that I did not know before and will use in future:

  • Entering NPE is automatically replaced with NullPointerException when using CTRL + SPACE.  This works for any class in Code Completion! Next, I will only write IAE, ISE, LL, and many more.
  • Pressing CTRL during Code Completion does not introduce an additional pair of brackes () that has to be removed when changing a method. Normally, when you have list.add("ASDF"); and change the add method via Code Completion to remove, you get list.remove(o)("ASDF");. This is quite annoying. If you accept the remove method instead of ENTER with CTRL + ENTER, you will get list.remove("ASDF"); directly.
  • Compare With works on Files and on Directories. So you can compare complete directories including subdirectories and their files with this method.
  • Package View: You can provide package abreviations for long package names
  • You can configure forbidden and discouraged files for a specific library. This allows for better code quality in huge teams as this prevents the usage of, e.g., internal classes circumventing the appropriate interfaces
  • JUnit: You can run a single test by right clicking on the method Run As -> run as JUnit Test
  • Cursor is at a bracket: Quick Fix for deleting the sourrounding statement
  • ALT + SHIFT + Z: Sourround with can be used to create Runnables, while, if, for, try-catch, etc. blocks around (a) selected line(s).
  • ALT + SHIFT + UP/DOWN: Structured Selection following the bracket structures
  • You can activate the checking of redundant null checks, potential null pointer access and for null pointer access at Java > Compiler > Errors/Warnings / Null Analysis
  • You can activate the validation of the JavaDoc and its corresponding method as warnings in Java > Compiler > Javadoc settings.

Do you have any Eclipse tips or tricks that you use extensively?

Advertisements

Innovation for the JDT in Eclipse

Currently, there is some innovation for the JDT. It is a Code Recommender.

http://code-recommenders.blogspot.com/2010/10/code-recommenders-goes-eclipse-today-is.html

It analyses your code and code frome other projects and is able to provide a filtered code completion depending on used functions. I hope that it will be a full eclipse project, soon.

The most useful eclipse plugins

I will not explain in detail the eclipse plugins you obviously try to get like subclipse, or other eclipse plugins that helps you with your current language like PHPclipse for php, etc.

I focus on the eclipse plugins that helps you with small problems and make your like easier on a day to day basis.

  1. FindBugs for static code analysis in Java. Reviews the code and shows problems with solutions how to fix them.
    Update Site: http://findbugs.cs.umd.edu/eclipse/
  2. QuickREx for evaluating regular expressions as you type. This helps to create these expressions in quite some way.
    Update Site: http://www.bastian-bergerhoff.com/eclipse/features
  3. OpenExtern for opening a folder or file using the shell or the explorer
    Update Site: http://openextern.googlecode.com/svn/trunk/openextern_update/

Maybe this also helps you during your development of your solutions.

Acceleo 3.0 A short practical review

Acceleo features that I found after searching a little bit:

1. The variable i in a for loop is implicitly defined to represent the iteration counter

It can be used like this: [i/] and prints out 1 for the first iteration, 2 for the second, and so on and on.

2. You can define querys just like functions that can be invoked from anywhere.
[query public foo(muh : String) : OclAnyType = self /]
Call: [foo(“est”)/]

However, you can also define the query in that way, that it can be executed on a specific object.
[query public foo(e: E) : OclAnyType = self /]
Call: [e.foo()/]

3. For my current project, i have to increase the memory size of eclipse to 2048MB. Otherwise, it is unusable slow. I have more than 100 template files.

4. Properties can be used, however, there is no error message if a property is not found. Therefore, they should be used with caution as wrong text can be generated without your knowledge.

5. If you import a module which in turn also imports a module, you can only use the methods defined in the module you import yourself. This does not work transitively.

Example: Module A imports Module B; Module B imports Module C;
Module A can only use public queries and templates defined in Module B, not the ones in Module C

This has the negative side effect in my project, that i have to use about 10 or more imports on top of each file.

6. String concatenation with runtime-executed function results does not work

Example: [functionX(‘muh sadf’ + getNumberAsString(5)) /]

Solution: Use variables of the templates

[template private generateIt(path : String)
{
fullPath : String = path + ‘Filename.extension’;
}]

This is also more selfdocumenting.

7. If you need some conditional logic in your queries, just use static java methods and import them into your project as modules. This is way more easier. You can also you the types your ecore model defines in java.

Nevertheless, Eclipse Acceleo 3.0 MTL is quite a promising template framework and I enjoy using it. I hope, some of the issues above will be solved in the future.

If you have questions reguarding these issues, just contact me via email.