Search in sources :

Example 1 with SourceRange

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

the class RenameAnalyzeUtil method addShadowsError.

private static void addShadowsError(ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) {
    //TODO: should not have to filter declarations:
    if (oldMatch instanceof MethodDeclarationMatch || oldMatch instanceof FieldDeclarationMatch)
        return;
    ISourceRange range = new SourceRange(oldMatch.getOffset(), oldMatch.getLength());
    RefactoringStatusContext context = JavaStatusContext.create(cu, range);
    String message = Messages.format(RefactoringCoreMessages.RenameAnalyzeUtil_shadows, BasicElementLabels.getFileName(cu));
    result.addError(message, context);
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) MethodDeclarationMatch(org.eclipse.jdt.core.search.MethodDeclarationMatch) FieldDeclarationMatch(org.eclipse.jdt.core.search.FieldDeclarationMatch) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 2 with SourceRange

use of org.eclipse.jdt.core.SourceRange 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 3 with SourceRange

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

the class SourceMapper method exitType.

/**
     * @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor
     */
public void exitType(int declarationEnd) {
    if (this.typeDepth >= 0) {
        IType currentType = this.types[this.typeDepth];
        setSourceRange(currentType, new SourceRange(this.typeDeclarationStarts[this.typeDepth], declarationEnd - this.typeDeclarationStarts[this.typeDepth] + 1), this.typeNameRanges[this.typeDepth]);
        this.typeDepth--;
    }
}
Also used : ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) IType(org.eclipse.jdt.core.IType)

Example 4 with SourceRange

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

the class SourceMapper method exitAbstractMethod.

private void exitAbstractMethod(int declarationEnd) {
    if (this.typeDepth >= 0) {
        IType currentType = this.types[this.typeDepth];
        SourceRange sourceRange = new SourceRange(this.memberDeclarationStart[this.typeDepth], declarationEnd - this.memberDeclarationStart[this.typeDepth] + 1);
        IMethod method = currentType.getMethod(this.memberName[this.typeDepth], convertTypeNamesToSigs(this.methodParameterTypes[this.typeDepth]));
        setSourceRange(method, sourceRange, this.memberNameRange[this.typeDepth]);
        setMethodParameterNames(method, this.methodParameterNames[this.typeDepth]);
    }
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) IType(org.eclipse.jdt.core.IType)

Example 5 with SourceRange

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

the class SourceMapper method exitField.

/**
     * @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor
     */
public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) {
    if (this.typeDepth >= 0) {
        IType currentType = this.types[this.typeDepth];
        setSourceRange(currentType.getField(this.memberName[this.typeDepth]), new SourceRange(this.memberDeclarationStart[this.typeDepth], declarationEnd - this.memberDeclarationStart[this.typeDepth] + 1), this.memberNameRange[this.typeDepth]);
    }
}
Also used : ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) IType(org.eclipse.jdt.core.IType)

Aggregations

SourceRange (org.eclipse.jdt.core.SourceRange)14 ISourceRange (org.eclipse.jdt.core.ISourceRange)13 IType (org.eclipse.jdt.core.IType)6 IMethod (org.eclipse.jdt.core.IMethod)4 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IMember (org.eclipse.jdt.core.IMember)2 ITypeParameter (org.eclipse.jdt.core.ITypeParameter)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 Expression (org.eclipse.jdt.core.dom.Expression)2 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)2 RefactoringStatusContext (org.eclipse.ltk.core.refactoring.RefactoringStatusContext)2 HashSet (java.util.HashSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 IClassFile (org.eclipse.jdt.core.IClassFile)1 IField (org.eclipse.jdt.core.IField)1 IScanner (org.eclipse.jdt.core.compiler.IScanner)1 Assignment (org.eclipse.jdt.core.dom.Assignment)1 CastExpression (org.eclipse.jdt.core.dom.CastExpression)1 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)1 IAnnotationBinding (org.eclipse.jdt.core.dom.IAnnotationBinding)1