use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testImportCountAddandRemove.
@Test
public void testImportCountAddandRemove() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack" };
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.ArrayList;\n");
buf.append("import java.util.HashMap;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
assertEquals(2, op.getNumberOfImportsAdded());
assertEquals(1, op.getNumberOfImportsRemoved());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testVisibility_bug67644.
@Test
public void testVisibility_bug67644() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("public class A {\n");
buf.append(" public class AX {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("A.java", buf.toString(), false, null);
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack2", false, null);
buf = new StringBuffer();
buf.append("package pack2;\n");
buf.append("\n");
buf.append("import pack1.A;\n");
buf.append("import pack1.AX;\n");
buf.append("public class B {\n");
buf.append(" public void foo() {\n");
buf.append(" Object x= new A().new AX();\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("B.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("testVisibility_bug67644", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack2;\n");
buf.append("\n");
buf.append("import pack1.A;\n");
buf.append("public class B {\n");
buf.append(" public void foo() {\n");
buf.append(" Object x= new A().new AX();\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method test_PackageInfoBug216432.
@Test
public void test_PackageInfoBug216432() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("/**\n");
buf.append(" * @see Bar\n");
buf.append(" */\n");
buf.append("@Foo\n");
buf.append("package pack1;");
ICompilationUnit cu = pack1.createCompilationUnit("package-info.java", buf.toString(), false, null);
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack2", false, null);
buf = new StringBuffer();
buf.append("package pack2;\n");
buf.append("public @interface Foo {\n");
buf.append("}\n");
pack2.createCompilationUnit("Foo.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack2;\n");
buf.append("public @interface Bar {\n");
buf.append("}\n");
pack2.createCompilationUnit("Bar.java", buf.toString(), false, null);
String[] order = new String[] { "", "#" };
IChooseImportQuery query = createQuery("test_PackageInfoBug216432", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("/**\n");
buf.append(" * @see Bar\n");
buf.append(" */\n");
buf.append("@Foo\n");
buf.append("package pack1;\n");
// no import for Bar
buf.append("import pack2.Foo;\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testImportCountRemoveStatic.
@Test
public void testImportCountRemoveStatic() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.BitSet;\n");
buf.append("// some comment;\n");
buf.append("import java.util.Calendar; /*another comment*/\n");
buf.append("import static java.io.File.pathSeparator;\n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack" };
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.ArrayList;\n");
buf.append("import java.util.HashMap;\n");
buf.append("// some comment;\n");
buf.append("/*another comment*/\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
assertEquals(2, op.getNumberOfImportsAdded());
assertEquals(4, op.getNumberOfImportsRemoved());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testImportOfMemberFromLocal.
@Test
public void testImportOfMemberFromLocal() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" class Local {\n");
buf.append(" class LocalMember {\n");
buf.append(" }\n");
buf.append(" LocalMember x;\n");
buf.append(" Vector v;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack" };
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.Vector;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" class Local {\n");
buf.append(" class LocalMember {\n");
buf.append(" }\n");
buf.append(" LocalMember x;\n");
buf.append(" Vector v;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations