### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java,v retrieving revision 1.12 diff -u -r1.12 ImportRewriteTest.java --- src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 24 Oct 2008 10:40:41 -0000 1.12 +++ src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java 30 Sep 2009 06:57:43 -0000 @@ -572,6 +572,52 @@ assertEqualString(cu.getSource(), buf.toString()); } + public void testAddImports_bug194358() throws Exception { + + IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package pack1;\n"); + buf.append("\n"); + buf.append("import pack2.A;\n"); + buf.append("import pack2.A.Inner;\n"); + buf.append("import pack2.B;\n"); + buf.append("\n"); + buf.append("public class C {\n"); + buf.append("}\n"); + + ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); + + // We need to actually make some state in the AST for the classes, to test that we can + // disambiguate between packages and inner classes (see the bug for details). + IPackageFragment pack2= this.sourceFolder.createPackageFragment("pack2", false, null); + ICompilationUnit aUnit= pack2.createCompilationUnit("A.java", "", false, null); + ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null); + bUnit.createType("class B {}", null, false, null); + + IType aType= aUnit.createType("class A {}", null, false, null); + aType.createType("class Inner {}", null, false, null); + String[] order= new String[] { "java" }; + + long time = System.nanoTime(); + ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); + imports.addImport("pack2.A"); + imports.addImport("pack2.A.Inner"); + imports.addImport("pack2.B"); + + apply(imports); + System.out.println("Time taken: " + (System.nanoTime() - time)); + + buf= new StringBuffer(); + buf.append("package pack1;\n"); + buf.append("\n"); + buf.append("import pack2.A;\n"); + buf.append("import pack2.A.Inner;\n"); + buf.append("import pack2.B;\n"); + buf.append("\n"); + buf.append("public class C {\n"); + buf.append("}\n"); + assertEqualString(cu.getSource(), buf.toString()); + } public void testAddStaticImports1() throws Exception { IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);