本文整理汇总了Java中org.eclipse.jdt.core.search.SearchMatch.A_INACCURATE属性的典型用法代码示例。如果您正苦于以下问题:Java SearchMatch.A_INACCURATE属性的具体用法?Java SearchMatch.A_INACCURATE怎么用?Java SearchMatch.A_INACCURATE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.core.search.SearchMatch
的用法示例。
在下文中一共展示了SearchMatch.A_INACCURATE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acceptSearchMatch
@Override
public final void acceptSearchMatch(final SearchMatch match) throws CoreException {
final SearchMatch accepted = fRequestor.acceptSearchMatch(match);
if (accepted != null) {
final IResource resource = accepted.getResource();
if (!resource.equals(fLastResource)) {
final IJavaElement element = JavaCore.create(resource);
if (element instanceof ICompilationUnit) fCollectedUnits.add((ICompilationUnit) element);
}
if (fInaccurate
&& accepted.getAccuracy() == SearchMatch.A_INACCURATE
&& !fInaccurateMatches.contains(accepted)) {
fStatus.addEntry(
fSeverity,
Messages.format(
RefactoringCoreMessages.RefactoringSearchEngine_inaccurate_match,
BasicElementLabels.getResourceName(accepted.getResource())),
null,
null,
RefactoringStatusEntry.NO_CODE);
fInaccurateMatches.add(accepted);
}
}
}
示例2: acceptSearchMatch
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IJavaElement enclosingElement = (IJavaElement) match.getElement();
if (enclosingElement != null) {
if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE)) return;
boolean isWriteAccess = false;
boolean isReadAccess = false;
if (match instanceof FieldReferenceMatch) {
FieldReferenceMatch fieldRef = ((FieldReferenceMatch) match);
isWriteAccess = fieldRef.isWriteAccess();
isReadAccess = fieldRef.isReadAccess();
} else if (match instanceof FieldDeclarationMatch) {
isWriteAccess = true;
} else if (match instanceof LocalVariableReferenceMatch) {
LocalVariableReferenceMatch localVarRef = ((LocalVariableReferenceMatch) match);
isWriteAccess = localVarRef.isWriteAccess();
isReadAccess = localVarRef.isReadAccess();
} else if (match instanceof LocalVariableDeclarationMatch) {
isWriteAccess = true;
}
boolean isSuperInvocation = false;
if (match instanceof MethodReferenceMatch) {
MethodReferenceMatch methodRef = (MethodReferenceMatch) match;
isSuperInvocation = methodRef.isSuperInvocation();
}
fSearch.addMatch(
new JavaElementMatch(
enclosingElement,
match.getRule(),
match.getOffset(),
match.getLength(),
match.getAccuracy(),
isReadAccess,
isWriteAccess,
match.isInsideDocComment(),
isSuperInvocation));
}
}
示例3: collectMatch
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);
}
示例4: acceptSearchMatch
@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);
}
示例5: getAffectedCompilationUnits
@Override
public ICompilationUnit[] getAffectedCompilationUnits(
final RefactoringStatus status, ReferencesInBinaryContext binaryRefs, IProgressMonitor pm)
throws CoreException {
IMethod method = (IMethod) fMethodBinding.getJavaElement();
Assert.isTrue(method != null);
SearchPattern pattern =
SearchPattern.createPattern(
method, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
IJavaSearchScope scope = RefactoringScopeFactory.create(method, true, false);
final HashSet<ICompilationUnit> affectedCompilationUnits = new HashSet<ICompilationUnit>();
CollectingSearchRequestor requestor =
new CollectingSearchRequestor(binaryRefs) {
private ICompilationUnit fLastCU;
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (filterMatch(match)) return;
if (match.isInsideDocComment())
return; // TODO: should warn user (with something like a ReferencesInBinaryContext)
ICompilationUnit unit = SearchUtils.getCompilationUnit(match);
if (match.getAccuracy() == SearchMatch.A_INACCURATE) {
if (unit != null) {
status.addError(
RefactoringCoreMessages.TargetProvider_inaccurate_match,
JavaStatusContext.create(
unit, new SourceRange(match.getOffset(), match.getLength())));
} else {
status.addError(RefactoringCoreMessages.TargetProvider_inaccurate_match);
}
} else if (unit != null) {
if (!unit.equals(fLastCU)) {
fLastCU = unit;
affectedCompilationUnits.add(unit);
}
}
}
};
new SearchEngine()
.search(
pattern,
SearchUtils.getDefaultSearchParticipants(),
scope,
requestor,
new SubProgressMonitor(pm, 1));
return affectedCompilationUnits.toArray(
new ICompilationUnit[affectedCompilationUnits.size()]);
}
示例6: findAffectedCompilationUnits
public static ICompilationUnit[] findAffectedCompilationUnits(
SearchPattern pattern,
IJavaSearchScope scope,
final IProgressMonitor pm,
RefactoringStatus status,
final boolean tolerateInAccurateMatches)
throws JavaModelException {
boolean hasNonCuMatches = false;
class ResourceSearchRequestor extends SearchRequestor {
boolean hasPotentialMatches = false;
Set<IResource> resources = new HashSet<IResource>(5);
private IResource fLastResource;
@Override
public void acceptSearchMatch(SearchMatch match) {
if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
hasPotentialMatches = true;
}
if (fLastResource != match.getResource()) {
fLastResource = match.getResource();
resources.add(fLastResource);
}
}
}
ResourceSearchRequestor requestor = new ResourceSearchRequestor();
try {
new SearchEngine()
.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
} catch (CoreException e) {
throw new JavaModelException(e);
}
List<IJavaElement> result = new ArrayList<IJavaElement>(requestor.resources.size());
for (Iterator<IResource> iter = requestor.resources.iterator(); iter.hasNext(); ) {
IResource resource = iter.next();
IJavaElement element = JavaCore.create(resource);
if (element instanceof ICompilationUnit) {
result.add(element);
} else {
hasNonCuMatches = true;
}
}
addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
return result.toArray(new ICompilationUnit[result.size()]);
}
示例7: filters
@Override
public boolean filters(JavaElementMatch match) {
return match.getAccuracy() == SearchMatch.A_INACCURATE;
}