Search in sources :

Example 86 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project AutoRefactor by JnRouvignac.

the class PrepareApplyRefactoringsJob method addAll.

private void addAll(Queue<RefactoringUnit> results, List<IJavaElement> javaElements, IProgressMonitor monitor) throws JavaModelException {
    final SubMonitor subMonitor = SubMonitor.convert(monitor, javaElements.size());
    for (IJavaElement javaElement : javaElements) {
        final SubMonitor child = subMonitor.newChild(1);
        final JavaProjectOptions options = getJavaProjectOptions(javaElement);
        if (javaElement instanceof ICompilationUnit) {
            add(results, (ICompilationUnit) javaElement, options);
        } else if (javaElement instanceof IPackageFragment) {
            final IPackageFragment pf = (IPackageFragment) javaElement;
            addAll(results, getSubPackages(pf), child);
            addAll(results, pf.getCompilationUnits(), options);
        } else if (javaElement instanceof IPackageFragmentRoot) {
            final IPackageFragmentRoot pfr = (IPackageFragmentRoot) javaElement;
            addAll(results, Arrays.asList(pfr.getChildren()), child);
        } else if (javaElement instanceof IJavaProject) {
            IJavaProject javaProject = (IJavaProject) javaElement;
            for (IPackageFragment pf : javaProject.getPackageFragments()) {
                addAll(results, pf.getCompilationUnits(), options);
            }
        }
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) SubMonitor(org.eclipse.core.runtime.SubMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 87 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project AutoRefactor by JnRouvignac.

the class PrepareApplyRefactoringsJob method getSubPackages.

private List<IJavaElement> getSubPackages(IPackageFragment motherPackage) throws JavaModelException {
    List<IJavaElement> subPackages = new ArrayList<IJavaElement>();
    String packageName = motherPackage.getElementName();
    IJavaElement[] packages = ((IPackageFragmentRoot) motherPackage.getParent()).getChildren();
    for (IJavaElement onePackage : packages) {
        if (onePackage instanceof IPackageFragment && onePackage.getElementName().startsWith(packageName + ".")) {
            subPackages.add(onePackage);
        }
    }
    return subPackages;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ArrayList(java.util.ArrayList) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 88 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project xtext-xtend by eclipse.

the class XtendUIValidator method getExpectedPackageName.

protected String getExpectedPackageName(XtendFile xtendFile) {
    URI fileURI = xtendFile.eResource().getURI();
    for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) {
        if (storage.getFirst() instanceof IFile) {
            IPath fileWorkspacePath = storage.getFirst().getFullPath();
            IJavaProject javaProject = JavaCore.create(storage.getSecond());
            if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
                try {
                    for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
                        if (!root.isArchive() && !root.isExternal()) {
                            IResource resource = root.getResource();
                            if (resource != null) {
                                IPath sourceFolderPath = resource.getFullPath();
                                if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) {
                                    IPath claspathRelativePath = fileWorkspacePath.makeRelativeTo(sourceFolderPath);
                                    return claspathRelativePath.removeLastSegments(1).toString().replace("/", ".");
                                }
                            }
                        }
                    }
                } catch (JavaModelException e) {
                    LOG.error("Error resolving expected path for XtendFile", e);
                }
            }
        }
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 89 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project xtext-xtend by eclipse.

the class XbaseEditorOpenClassFileTest method testOpenFileFromSmapJarWithIncludedSource.

@Test
public void testOpenFileFromSmapJarWithIncludedSource() {
    try {
        boolean _supportsEditorOverride = this.supportsEditorOverride();
        boolean _not = (!_supportsEditorOverride);
        if (_not) {
            return;
        }
        final IJavaProject jp = JavaCore.create(this.project);
        final IPackageFragmentRoot root = this.addJarToClassPath(jp, "smap-all.jar", null);
        Assert.assertNotNull(root);
        final IType type = jp.findType("de.itemis.HelloXtend");
        Assert.assertNotNull(type);
        final String result = this.getEditorContents(type);
        this.assertContains("println(\'Hello Xtend!\')", result);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 90 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project xtext-xtend by eclipse.

the class XbaseEditorOpenClassFileTest method testOpenFileFromJarWithNameConflictingLocalFile.

@Test
public void testOpenFileFromJarWithNameConflictingLocalFile() {
    try {
        boolean _supportsEditorOverride = this.supportsEditorOverride();
        boolean _not = (!_supportsEditorOverride);
        if (_not) {
            return;
        }
        final IJavaProject jp = JavaCore.create(this.project);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.append("class HelloXtend {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("// wrong class");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.helper.createFile("foo/HelloXtend.xtend", _builder.toString());
        final IPackageFragmentRoot root = this.addJarToClassPath(jp, "primary-debug-binary.jar", "primary-debug-sources.jar");
        Assert.assertNotNull(root);
        final IType type = jp.findType("de.itemis.HelloXtend");
        Assert.assertNotNull(type);
        final String result = this.getEditorContents(type);
        this.assertContains("println(\'Hello Xtend!\')", result);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

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