use of org.eclipse.jdt.core.IPackageFragmentRoot 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());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testNewImportsNoPackage.
@Test
public void testNewImportsNoPackage() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.getPackageFragment("");
StringBuffer buf = new StringBuffer();
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("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.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testStaticImports_bug187004b.
@Test
public void testStaticImports_bug187004b() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack0 = sourceFolder.createPackageFragment("b", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package b;\n");
buf.append("\n");
buf.append("abstract public class Parent<T> {\n");
buf.append(" protected static final int CONSTANT() { return 42; }\n");
buf.append("}\n");
pack0.createCompilationUnit("Parent.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("a", false, null);
buf = new StringBuffer();
buf.append("package a;\n");
buf.append("\n");
buf.append("import b.Parent;\n");
buf.append("\n");
buf.append("public class Child extends Parent<String> {\n");
buf.append(" public Child() {\n");
buf.append(" System.out.println(CONSTANT());\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("Child.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("Child", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package a;\n");
buf.append("\n");
// no static import for CONSTANT()
buf.append("import b.Parent;\n");
buf.append("\n");
buf.append("public class Child extends Parent<String> {\n");
buf.append(" public Child() {\n");
buf.append(" System.out.println(CONSTANT());\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testStaticImports_bug175498.
@Test
public void testStaticImports_bug175498() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("p", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package p;\n");
buf.append("public class Test<T> {\n");
buf.append(" public static enum TestEnum {\n");
buf.append(" V1,\n");
buf.append(" V2\n");
buf.append(" }\n");
buf.append("\n");
buf.append(" public void test(final TestEnum value) {\n");
buf.append(" switch (value) {\n");
buf.append(" case V1:\n");
buf.append(" case V2:\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("testStaticImports_bug175498", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
// no changes, don't add 'V1' and 'V2' as static import
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testInnerClassVisibility.
@Test
public void testInnerClassVisibility() 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("public class C {\n");
buf.append(" public static class C1 {\n");
buf.append(" public static class C2 {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("C.java", buf.toString(), false, null);
IPackageFragment pack2 = sourceFolder.createPackageFragment("test2", false, null);
buf = new StringBuffer();
buf.append("package test2;\n");
buf.append("import test2.A.A1;\n");
buf.append("import test2.A.A1.A2;\n");
buf.append("import test2.A.A1.A2.A3;\n");
buf.append("import test2.A.B1;\n");
buf.append("import test2.A.B1.B2;\n");
buf.append("import test1.C;\n");
buf.append("import test1.C.C1.C2;\n");
buf.append("public class A {\n");
buf.append(" public static class A1 {\n");
buf.append(" public static class A2 {\n");
buf.append(" public static class A3 {\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" public static class B1 {\n");
buf.append(" public static class B2 {\n");
buf.append(" }\n");
buf.append(" public static class B3 {\n");
buf.append(" public static class B4 extends C {\n");
buf.append(" B4 b4;\n");
buf.append(" B3 b3;\n");
buf.append(" B2 b2;\n");
buf.append(" B1 b1;\n");
buf.append(" A1 a1;\n");
buf.append(" A2 a2;\n");
buf.append(" A3 a3;\n");
buf.append(" C1 c1;\n");
buf.append(" C2 c2;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu2 = pack2.createCompilationUnit("A.java", buf.toString(), false, null);
String[] order = new String[0];
IChooseImportQuery query = createQuery("A", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu2, order, 99, false, true, true, query);
op.run(null);
assertImports(cu2, new String[] { "test1.C", "test1.C.C1.C2", "test2.A.A1.A2", "test2.A.A1.A2.A3" });
}
Aggregations