use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testReplaceImports.
@Test
public void testReplaceImports() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("\n");
buf.append("import java.util.Set;\n");
buf.append("\n");
buf.append("public class C extends Vector {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[0];
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 test1;\n");
buf.append("\n");
buf.append("import java.util.Vector;\n");
buf.append("\n");
buf.append("public class C extends Vector {\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_bug78397.
@Test
public void test_bug78397() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("import java.util.Collection;\n");
buf.append("public class A {\n");
buf.append(" Collection<java.sql.Date> foo;\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.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 pack0;\n");
buf.append("import java.util.Collection;\n");
buf.append("public class A {\n");
// no import for Date
buf.append(" Collection<java.sql.Date> foo;\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 testVisibility_bug56704.
@Test
public void testVisibility_bug56704() 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 A {\n");
buf.append(" public class AX {\n");
buf.append(" }\n");
buf.append("}\n");
pack2.createCompilationUnit("A.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("\n");
buf.append("import pack0.A.AX;\n");
buf.append("public class B extends A {\n");
buf.append(" public class BX extends 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("MyClass", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("\n");
buf.append("public class B extends A {\n");
buf.append(" public class BX extends 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 testVisibility_bug131305.
@Test
public void testVisibility_bug131305() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment packUtil = sourceFolder.createPackageFragment("util", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package util;\n");
buf.append("\n");
buf.append("public interface Map \n");
buf.append(" public static interface Entry {\n");
buf.append(" }\n");
buf.append("}\n");
packUtil.createCompilationUnit("Map.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package util;\n");
buf.append("\n");
buf.append("public interface HashMap implements Map {\n");
buf.append(" private static interface Entry {\n");
buf.append(" }\n");
buf.append("}\n");
packUtil.createCompilationUnit("HashMap.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 util.HashMap;\n");
buf.append("import util.Map;\n");
buf.append("import util.Map.Entry;\n");
buf.append("\n");
buf.append("public class A extends HashMap {\n");
buf.append(" public A(Map m, Entry e) {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("testVisibility_bug131305", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
// no changes, import for Entry is required
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testStaticImports1.
@Test
public void testStaticImports1() 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 static java.lang.System.out;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public int foo() {\n");
buf.append(" out.print(File.separator);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack", "#java" };
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("\n");
buf.append("import static java.lang.System.out;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public int foo() {\n");
buf.append(" out.print(File.separator);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations