Save Activity in Eclipse IDE to convert java code to diamond notation

If you have java version> = 1.7 you can use diamond notation.

Instead:

List<String> rows = new ArrayList<String>();

      

You can write:

List<String> rows = new ArrayList<>();

      

With Eclipse Mars-M4, I have errors when I use the first construct. (It may have been with the Eclipse Luna version already. I haven't tested it):

Java Code

It has to do with this configuration:

Preferences> Java> Compiler> Errors / Warnings in the tree. In the list: General Types> Redundant Type Arguments (1.7 or higher).

Errors / Warnings preference page

The value is set to ERROR. I can of course set it to IGNORE to remove the error.

I am looking for another solution. Eclipse has a concept called Additional Actions. I am looking for an action that would rewrite the code to diamond notation.

Does this action already exist? How do I set it up?

Similar questions:

+3


source to share


3 answers


With Eclipse Neon, simply select Remove Redundant Type Arguments (1.7 or higher) from the Optional Code tab in the Advanced Save Operations windows (or in the Edit Cleanup - up Profile).

Additional action windows with saving



Read more in this blog post: Eclipse Neon: Diamond Notation as a Cleanup Action

+1


source


Unfortunately, this is not possible out of the box. You will need to write your own plugin and implement the interface ICleanUp

.



If you want to create your own plugin, details on how to create a cleanup and save operation can be found here: Promoting cleanup and saving using the cleanup extension point

+1


source


Looks like there is a ticket for targeting eclipse 4.6 https://bugs.eclipse.org/bugs/show_bug.cgi?id=434788

+1


source







All Articles