For generic calls one can explicitly add the type like this new ArrayList<String>(). In many cases explicitly writing the type is redundant, because the compiler can infer it.
Current implementation
The implementation is currently done in PMD, but this has several problems:
the PMD dependency can not be removed
the submission has to be compiled for spoon and PMD
any bugs might take a long time to be fixed
PMD implements the check by checking each invocation and creating a new one, but with the explicit type removed. If the new invocation works, the type is redundant.
How to implement this in Spoon?
The problem is that spoon does not expose any of the type inference done by jdt and every constructed invocation must set the type manually.
There are some solutions that come to mind to replicate a similar behavior:
Implement type inference according to the JLS (note: not worth the amount of work and error prone)
Try to work with the spoon developers to expose the jdt type inference and apply them to created elements
Replicate the relevant source code in a new project and recompile it to check if it still works with the type removed. The proof of concept would be very easy to implement, but it would result in a compilation of the model for every diamond operator with an explicit type. The compilation of the model is the part that takes by far the longest time. To mitigate this, one could try to minimize the source code as much as possible, before recompiling or one could remove all diamond operators at once, and then try to map the compiler messages to the relevant source fragments (in that case the project has to be recompiled only once).
Description
What it does?
For generic calls one can explicitly add the type like this
new ArrayList<String>()
. In many cases explicitly writing the type is redundant, because the compiler can infer it.Current implementation
The implementation is currently done in PMD, but this has several problems:
PMD implements the check by checking each invocation and creating a new one, but with the explicit type removed. If the new invocation works, the type is redundant.
How to implement this in Spoon?
The problem is that spoon does not expose any of the type inference done by jdt and every constructed invocation must set the type manually.
There are some solutions that come to mind to replicate a similar behavior: