Search in sources :

Example 76 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 77 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)

Example 78 with IPackageFragmentRoot

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

the class RenamePackageTest method helperProjectsPrgTest.

/**
     * 2 Projects with a root each: Project RenamePack2 (root: srcTest) requires project RenamePack1
     * (root: srcPrg).
     *
     * @param packageNames package names per root
     * @param newPackageName the new package name for packageNames[0][0]
     * @param cuNames cu names per package
     * @throws Exception if one of the resources cannot be created
     */
private void helperProjectsPrgTest(String[][] packageNames, String newPackageName, String[][][] cuNames) throws Exception {
    IJavaProject projectPrg = null;
    IJavaProject projectTest = null;
    try {
        projectPrg = JavaProjectHelper.createJavaProject("RenamePack1", "bin");
        assertNotNull(JavaProjectHelper.addRTJar(projectPrg));
        IPackageFragmentRoot srcPrg = JavaProjectHelper.addSourceContainer(projectPrg, "srcPrg");
        Map optionsPrg = projectPrg.getOptions(false);
        JavaProjectHelper.set15CompilerOptions(optionsPrg);
        projectPrg.setOptions(optionsPrg);
        projectTest = JavaProjectHelper.createJavaProject("RenamePack2", "bin");
        assertNotNull(JavaProjectHelper.addRTJar(projectTest));
        IPackageFragmentRoot srcTest = JavaProjectHelper.addSourceContainer(projectTest, "srcTest");
        Map optionsTest = projectTest.getOptions(false);
        JavaProjectHelper.set15CompilerOptions(optionsTest);
        projectTest.setOptions(optionsTest);
        JavaProjectHelper.addRequiredProject(projectTest, projectPrg);
        helperMultiProjects(new IPackageFragmentRoot[] { srcPrg, srcTest }, packageNames, newPackageName, cuNames);
    } finally {
        JavaProjectHelper.delete(projectPrg);
        JavaProjectHelper.delete(projectTest);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) Map(java.util.Map) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 79 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method getSrcRootLocation.

/**
     * Get the path of .JAVA/src
     * 
     * @throws Exception
     */
protected IPath getSrcRootLocation() throws Exception {
    ITalendProcessJavaProject talendProcessJavaProject = RepositoryPlugin.getDefault().getRunProcessService().getTalendProcessJavaProject();
    if (talendProcessJavaProject == null) {
        //$NON-NLS-1$
        return new Path("");
    }
    IProject project = talendProcessJavaProject.getProject();
    IJavaProject javaProject = talendProcessJavaProject.getJavaProject();
    IPackageFragmentRoot[] pp = javaProject.getAllPackageFragmentRoots();
    IPackageFragmentRoot src = null;
    for (IPackageFragmentRoot root : pp) {
        if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
            src = root;
            break;
        }
    }
    IPath root = project.getParent().getLocation();
    root = root.append(src.getPath());
    return root;
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 80 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project tdi-studio-se by Talend.

the class AddPackageDialog method getPackageFragments.

/**
     * Gets the package fragments.
     * 
     * @param javaModel The java model
     * @return The package fragments
     */
private Object[] getPackageFragments(IJavaModel javaModel) {
    Set<String> packageElements = new HashSet<String>();
    IJavaProject[] projects;
    try {
        projects = javaModel.getJavaProjects();
    } catch (JavaModelException e) {
        Activator.log(IStatus.ERROR, Messages.getJavaModelFailedMsg, e);
        return new Object[0];
    }
    for (IJavaProject project : projects) {
        if (EXTERNAL_PLUGIN_LIBRARIES.equals(project.getResource().getName())) {
            continue;
        }
        IPackageFragmentRoot[] packageFragmentRoots;
        try {
            packageFragmentRoots = project.getPackageFragmentRoots();
        } catch (JavaModelException e) {
            continue;
        }
        for (IPackageFragmentRoot packageFragment : packageFragmentRoots) {
            try {
                addPackage(packageElements, packageFragment);
            } catch (JavaModelException e) {
            // do nothing
            }
        }
    }
    for (Object packageName : filteringPackages) {
        packageElements.remove(packageName);
    }
    return packageElements.toArray(new String[0]);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashSet(java.util.HashSet) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)179 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)96 Test (org.junit.Test)95 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)78 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)37 File (java.io.File)26 IJavaElement (org.eclipse.jdt.core.IJavaElement)22 IResource (org.eclipse.core.resources.IResource)17 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)16 IPath (org.eclipse.core.runtime.IPath)15 ArrayList (java.util.ArrayList)13 IType (org.eclipse.jdt.core.IType)12 CoreException (org.eclipse.core.runtime.CoreException)11 Path (org.eclipse.core.runtime.Path)11 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 IFile (org.eclipse.core.resources.IFile)9 IProject (org.eclipse.core.resources.IProject)9