Search in sources :

Example 66 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery 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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) OrganizeImportsOperation(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation) IChooseImportQuery(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 67 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery 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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) OrganizeImportsOperation(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation) IChooseImportQuery(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 68 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery 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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) OrganizeImportsOperation(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation) IChooseImportQuery(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 69 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery 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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) OrganizeImportsOperation(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation) IChooseImportQuery(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 70 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery 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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) OrganizeImportsOperation(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation) IChooseImportQuery(org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Aggregations

IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)71 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)70 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)70 Test (org.junit.Test)69 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)67 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)67 File (java.io.File)5 JUnitSourceSetup (org.eclipse.che.plugin.java.server.jdt.search.JUnitSourceSetup)5 Path (org.eclipse.core.runtime.Path)5 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 TypeNameMatch (org.eclipse.jdt.core.search.TypeNameMatch)1