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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations