Community
Participate
Working Groups
When we perform "organize imports" on a ".aj" file that has warnings, it fails with a message that the "file has parsing errors". This is problematic since the typical scenario to organize imports is when we have unused imports. The unused imports consitute warnings. Example: Try organize imports on the following: package spects; import java.util.List; import claszes.MyClass; public aspect MyAspect { public int MyClass.doit() { System.out.println("doing it"); return 0; } }
This is a regression from 2.0.2. The problem comes from a change added to address bug 313770. As described in bug 313774, there are no tests in this area and so an error was introduced with the change.
Things get curiouser. The example aspect from the description does not work with organize import, but when an advice is added, organize imports works as expected. Eg- the following aspect has no problems with organize imports: package spects; import java.util.List; import other.Java; public aspect MyAspect { public int Other.doit() { new Other(); System.out.println("doing it"); return 0; } before(Java java, int arg) : execution(int Java.xxx(int)) && args(arg) && this(java) { } } The reason appears to be that unused import statements are not found by the (Java) parser for AJ files when advice exists in the file.
I committed a fix for this in the 3.6 stream after some manual testing. I feel confident that this fixes the problem addressed by this bug report. However, I will keep this bug open until I create some tests for organize imports.
I have a bunch of tests for this now. Most common situations are handled. However, there is one situation with declare @annotations that is not working. If the following declare statement is in an aspect, but ArrayList is not imported: declare @type : ArrayList : @Foo; ArrayList will still not be imported after an organize imports occurs. However, given the same declare @annotation statement and if 'import java.util.ArrayList;' already exists, the import statement will not be removed. I have a test case for this, but it has been removed. Once I commit this work, I'll close this bug report and create a new one for the existing problem, which I believe is relatively minor.
Fix has been committed in 36 stream. Waiting for snapshot build.