本文整理汇总了Java中org.eclipse.jdt.core.search.SearchMatch.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java SearchMatch.getResource方法的具体用法?Java SearchMatch.getResource怎么用?Java SearchMatch.getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.search.SearchMatch
的用法示例。
在下文中一共展示了SearchMatch.getResource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acceptSearchMatch
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
@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
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));
}
}
}
}
}
示例3: findAffectedCompilationUnits
import org.eclipse.jdt.core.search.SearchMatch; //导入方法依赖的package包/类
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()]);
}