Search in sources :

Example 21 with IJavaElement

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

the class DeltaProcessor method createExternalArchiveDelta.

/*
     * Check if external archives have changed for the given elements and create the corresponding deltas.
     * Returns whether at least one delta was created.
     */
private boolean createExternalArchiveDelta(HashSet refreshedElements, IProgressMonitor monitor) {
    HashMap externalArchivesStatus = new HashMap();
    boolean hasDelta = false;
    // find JARs to refresh
    HashSet archivePathsToRefresh = new HashSet();
    Iterator iterator = refreshedElements.iterator();
    while (iterator.hasNext()) {
        IJavaElement element = (IJavaElement) iterator.next();
        switch(element.getElementType()) {
            case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                archivePathsToRefresh.add(element.getPath());
                break;
            case IJavaElement.JAVA_PROJECT:
                JavaProject javaProject = (JavaProject) element;
                if (!JavaProject.hasJavaNature(javaProject.getProject())) {
                    // project is not accessible or has lost its Java nature
                    break;
                }
                IClasspathEntry[] classpath;
                try {
                    classpath = javaProject.getResolvedClasspath();
                    for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
                        if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                            archivePathsToRefresh.add(classpath[j].getPath());
                        }
                    }
                } catch (JavaModelException e) {
                // project doesn't exist -> ignore
                }
                break;
            case IJavaElement.JAVA_MODEL:
                //					}
                throw new UnsupportedOperationException();
        }
    }
    //		}
    return hasDelta;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 22 with IJavaElement

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

the class JavaModel method getHandleFromMemento.

/*
 * @see JavaElement
 */
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
    switch(token.charAt(0)) {
        case JavaElement.JEM_JAVAPROJECT:
            if (!memento.hasMoreTokens())
                return this;
            String projectName = memento.nextToken();
            JavaElement project = (JavaElement) getJavaProject(projectName);
            return project.getHandleFromMemento(memento, owner);
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement)

Example 23 with IJavaElement

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

the class JavaProject method getHandleFromMemento.

@Override
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
    switch(token.charAt(0)) {
        case JavaElement.JEM_PACKAGEFRAGMENTROOT:
            String rootPath = IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
            token = null;
            while (memento.hasMoreTokens()) {
                token = memento.nextToken();
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331821
                if (token == MementoTokenizer.PACKAGEFRAGMENT || token == MementoTokenizer.COUNT) {
                    break;
                }
                rootPath += token;
            }
            JavaElement root = (JavaElement) getPackageFragmentRoot(new Path(rootPath));
            if (token != null && token.charAt(0) == JavaElement.JEM_PACKAGEFRAGMENT) {
                return root.getHandleFromMemento(token, memento, owner);
            } else {
                return root.getHandleFromMemento(memento, owner);
            }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement)

Example 24 with IJavaElement

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

the class SourceMapper method getNameRange.

/**
     * Returns the SourceRange for the name of the given element, or
     * {-1, -1} if no source range is known for the name of the element.
     */
public SourceRange getNameRange(IJavaElement element) {
    switch(element.getElementType()) {
        case IJavaElement.METHOD:
            if (((IMember) element).isBinary()) {
                IJavaElement[] el = getUnqualifiedMethodHandle((IMethod) element, false);
                if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
                    element = getUnqualifiedMethodHandle((IMethod) element, true)[0];
                } else {
                    element = el[0];
                }
            }
            break;
        case IJavaElement.TYPE_PARAMETER:
            IJavaElement parent = element.getParent();
            if (parent.getElementType() == IJavaElement.METHOD) {
                IMethod method = (IMethod) parent;
                if (method.isBinary()) {
                    IJavaElement[] el = getUnqualifiedMethodHandle(method, false);
                    if (el[1] != null && this.sourceRanges.get(el[0]) == null) {
                        method = (IMethod) getUnqualifiedMethodHandle(method, true)[0];
                    } else {
                        method = (IMethod) el[0];
                    }
                    element = method.getTypeParameter(element.getElementName());
                }
            }
            break;
        case IJavaElement.LOCAL_VARIABLE:
            LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName());
            SourceRange[] ranges = (SourceRange[]) this.parametersRanges.get(key);
            if (ranges == null) {
                return UNKNOWN_RANGE;
            } else {
                return ranges[1];
            }
    }
    SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element);
    if (ranges == null) {
        return UNKNOWN_RANGE;
    } else {
        return ranges[1];
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMethod(org.eclipse.jdt.core.IMethod) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) IMember(org.eclipse.jdt.core.IMember)

Example 25 with IJavaElement

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

the class SourceMapper method mapSource.

/**
     * Maps the given source code to the given binary type and its children.
     * If a non-null java element is passed, finds the name range for the
     * given java element without storing it.
     */
public synchronized ISourceRange mapSource(IType type, char[] contents, IBinaryType info, IJavaElement elementToFind) {
    this.binaryType = (BinaryType) type;
    // check whether it is already mapped
    if (this.sourceRanges.get(type) != null)
        return (elementToFind != null) ? getNameRange(elementToFind) : null;
    this.importsTable.remove(this.binaryType);
    this.importsCounterTable.remove(this.binaryType);
    this.searchedElement = elementToFind;
    this.types = new IType[1];
    this.typeDeclarationStarts = new int[1];
    this.typeNameRanges = new SourceRange[1];
    this.typeModifiers = new int[1];
    this.typeDepth = -1;
    this.memberDeclarationStart = new int[1];
    this.memberName = new String[1];
    this.memberNameRange = new SourceRange[1];
    this.methodParameterTypes = new char[1][][];
    this.methodParameterNames = new char[1][][];
    this.anonymousCounter = 0;
    HashMap oldSourceRanges = null;
    if (elementToFind != null) {
        oldSourceRanges = (HashMap) this.sourceRanges.clone();
    }
    try {
        IProblemFactory factory = new DefaultProblemFactory();
        SourceElementParser parser = null;
        this.anonymousClassName = 0;
        if (info == null) {
            try {
                info = (IBinaryType) this.binaryType.getElementInfo();
            } catch (JavaModelException e) {
                return null;
            }
        }
        boolean isAnonymousClass = info.isAnonymous();
        char[] fullName = info.getName();
        if (isAnonymousClass) {
            String eltName = this.binaryType.getParent().getElementName();
            eltName = eltName.substring(eltName.lastIndexOf('$') + 1, eltName.length());
            try {
                this.anonymousClassName = Integer.parseInt(eltName);
            } catch (NumberFormatException e) {
            // ignore
            }
        }
        boolean doFullParse = hasToRetrieveSourceRangesForLocalClass(fullName);
        parser = new SourceElementParser(this, factory, new CompilerOptions(this.options), doFullParse, true);
        // disable javadoc parsing
        parser.javadocParser.checkDocComment = false;
        IJavaElement javaElement = this.binaryType.getCompilationUnit();
        if (javaElement == null)
            javaElement = this.binaryType.getParent();
        parser.parseCompilationUnit(new BasicCompilationUnit(contents, null, this.binaryType.sourceFileName(info), javaElement), doFullParse, null);
        if (elementToFind != null) {
            ISourceRange range = getNameRange(elementToFind);
            return range;
        } else {
            return null;
        }
    } finally {
        if (elementToFind != null) {
            this.sourceRanges = oldSourceRanges;
        }
        this.binaryType = null;
        this.searchedElement = null;
        this.types = null;
        this.typeDeclarationStarts = null;
        this.typeNameRanges = null;
        this.typeDepth = -1;
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) BasicCompilationUnit(org.eclipse.jdt.internal.core.BasicCompilationUnit) SourceElementParser(org.eclipse.jdt.internal.compiler.SourceElementParser) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) IProblemFactory(org.eclipse.jdt.internal.compiler.IProblemFactory) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)208 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)46 IType (org.eclipse.jdt.core.IType)41 ArrayList (java.util.ArrayList)34 IJavaProject (org.eclipse.jdt.core.IJavaProject)32 JavaModelException (org.eclipse.jdt.core.JavaModelException)31 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)30 IResource (org.eclipse.core.resources.IResource)29 IMethod (org.eclipse.jdt.core.IMethod)28 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)28 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)21 IField (org.eclipse.jdt.core.IField)14 IMember (org.eclipse.jdt.core.IMember)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 HashSet (java.util.HashSet)8