diff --git a/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java b/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java index 1c57400..5548dbf 100644 --- a/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java +++ b/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java @@ -572,6 +572,96 @@ public class ImportRewriteTest extends AbstractJavaModelTests { assertEqualString(cu.getSource(), buf.toString()); } + /** + * Test that a valid inner class glob import is not removed even if it's in the same package. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=235253" + */ + public void testAddImports_bug235253_glob() throws Exception { + StringBuffer buf= new StringBuffer(); + buf.append("package com.pack1;\n"); + buf.append("\n"); + buf.append("import com.pack1.A;\n"); + buf.append("import com.pack1.A.*;\n"); + buf.append("import com.pack2.B;\n"); + buf.append("\n"); + buf.append("public class C {\n"); + buf.append("}\n"); + + IPackageFragment pack1= this.sourceFolder.createPackageFragment("com.pack1", false, null); + ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); + ICompilationUnit aUnit= pack1.createCompilationUnit("A.java", "", false, null); + + IPackageFragment pack2= this.sourceFolder.createPackageFragment("com.pack2", 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" }; + + ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); + imports.addImport("com.pack1.A"); + imports.addImport("com.pack1.A.*"); + imports.addImport("com.pack2.B"); + + apply(imports); + + buf= new StringBuffer(); + buf.append("package com.pack1;\n"); + buf.append("\n"); + buf.append("import com.pack1.A.*;\n"); + buf.append("import com.pack2.B;\n"); + buf.append("\n"); + buf.append("public class C {\n"); + buf.append("}\n"); + assertEqualString(cu.getSource(), buf.toString()); + } + + /** + * Test that a valid inner class import is not removed even if it's in the same package. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=235253" + */ + public void testAddImports_bug235253_noglob() throws Exception { + StringBuffer buf= new StringBuffer(); + buf.append("package com.pack1;\n"); + buf.append("\n"); + buf.append("import com.pack1.A;\n"); + buf.append("import com.pack1.A.Inner;\n"); + buf.append("import com.pack2.B;\n"); + buf.append("\n"); + buf.append("public class C {\n"); + buf.append("}\n"); + + IPackageFragment pack1= this.sourceFolder.createPackageFragment("com.pack1", false, null); + ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); + ICompilationUnit aUnit= pack1.createCompilationUnit("A.java", "", false, null); + + IPackageFragment pack2= this.sourceFolder.createPackageFragment("com.pack2", 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" }; + + ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false); + imports.addImport("com.pack1.A"); + imports.addImport("com.pack1.A.Inner"); + imports.addImport("com.pack2.B"); + + apply(imports); + + buf= new StringBuffer(); + buf.append("package com.pack1;\n"); + buf.append("\n"); + buf.append("import com.pack1.A.Inner;\n"); + buf.append("import com.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);