Search in sources :

Example 61 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.

the class ImportOrganizeTest method testStaticImports_bug187004a.

@Test
public void testStaticImports_bug187004a() 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 = 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());
}
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 62 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.

the class ImportOrganizeTest method testJavadocImports_bug319860.

@Test
public void testJavadocImports_bug319860() throws Exception {
    IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
    IPackageFragment pack0 = sourceFolder.createPackageFragment("p", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package p;\n");
    buf.append("\n");
    buf.append("import p.Main.I;\n");
    buf.append("\n");
    buf.append("/**\n");
    buf.append(" * {@link I}.\n");
    buf.append(" * @see C\n");
    buf.append(" */\n");
    buf.append("public class Main {\n");
    buf.append("    public interface I {\n");
    buf.append("    }\n");
    buf.append("    public class C {}\n");
    buf.append("}\n");
    ICompilationUnit cu = pack0.createCompilationUnit("Main.java", buf.toString(), false, null);
    String[] order = new String[] {};
    IChooseImportQuery query = createQuery("JavadocImports_bug319860", new String[] {}, new int[] {});
    OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
    op.run(null);
    buf = new StringBuffer();
    buf.append("package p;\n");
    buf.append("\n");
    buf.append("\n");
    buf.append("/**\n");
    buf.append(" * {@link I}.\n");
    buf.append(" * @see C\n");
    buf.append(" */\n");
    buf.append("public class Main {\n");
    buf.append("    public interface I {\n");
    buf.append("    }\n");
    buf.append("    public class C {}\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 63 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.

the class ImportOrganizeTest method testStaticImports_bug230067.

@Test
public void testStaticImports_bug230067() throws Exception {
    IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
    IPackageFragment pack1 = sourceFolder.createPackageFragment("a", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package a;\n");
    buf.append("\n");
    buf.append("class Test<T> {\n");
    buf.append("    private static String TEST = \"constant\";\n");
    buf.append("\n");
    buf.append("    static class Inner extends Test<String> {\n");
    buf.append("        public void test() {\n");
    buf.append("            TEST.concat(\"access\");\n");
    buf.append("        }\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("Test.java", buf.toString(), false, null);
    String[] order = new String[] {};
    IChooseImportQuery query = createQuery("Test", 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");
    // no static import for 'TEST'
    buf.append("\n");
    buf.append("class Test<T> {\n");
    buf.append("    private static String TEST = \"constant\";\n");
    buf.append("\n");
    buf.append("    static class Inner extends Test<String> {\n");
    buf.append("        public void test() {\n");
    buf.append("            TEST.concat(\"access\");\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)

Example 64 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.

the class ImportOrganizeTest method test_PackageInfoBug157541b.

@Test
public void test_PackageInfoBug157541b() throws Exception {
    IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
    IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("@Foo @Bar\n");
    buf.append("package pack1;\n");
    buf.append("\n");
    buf.append("import pack2.Foo;\n");
    buf.append("\n");
    ICompilationUnit cu = pack1.createCompilationUnit("package-info.java", buf.toString(), false, null);
    IPackageFragment pack2 = sourceFolder.createPackageFragment("pack2", false, null);
    buf = new StringBuffer();
    buf.append("package pack2;\n");
    buf.append("public @interface Foo {\n");
    buf.append("}\n");
    pack2.createCompilationUnit("Foo.java", buf.toString(), false, null);
    buf = new StringBuffer();
    buf.append("package pack2;\n");
    buf.append("public @interface Bar {\n");
    buf.append("}\n");
    pack2.createCompilationUnit("Bar.java", buf.toString(), false, null);
    String[] order = new String[] { "", "#" };
    IChooseImportQuery query = createQuery("Foo", new String[] {}, new int[] {});
    OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
    op.run(null);
    buf = new StringBuffer();
    buf.append("@Foo @Bar\n");
    buf.append("package pack1;\n");
    buf.append("\n");
    buf.append("import pack2.Bar;\n");
    buf.append("import pack2.Foo;\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 65 with IChooseImportQuery

use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.

the class ImportOrganizeTest method testVisibility_bug37299a.

@Test
public void testVisibility_bug37299a() 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("public class ClusterSingletonStepped {\n");
    buf.append("	public interface SingletonStep {\n");
    buf.append("	}\n");
    buf.append("}\n");
    pack1.createCompilationUnit("ClusterSingletonStepped.java", buf.toString(), false, null);
    IPackageFragment pack2 = sourceFolder.createPackageFragment("pack0", false, null);
    buf = new StringBuffer();
    buf.append("package pack0;\n");
    buf.append("\n");
    buf.append("import pack1.ClusterSingletonStepped;\n");
    buf.append("import pack1.ClusterSingletonStepped.SingletonStep;\n");
    buf.append("\n");
    buf.append("public class TestFile extends ClusterSingletonStepped implements SingletonStep {\n");
    buf.append("    SingletonStep step;\n");
    buf.append("}\n");
    ICompilationUnit cu = pack2.createCompilationUnit("TestFile.java", buf.toString(), false, null);
    String[] order = new String[] {};
    IChooseImportQuery query = createQuery("TestFile", 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("import pack1.ClusterSingletonStepped;\n");
    buf.append("import pack1.ClusterSingletonStepped.SingletonStep;\n");
    buf.append("\n");
    buf.append("public class TestFile extends ClusterSingletonStepped implements SingletonStep {\n");
    buf.append("    SingletonStep step;\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