use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method test4.
@Test
public void test4() throws Exception {
File junitSrcArchive = new File(JUnitSourceSetup.class.getClassLoader().getResource(JavaProjectHelper.JUNIT_SRC_381.toOSString()).getFile());
assertTrue("junit src not found", junitSrcArchive != null && junitSrcArchive.exists());
JavaProjectHelper.addSourceContainerWithImport(fJProject1, "src", junitSrcArchive, JavaProjectHelper.JUNIT_SRC_ENCODING);
ICompilationUnit cu = (ICompilationUnit) fJProject1.findElement(new Path("junit/textui/TestRunner.java"));
assertNotNull("TestRunner.java", cu);
String[] order = new String[0];
IChooseImportQuery query = createQuery("TestRunner", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
assertImports(cu, new String[] { "java.io.PrintStream", "junit.framework.Test", "junit.framework.TestResult", "junit.framework.TestSuite", "junit.runner.BaseTestRunner", "junit.runner.StandardTestSuiteLoader", "junit.runner.TestSuiteLoader", "junit.runner.Version" });
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method test_bug78716.
@Test
public void test_bug78716() 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 enum MyEnum {\n");
buf.append(" A, B, C\n");
buf.append("}\n");
pack0.createCompilationUnit("MyEnum.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 pack0.MyEnum;\n");
buf.append("import static pack0.MyEnum.*;\n");
buf.append("\n");
buf.append("public class Test2 {\n");
buf.append(" MyEnum e= A;\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 pack0.MyEnum;\n");
buf.append("\n");
buf.append("import static pack0.MyEnum.A;\n");
buf.append("\n");
buf.append("public class Test2 {\n");
buf.append(" MyEnum e= A;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method testGroups1.
@Test
public void testGroups1() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("public class List1 {\n");
buf.append("}\n");
pack2.createCompilationUnit("List1.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("public class C {\n");
buf.append(" File f;\n");
buf.append(" IOException f1;\n");
buf.append(" RandomAccessFile f2;\n");
buf.append(" ArrayList f3;\n");
buf.append(" List1 f4;\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java.io", "java.util" };
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.io.File;\n");
buf.append("import java.io.IOException;\n");
buf.append("import java.io.RandomAccessFile;\n");
buf.append("\n");
buf.append("import java.util.ArrayList;\n");
buf.append("\n");
buf.append("import pack0.List1;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" File f;\n");
buf.append(" IOException f1;\n");
buf.append(" RandomAccessFile f2;\n");
buf.append(" ArrayList f3;\n");
buf.append(" List1 f4;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method testImportFromDefaultWithStar.
@Test
public void testImportFromDefaultWithStar() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("", false, null);
StringBuffer buf = new StringBuffer();
buf.append("public class List1 {\n");
buf.append("}\n");
pack2.createCompilationUnit("List1.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("public class List2 {\n");
buf.append("}\n");
pack2.createCompilationUnit("List2.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
// no imports from default in compatibility >= 1.4
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("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List1 v4;\n");
buf.append(" List2 v5;\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("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List1 v4;\n");
buf.append(" List2 v5;\n");
buf.append(" String v6;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery 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());
}
Aggregations