use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testAnnotationImports2.
@Test
public void testAnnotationImports2() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack0 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("public @interface MyAnnot1 {\n");
buf.append("}\n");
pack0.createCompilationUnit("MyAnnot1.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("public @interface MyAnnot2 {\n");
buf.append(" char value();\n");
buf.append("}\n");
pack0.createCompilationUnit("MyAnnot2.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("@MyAnnot1()\n");
buf.append("@MyAnnot2(File.separatorChar)\n");
buf.append("public @interface Test2 {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("Test2.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("MyClass", 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.io.File;\n");
buf.append("\n");
buf.append("import pack0.MyAnnot1;\n");
buf.append("import pack0.MyAnnot2;\n");
buf.append("\n");
buf.append("@MyAnnot1()\n");
buf.append("@MyAnnot2(File.separatorChar)\n");
buf.append("public @interface Test2 {\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 testImportToStar.
@Test
public void testImportToStar() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class List {\n");
buf.append("}\n");
pack2.createCompilationUnit("List.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.Set;\n");
buf.append("import java.util.Vector;\n");
buf.append("import java.util.Map;\n");
buf.append("\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v5;\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, 2, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v5;\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 testStaticImports_bug181895.
@Test
public void testStaticImports_bug181895() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack0 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test;\n");
buf.append("\n");
buf.append("import static java.lang.Math.max;\n");
buf.append("\n");
buf.append("public class Test {\n");
buf.append(" /**\n");
buf.append(" * @see #max\n");
buf.append(" */\n");
buf.append(" public void doFoo() {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack0.createCompilationUnit("Test.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("Test", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package test;\n");
buf.append("\n");
buf.append("\n");
buf.append("public class Test {\n");
buf.append(" /**\n");
buf.append(" * @see #max\n");
buf.append(" */\n");
buf.append(" public void doFoo() {\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 testImportCountAddTwoRemoveOne.
@Test
public void testImportCountAddTwoRemoveOne() 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("\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 testImportToStarWithExplicit2.
@Test
public void testImportToStarWithExplicit2() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class List {\n");
buf.append("}\n");
pack2.createCompilationUnit("List.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.Set;\n");
buf.append("import java.util.Vector;\n");
buf.append("import java.util.Map;\n");
buf.append("\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v6;\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, 2, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v6;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations