Java Code Examples for org.eclipse.jdt.core.search.SearchMatch#isImplicit()

The following examples show how to use org.eclipse.jdt.core.search.SearchMatch#isImplicit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameMethodProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
protected final ReplaceEdit createReplaceEdit(SearchMatch searchResult, ICompilationUnit cu) {
	if (searchResult.isImplicit()) { // handle Annotation Element references, see bug 94062
		StringBuffer sb= new StringBuffer(getNewElementName());
		if (JavaCore.INSERT.equals(cu.getJavaProject().getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, true))) {
			sb.append(' ');
		}
		sb.append('=');
		if (JavaCore.INSERT.equals(cu.getJavaProject().getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR, true))) {
			sb.append(' ');
		}
		return new ReplaceEdit(searchResult.getOffset(), 0, sb.toString());
	} else {
		return new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), getNewElementName());
	}
}
 
Example 2
Source File: RenameMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected final ReplaceEdit createReplaceEdit(SearchMatch searchResult, ICompilationUnit cu) {
	if (searchResult.isImplicit()) { // handle Annotation Element references, see bug 94062
		StringBuffer sb= new StringBuffer(getNewElementName());
		if (JavaCore.INSERT.equals(cu.getJavaProject().getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR, true)))
			sb.append(' ');
		sb.append('=');
		if (JavaCore.INSERT.equals(cu.getJavaProject().getOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR, true)))
			sb.append(' ');
		return new ReplaceEdit(searchResult.getOffset(), 0, sb.toString());
	} else {
		return new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), getNewElementName());
	}
}
 
Example 3
Source File: MethodOccurenceCollector.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
	if (match instanceof MethodReferenceMatch
			&& ((MethodReferenceMatch) match).isSuperInvocation()
			&& match.getAccuracy() == SearchMatch.A_INACCURATE) {
		return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
	}

	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 == InternalTokenNameIdentifier) {
				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);
}
 
Example 4
Source File: MethodOccurenceCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
	if (match instanceof MethodReferenceMatch
			&& ((MethodReferenceMatch) match).isSuperInvocation()
			&& match.getAccuracy() == SearchMatch.A_INACCURATE) {
		return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
	}

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