Search in sources :

Example 1 with InvalidInputException

use of org.eclipse.jdt.core.compiler.InvalidInputException in project che by eclipse.

the class MethodOccurenceCollector method acceptSearchMatch.

@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
    if (match instanceof MethodReferenceMatch && ((MethodReferenceMatch) match).isSuperInvocation() && match.getAccuracy() == SearchMatch.A_INACCURATE) {
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
        return;
    }
    if (match.isImplicit()) {
        // see bug 94062
        collectMatch(match);
        return;
    }
    int start = match.getOffset();
    int length = match.getLength();
    String matchText = unit.getBuffer().getText(start, length);
    //direct match:
    if (fName.equals(matchText)) {
        collectMatch(match);
        return;
    }
    // lambda expression
    if (match instanceof MethodDeclarationMatch && match.getElement() instanceof IMethod && ((IMethod) match.getElement()).isLambdaMethod()) {
        // don't touch the lambda
        return;
    }
    //Not a standard reference -- use scanner to find last identifier token before left parenthesis:
    IScanner scanner = getScanner(unit);
    scanner.setSource(matchText.toCharArray());
    int simpleNameStart = -1;
    int simpleNameEnd = -1;
    try {
        int token = scanner.getNextToken();
        while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) {
            // reference in code includes arguments in parentheses
            if (token == ITerminalSymbols.TokenNameIdentifier) {
                simpleNameStart = scanner.getCurrentTokenStartPosition();
                simpleNameEnd = scanner.getCurrentTokenEndPosition();
            }
            token = scanner.getNextToken();
        }
    } catch (InvalidInputException e) {
    //ignore
    }
    if (simpleNameStart != -1) {
        match.setOffset(start + simpleNameStart);
        match.setLength(simpleNameEnd + 1 - simpleNameStart);
    }
    collectMatch(match);
}
Also used : IScanner(org.eclipse.jdt.core.compiler.IScanner) InvalidInputException(org.eclipse.jdt.core.compiler.InvalidInputException) MethodReferenceMatch(org.eclipse.jdt.core.search.MethodReferenceMatch) IMethod(org.eclipse.jdt.core.IMethod) MethodDeclarationMatch(org.eclipse.jdt.core.search.MethodDeclarationMatch)

Example 2 with InvalidInputException

use of org.eclipse.jdt.core.compiler.InvalidInputException in project che by eclipse.

the class TypeOccurrenceCollector method acceptSearchMatch2.

public SearchMatch acceptSearchMatch2(ICompilationUnit unit, SearchMatch match) throws CoreException {
    int start = match.getOffset();
    int length = match.getLength();
    //unqualified:
    String matchText = unit.getBuffer().getText(start, length);
    if (fOldName.equals(matchText)) {
        return match;
    }
    //(partially) qualified:
    if (fOldQualifiedName.endsWith(matchText)) {
        //e.g. rename B and p.A.B ends with match A.B
        int simpleNameLenght = fOldName.length();
        match.setOffset(start + length - simpleNameLenght);
        match.setLength(simpleNameLenght);
        return match;
    }
    //Not a standard reference -- use scanner to find last identifier token:
    IScanner scanner = getScanner(unit);
    scanner.setSource(matchText.toCharArray());
    int simpleNameStart = -1;
    int simpleNameEnd = -1;
    try {
        int token = scanner.getNextToken();
        while (token != ITerminalSymbols.TokenNameEOF) {
            if (token == ITerminalSymbols.TokenNameIdentifier) {
                simpleNameStart = scanner.getCurrentTokenStartPosition();
                simpleNameEnd = scanner.getCurrentTokenEndPosition();
            }
            token = scanner.getNextToken();
        }
    } catch (InvalidInputException e) {
    //ignore
    }
    if (simpleNameStart != -1) {
        match.setOffset(start + simpleNameStart);
        match.setLength(simpleNameEnd + 1 - simpleNameStart);
    }
    return match;
}
Also used : IScanner(org.eclipse.jdt.core.compiler.IScanner) InvalidInputException(org.eclipse.jdt.core.compiler.InvalidInputException)

Example 3 with InvalidInputException

use of org.eclipse.jdt.core.compiler.InvalidInputException in project che by eclipse.

the class CodeTemplateContextType method isValidComment.

private boolean isValidComment(String template) {
    IScanner scanner = ToolFactory.createScanner(true, false, false, false);
    scanner.setSource(template.toCharArray());
    try {
        int next = scanner.getNextToken();
        while (TokenScanner.isComment(next)) {
            next = scanner.getNextToken();
        }
        return next == ITerminalSymbols.TokenNameEOF;
    } catch (InvalidInputException e) {
    }
    return false;
}
Also used : IScanner(org.eclipse.jdt.core.compiler.IScanner) InvalidInputException(org.eclipse.jdt.core.compiler.InvalidInputException)

Example 4 with InvalidInputException

use of org.eclipse.jdt.core.compiler.InvalidInputException in project eclipse.jdt.ls by eclipse.

the class CodeTemplateContextType method isValidComment.

private boolean isValidComment(String template) {
    IScanner scanner = ToolFactory.createScanner(true, false, false, false);
    scanner.setSource(template.toCharArray());
    try {
        int next = scanner.getNextToken();
        while (TokenScanner.isComment(next)) {
            next = scanner.getNextToken();
        }
        return next == ITerminalSymbols.TokenNameEOF;
    } catch (InvalidInputException e) {
    }
    return false;
}
Also used : IScanner(org.eclipse.jdt.core.compiler.IScanner) InvalidInputException(org.eclipse.jdt.core.compiler.InvalidInputException)

Example 5 with InvalidInputException

use of org.eclipse.jdt.core.compiler.InvalidInputException in project bndtools by bndtools.

the class NewTypeWizardPage method isValidComment.

private boolean isValidComment(String template) {
    IScanner scanner = ToolFactory.createScanner(true, false, false, false);
    scanner.setSource(template.toCharArray());
    try {
        int next = scanner.getNextToken();
        while (TokenScanner.isComment(next)) {
            next = scanner.getNextToken();
        }
        return next == ITerminalSymbols.TokenNameEOF;
    } catch (InvalidInputException e) {
    }
    return false;
}
Also used : IScanner(org.eclipse.jdt.core.compiler.IScanner) InvalidInputException(org.eclipse.jdt.core.compiler.InvalidInputException)

Aggregations

IScanner (org.eclipse.jdt.core.compiler.IScanner)11 InvalidInputException (org.eclipse.jdt.core.compiler.InvalidInputException)11 IMethod (org.eclipse.jdt.core.IMethod)2 MethodDeclarationMatch (org.eclipse.jdt.core.search.MethodDeclarationMatch)2 MethodReferenceMatch (org.eclipse.jdt.core.search.MethodReferenceMatch)2 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)1