本文整理汇总了Java中org.eclipse.jdt.core.search.SearchMatch.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java SearchMatch.getOffset方法的具体用法?Java SearchMatch.getOffset怎么用?Java SearchMatch.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.search.SearchMatch
的用法示例。
在下文中一共展示了SearchMatch.getOffset方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createReplaceEdit
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
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());
}
}
示例2: addReferenceUpdates
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
pm.beginTask("", fReferences.length); // $NON-NLS-1$
for (int i = 0; i < fReferences.length; i++) {
ICompilationUnit cu = fReferences[i].getCompilationUnit();
if (cu == null) continue;
String name = RefactoringCoreMessages.RenameTypeRefactoring_update_reference;
SearchMatch[] results = fReferences[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
ReplaceEdit replaceEdit =
new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
TextChangeCompatibility.addTextEdit(
manager.get(cu), name, replaceEdit, CATEGORY_TYPE_RENAME);
}
pm.worked(1);
}
}
示例3: getExactASTNode
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
public static ASTNode getExactASTNode(CompilationUnit root,
final SearchMatch match) {
final ArrayList ret = new ArrayList(1);
final ASTVisitor visitor = new ASTVisitor() {
public void preVisit(ASTNode node) {
if (node.getStartPosition() == match.getOffset()) {
ret.clear();
ret.add(node);
}
}
};
root.accept(visitor);
return (ASTNode) ret.get(0);
}
示例4: findParameters
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private void findParameters(final int paramNumber, SearchPattern pattern)
throws CoreException {
final SearchRequestor requestor = new SearchRequestor() {
public void acceptSearchMatch(SearchMatch match)
throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE
&& !match.isInsideDocComment()) {
IJavaElement elem = (IJavaElement) match.getElement();
ASTNode node = Util.getASTNode(elem,
ASTNodeProcessor.this.monitor);
ParameterProcessingVisitor visitor = new ParameterProcessingVisitor(
paramNumber, match.getOffset());
node.accept(visitor);
ASTNodeProcessor.this.found.addAll(visitor.getElements());
for (Iterator it = visitor.getExpressions().iterator(); it
.hasNext();) {
Expression exp = (Expression) it.next();
ASTNodeProcessor.this.processExpression(exp);
}
}
}
};
final SearchEngine searchEngine = new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
.getDefaultSearchParticipant() }, this.scope, requestor, null);
}
示例5: addAccessorOccurrences
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private void addAccessorOccurrences(
IProgressMonitor pm,
IMethod accessor,
String editName,
String newAccessorName,
RefactoringStatus status)
throws CoreException {
Assert.isTrue(accessor.exists());
IJavaSearchScope scope = RefactoringScopeFactory.create(accessor);
SearchPattern pattern =
SearchPattern.createPattern(
accessor,
IJavaSearchConstants.ALL_OCCURRENCES,
SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
SearchResultGroup[] groupedResults =
RefactoringSearchEngine.search(
pattern, scope, new MethodOccurenceCollector(accessor.getElementName()), pm, status);
for (int i = 0; i < groupedResults.length; i++) {
ICompilationUnit cu = groupedResults[i].getCompilationUnit();
if (cu == null) continue;
SearchMatch[] results = groupedResults[i].getSearchResults();
for (int j = 0; j < results.length; j++) {
SearchMatch searchResult = results[j];
TextEdit edit =
new ReplaceEdit(searchResult.getOffset(), searchResult.getLength(), newAccessorName);
addTextEdit(fChangeManager.get(cu), editName, edit);
}
}
}
示例6: addShadowsError
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private static void addShadowsError(
ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) {
// Old match not found in new matches -> reference has been shadowed
// 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);
}
示例7: collectMatch
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private TextEdit collectMatch(SearchMatch match, IJavaElement element, ICompilationUnit unit, String newName) throws IndexOutOfBoundsException, JavaModelException {
if (match instanceof MethodReferenceMatch && ((MethodReferenceMatch) match).isSuperInvocation() && match.getAccuracy() == SearchMatch.A_INACCURATE) {
return null;
}
if (!(element instanceof IMethod) || match.isImplicit()) {
return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
}
int start = match.getOffset();
int length = match.getLength();
String matchText = unit.getBuffer().getText(start, length);
//direct match:
if (newName.equals(matchText)) {
return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
}
// lambda expression
if (match instanceof MethodDeclarationMatch && match.getElement() instanceof IMethod && ((IMethod) match.getElement()).isLambdaMethod()) {
// don't touch the lambda
return null;
}
//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);
}
return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
}
示例8: createTextChange
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private TextEdit createTextChange(SearchMatch match) {
return new ReplaceEdit(match.getOffset(), match.getLength(), getNewElementName());
}
示例9: acceptSearchMatch
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@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);
}
示例10: createTextRange
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private static IRegion createTextRange(SearchMatch searchResult) {
return new Region(searchResult.getOffset(), searchResult.getLength());
}
示例11: acceptSearchMatch2
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
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;
}
示例12: createTextChange
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
private TextEdit createTextChange(SearchMatch searchResult) {
return new ReplaceEdit(
searchResult.getOffset(), searchResult.getLength(), getNewPackageName());
}
示例13: acceptSearchMatch
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (filterMatch(match)) return;
/*
* Processing is done in collector to reuse the buffer which was
* already required by the search engine to locate the matches.
*/
// [start, end[ include qualification.
IJavaElement element = SearchUtils.getEnclosingJavaElement(match);
int accuracy = match.getAccuracy();
int start = match.getOffset();
int length = match.getLength();
boolean insideDocComment = match.isInsideDocComment();
IResource res = match.getResource();
if (element.getAncestor(IJavaElement.IMPORT_DECLARATION) != null) {
collectMatch(
TypeReference.createImportReference(
element, accuracy, start, length, insideDocComment, res));
} else {
ICompilationUnit unit =
(ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
if (unit != null) {
IBuffer buffer = unit.getBuffer();
String matchText = buffer.getText(start, length);
if (fSource.isDefaultPackage()) {
collectMatch(
TypeReference.createSimpleReference(
element, accuracy, start, length, insideDocComment, res, matchText));
} else {
// assert: matchText doesn't start nor end with comment
int simpleNameStart = getLastSimpleNameStart(matchText);
if (simpleNameStart != 0) {
collectMatch(
TypeReference.createQualifiedReference(
element,
accuracy,
start,
length,
insideDocComment,
res,
start + simpleNameStart));
} else {
collectMatch(
TypeReference.createSimpleReference(
element, accuracy, start, length, insideDocComment, res, matchText));
}
}
}
}
}