Search in sources :

Example 1 with LogicalPackage

use of org.eclipse.jdt.internal.ui.browsing.LogicalPackage in project xtext-eclipse by eclipse.

the class MultiOrganizeImportsHandler method collectRelevantFiles.

private void collectRelevantFiles(Object element, Multimap<IProject, IFile> result) {
    try {
        if (element instanceof IJavaElement) {
            IJavaElement elem = (IJavaElement) element;
            if (elem.exists()) {
                switch(elem.getElementType()) {
                    case IJavaElement.PACKAGE_FRAGMENT:
                        collectRelevantFiles((IPackageFragment) elem, result);
                        break;
                    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                        collectRelevantFiles((IPackageFragmentRoot) elem, result);
                        break;
                    case IJavaElement.JAVA_PROJECT:
                        IPackageFragmentRoot[] roots;
                        roots = ((IJavaProject) elem).getPackageFragmentRoots();
                        for (int k = 0; k < roots.length; k++) {
                            collectRelevantFiles(roots[k], result);
                        }
                        break;
                }
            }
        } else if (element instanceof LogicalPackage) {
            IPackageFragment[] packageFragments = ((LogicalPackage) element).getFragments();
            for (int k = 0; k < packageFragments.length; k++) {
                IPackageFragment pack = packageFragments[k];
                if (pack.exists()) {
                    collectRelevantFiles(pack, result);
                }
            }
        } else if (element instanceof IWorkingSet) {
            IWorkingSet workingSet = (IWorkingSet) element;
            IAdaptable[] elements = workingSet.getElements();
            for (int j = 0; j < elements.length; j++) {
                collectRelevantFiles(elements[j], result);
            }
        } else if (element instanceof IFile) {
            collectIFiles(result, new Object[] { element });
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) LogicalPackage(org.eclipse.jdt.internal.ui.browsing.LogicalPackage) IWorkingSet(org.eclipse.ui.IWorkingSet) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 LogicalPackage (org.eclipse.jdt.internal.ui.browsing.LogicalPackage)1 IWorkingSet (org.eclipse.ui.IWorkingSet)1