Search in sources :

Example 11 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class ImportOrganizeTest method testStaticImports_bug181895.

@Test
public void testStaticImports_bug181895() throws Exception {
    IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
    IPackageFragment pack0 = sourceFolder.createPackageFragment("pack0", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test;\n");
    buf.append("\n");
    buf.append("import static java.lang.Math.max;\n");
    buf.append("\n");
    buf.append("public class Test {\n");
    buf.append("        /**\n");
    buf.append("         * @see #max\n");
    buf.append("         */\n");
    buf.append("        public void doFoo() {\n");
    buf.append("        }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack0.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 test;\n");
    buf.append("\n");
    buf.append("\n");
    buf.append("public class Test {\n");
    buf.append("        /**\n");
    buf.append("         * @see #max\n");
    buf.append("         */\n");
    buf.append("        public void doFoo() {\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 12 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class ImportOrganizeTest method testImportCountAddTwoRemoveOne.

@Test
public void testImportCountAddTwoRemoveOne() 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 java.util.BitSet;\n");
    buf.append("\n");
    buf.append("public class C {\n");
    buf.append("    public void foo() {\n");
    buf.append("        HashMap m;\n");
    buf.append("        ArrayList l;\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.ArrayList;\n");
    buf.append("import java.util.HashMap;\n");
    buf.append("\n");
    buf.append("public class C {\n");
    buf.append("    public void foo() {\n");
    buf.append("        HashMap m;\n");
    buf.append("        ArrayList l;\n");
    buf.append("    }\n");
    buf.append("}\n");
    assertEqualString(cu.getSource(), buf.toString());
    assertEquals(2, op.getNumberOfImportsAdded());
    assertEquals(1, op.getNumberOfImportsRemoved());
}
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 13 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class ImportOrganizeTest method testImportToStarWithExplicit2.

@Test
public void testImportToStarWithExplicit2() 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 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, 2, 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 14 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class ImportOrganizeTest method testBaseGroups1.

@Test
public void testBaseGroups1() 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 List1 {\n");
    buf.append("}\n");
    pack2.createCompilationUnit("List1.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("public class C {\n");
    buf.append("    File f;\n");
    buf.append("    IOException f1;\n");
    buf.append("    RandomAccessFile f2;\n");
    buf.append("    ArrayList f3;\n");
    buf.append("    List1 f4;\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
    String[] order = new String[] { "java", "java.io" };
    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.ArrayList;\n");
    buf.append("\n");
    buf.append("import java.io.File;\n");
    buf.append("import java.io.IOException;\n");
    buf.append("import java.io.RandomAccessFile;\n");
    buf.append("\n");
    buf.append("import pack0.List1;\n");
    buf.append("\n");
    buf.append("public class C {\n");
    buf.append("    File f;\n");
    buf.append("    IOException f1;\n");
    buf.append("    RandomAccessFile f2;\n");
    buf.append("    ArrayList f3;\n");
    buf.append("    List1 f4;\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 15 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class RenamePackageTest method testImportFromMultiRoots4.

@Test
@Ignore
public void testImportFromMultiRoots4() throws Exception {
    //circular buildpath references
    IJavaProject projectPrg = null;
    IJavaProject projectTest = null;
    Hashtable options = JavaCore.getOptions();
    Object cyclicPref = JavaCore.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH);
    try {
        projectPrg = JavaProjectHelper.createJavaProject("RenamePack1", "bin");
        assertNotNull(JavaProjectHelper.addRTJar(projectPrg));
        IPackageFragmentRoot srcPrg = JavaProjectHelper.addSourceContainer(projectPrg, "srcPrg");
        projectTest = JavaProjectHelper.createJavaProject("RenamePack2", "bin");
        assertNotNull(JavaProjectHelper.addRTJar(projectTest));
        IPackageFragmentRoot srcTest = JavaProjectHelper.addSourceContainer(projectTest, "srcTest");
        options.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING);
        JavaCore.setOptions(options);
        JavaProjectHelper.addRequiredProject(projectTest, projectPrg);
        JavaProjectHelper.addRequiredProject(projectPrg, projectTest);
        helperMultiProjects(new IPackageFragmentRoot[] { srcPrg, srcTest }, new String[][] { new String[] { "p" }, new String[] { "p" } }, "a.b.c", new String[][][] { new String[][] { new String[] { "A", "B" } }, new String[][] { new String[] { "ATest" } } });
    } finally {
        options.put(JavaCore.CORE_CIRCULAR_CLASSPATH, cyclicPref);
        JavaCore.setOptions(options);
        JavaProjectHelper.delete(projectPrg);
        JavaProjectHelper.delete(projectTest);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) Hashtable(java.util.Hashtable) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)171 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)94 Test (org.junit.Test)91 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)77 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)67 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)67 IJavaProject (org.eclipse.jdt.core.IJavaProject)30 File (java.io.File)26 IJavaElement (org.eclipse.jdt.core.IJavaElement)20 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)16 IResource (org.eclipse.core.resources.IResource)16 IPath (org.eclipse.core.runtime.IPath)13 ArrayList (java.util.ArrayList)12 Path (org.eclipse.core.runtime.Path)11 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)11 CoreException (org.eclipse.core.runtime.CoreException)10 IFile (org.eclipse.core.resources.IFile)8 IType (org.eclipse.jdt.core.IType)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)8 IFolder (org.eclipse.core.resources.IFolder)7