Search in sources :

Example 36 with IJavaElement

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

the class ParentChecker method removeResourcesDescendantsOfJavaElements.

private void removeResourcesDescendantsOfJavaElements() {
    List<IResource> subResources = new ArrayList<IResource>(3);
    for (int i = 0; i < fResources.length; i++) {
        IResource subResource = fResources[i];
        for (int j = 0; j < fJavaElements.length; j++) {
            IJavaElement superElements = fJavaElements[j];
            if (isDescendantOf(subResource, superElements))
                subResources.add(subResource);
        }
    }
    removeFromSetToDelete(subResources.toArray(new IResource[subResources.size()]));
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource)

Example 37 with IJavaElement

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

the class ParentChecker method removeJavaElementsDescendantsOfJavaElements.

private void removeJavaElementsDescendantsOfJavaElements() {
    List<IJavaElement> subElements = new ArrayList<IJavaElement>(3);
    for (int i = 0; i < fJavaElements.length; i++) {
        IJavaElement subElement = fJavaElements[i];
        for (int j = 0; j < fJavaElements.length; j++) {
            IJavaElement superElement = fJavaElements[j];
            if (isDescendantOf(subElement, superElement))
                subElements.add(subElement);
        }
    }
    removeFromSetToDelete(subElements.toArray(new IJavaElement[subElements.size()]));
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ArrayList(java.util.ArrayList)

Example 38 with IJavaElement

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

the class StandardJavaElementContentProvider method internalGetParent.

/**
     * Note: This method is for internal use only. Clients should not call this method.
     *
     * @param element the element
     * @return the parent of the element
     *
     * @noreference This method is not intended to be referenced by clients.
     */
protected Object internalGetParent(Object element) {
    // try to map resources to the containing package fragment
    if (element instanceof IResource) {
        IResource parent = ((IResource) element).getParent();
        IJavaElement jParent = JavaCore.create(parent);
        // http://bugs.eclipse.org/bugs/show_bug.cgi?id=31374
        if (jParent != null && jParent.exists())
            return jParent;
        return parent;
    } else if (element instanceof IJavaElement) {
        IJavaElement parent = ((IJavaElement) element).getParent();
        // we have to skip the package fragment root as the parent.
        if (element instanceof IPackageFragment) {
            return skipProjectPackageFragmentRoot((IPackageFragmentRoot) parent);
        }
        return parent;
    } else if (element instanceof IJarEntryResource) {
        return ((IJarEntryResource) element).getParent();
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 39 with IJavaElement

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

the class StandardJavaElementContentProvider method getFolderContent.

/**
     * Evaluates all children of a given {@link IFolder}. Clients can override this method.
     * @param folder The folder to evaluate the children for.
     * @return The children of the given folder.
     * @exception CoreException if the folder does not exist.
     *
     * @since 3.3
     */
protected Object[] getFolderContent(IFolder folder) throws CoreException {
    IResource[] members = folder.members();
    IJavaProject javaProject = JavaCore.create(folder.getProject());
    if (javaProject == null || !javaProject.exists())
        return members;
    boolean isFolderOnClasspath = javaProject.isOnClasspath(folder);
    List<IResource> nonJavaResources = new ArrayList<IResource>();
    // Can be on classpath but as a member of non-java resource folder
    for (int i = 0; i < members.length; i++) {
        IResource member = members[i];
        // of non-Java resources.
        if (isFolderOnClasspath) {
            if (javaProject.findPackageFragmentRoot(member.getFullPath()) == null) {
                nonJavaResources.add(member);
            }
        } else if (!javaProject.isOnClasspath(member)) {
            nonJavaResources.add(member);
        } else {
            IJavaElement element = JavaCore.create(member, javaProject);
            if (element instanceof IPackageFragmentRoot && javaProject.equals(element.getJavaProject()) && ((IPackageFragmentRoot) element).getKind() != IPackageFragmentRoot.K_SOURCE) {
                // don't skip libs and class folders on the classpath of their project
                nonJavaResources.add(member);
            }
        }
    }
    return nonJavaResources.toArray();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 40 with IJavaElement

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

the class CompilationUnitChangeNode method getChangeElement.

private JavaLanguageNode getChangeElement(Map<IJavaElement, JavaLanguageNode> map, IJavaElement element, List<ChildNode> children, TextEditChangeNode cunitChange) {
    JavaLanguageNode result = map.get(element);
    if (result != null)
        return result;
    IJavaElement parent = element.getParent();
    if (parent instanceof ICompilationUnit) {
        result = new JavaLanguageNode(cunitChange, element);
        children.add(result);
        map.put(element, result);
    } else {
        JavaLanguageNode parentChange = getChangeElement(map, parent, children, cunitChange);
        result = new JavaLanguageNode(parentChange, element);
        parentChange.addChild(result);
        map.put(element, result);
    }
    return result;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)226 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 IType (org.eclipse.jdt.core.IType)44 ArrayList (java.util.ArrayList)35 IJavaProject (org.eclipse.jdt.core.IJavaProject)35 IMethod (org.eclipse.jdt.core.IMethod)34 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)32 JavaModelException (org.eclipse.jdt.core.JavaModelException)32 IResource (org.eclipse.core.resources.IResource)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)28 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)23 IField (org.eclipse.jdt.core.IField)16 IMember (org.eclipse.jdt.core.IMember)14 Test (org.junit.Test)14 CoreException (org.eclipse.core.runtime.CoreException)13 StringTokenizer (java.util.StringTokenizer)11 ISourceRange (org.eclipse.jdt.core.ISourceRange)11 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)11 IPath (org.eclipse.core.runtime.IPath)10 HashMap (java.util.HashMap)9