Bug 319613 - Organize Imports treats warnings as errors
Summary: Organize Imports treats warnings as errors
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: UI (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 2.0.2   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 319931
  Show dependency tree
 
Reported: 2010-07-12 13:16 EDT by Kris De Volder CLA
Modified: 2010-07-19 12:03 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kris De Volder CLA 2010-07-12 13:16:57 EDT
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;
	}
	
}
Comment 1 Andrew Eisenberg CLA 2010-07-12 16:11:18 EDT
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.
Comment 2 Andrew Eisenberg CLA 2010-07-12 16:14:06 EDT
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.
Comment 3 Andrew Eisenberg CLA 2010-07-12 23:40:16 EDT
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.
Comment 4 Andrew Eisenberg CLA 2010-07-14 19:25:53 EDT
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.
Comment 5 Andrew Eisenberg CLA 2010-07-19 12:03:19 EDT
Fix has been committed in 36 stream.  Waiting for snapshot build.