Bug 67644 "Organize Imports" imports inner classes but the compiler think it unnecessary [code manipulation]
Here is an example. There are two packages, a and b. Class A is in package a, with an inner class named AA (showed in the code following). ----- A.java --------------------------------------- package a; public class A { public class AA { }; } And there is a class named B in package b that use class A and A.AA: ----- B.java ----------------------------- package b; public class B { public void useA() { A a = new A(); A.AA aa = a.new AA(); } } If I use the "Organize Imports" command, it will add two import statements: import a.A; import a.A.AA; But after that, the compiler shows a warning, saying that "the import a.A.AA is never used".
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest.java
buf.append("    public void foo(Vector vec) {\n");
		buf.append("        HashMap map;\n");
		buf.append("        /*b*/\n");
		buf.append("        Iterator iter= ((Collection) vec).iterator();\n");
		buf.append("        /*e*/\n");
		buf.append("    }\n");
		buf.append("}\n");	
		String content= buf.toString();
		ICompilationUnit cu= pack1.createCompilationUnit("A.java", content, false, null);
		int start= content.indexOf("/*b*/");
		int end= content.indexOf("/*e*/");
		Region sel= new Region(start, end);
		String[] order= new String[] { };
		int threshold= 99;
				
		ImportsStructure structure= new ImportsStructure(cu, order, threshold, true);
		OrganizeImportsOperation op= new OrganizeImportsOperation(structure, sel, true, true, null);
		op.run(null);
		buf= new StringBuffer();
		buf.append("package test1;\n");
		buf.append("import java.util.Collection;\n");
		buf.append("import java.util.Iterator;\n");
		buf.append("import java.util.Vector;\n");
		buf.append("public class A {\n");
		buf.append("    public void foo(Vector vec) {\n");
		buf.append("        HashMap map;\n");
		buf.append("        /*b*/\n");
		buf.append("        Iterator iter= ((Collection) vec).iterator();\n");
		buf.append("        /*e*/\n");
		buf.append("    }\n");