use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testImportToStarWithExplicit4.
@Test
public void testImportToStarWithExplicit4() 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 pack3 = sourceFolder.createPackageFragment("pack3", false, null);
buf = new StringBuffer();
buf.append("package pack3;\n");
buf.append("public class List {\n");
buf.append("}\n");
pack3.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, 1, 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());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testStaticImports_bug90556.
@Test
public void testStaticImports_bug90556() 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 class BasePanel<T extends Number> {\n");
buf.append(" public static void add2panel(String... s) {\n");
buf.append(" }\n");
buf.append("}\n");
pack0.createCompilationUnit("Test1.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("\n");
buf.append("public class ManufacturerMainPanel<T extends Number> extends BasePanel<T>{\n");
buf.append(" public void testMe() {\n");
buf.append(" add2panel(null, null);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack0.createCompilationUnit("ManufacturerMainPanel.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("ManufacturerMainPanel", 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 ManufacturerMainPanel<T extends Number> extends BasePanel<T>{\n");
buf.append(" public void testMe() {\n");
buf.append(" add2panel(null, null);\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_bug159638.
@Test
public void testVisibility_bug159638() 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 abstract class Parent<E> {\n");
buf.append(" public static class Inner {\n");
buf.append(" }\n");
buf.append(" public @interface Tag{\n");
buf.append(" String value();\n");
buf.append(" }\n");
buf.append("}\n");
pack0.createCompilationUnit("Parent.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.Parent;\n");
buf.append("import pack0.Parent.Inner;\n");
buf.append("import pack0.Parent.Tag;\n");
buf.append("\n");
buf.append("@Tag(\"foo\")\n");
buf.append("public class Child extends Parent<Inner> {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("Child.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("testVisibility_bug159638", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
// no changes, imports for Inner and tag are required
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testAnnotationImports1.
@Test
public void testAnnotationImports1() 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(" int value();\n");
buf.append("}\n");
pack0.createCompilationUnit("MyAnnot2.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("public @interface MyAnnot3 {\n");
buf.append("}\n");
pack0.createCompilationUnit("MyAnnot3.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("@MyAnnot3 public class Test2 {\n");
buf.append(" @MyAnnot1 Object e;\n");
buf.append(" @MyAnnot2(1) void foo() {\n");
buf.append(" }\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.MyAnnot1;\n");
buf.append("import pack0.MyAnnot2;\n");
buf.append("import pack0.MyAnnot3;\n");
buf.append("\n");
buf.append("@MyAnnot3 public class Test2 {\n");
buf.append(" @MyAnnot1 Object e;\n");
buf.append(" @MyAnnot2(1) void foo() {\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 testStaticImports_bug81589.
@Test
public void testStaticImports_bug81589() 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 E {\n");
buf.append(" A, B, C;\n");
buf.append("}\n");
pack0.createCompilationUnit("E.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.E;\n");
buf.append("import static pack0.E.A;\n");
buf.append("\n");
buf.append("public class Test2 {\n");
buf.append(" public void testMe(E e) {\n");
buf.append(" switch (e) {\n");
buf.append(" case A:\n");
buf.append(" }\n");
buf.append(" }\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");
// no import for E.A
buf.append("import pack0.E;\n");
buf.append("\n");
buf.append("public class Test2 {\n");
buf.append(" public void testMe(E e) {\n");
buf.append(" switch (e) {\n");
buf.append(" case A:\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations