本文整理汇总了Java中org.eclipse.jdt.core.search.SearchMatch类的典型用法代码示例。如果您正苦于以下问题:Java SearchMatch类的具体用法?Java SearchMatch怎么用?Java SearchMatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SearchMatch类属于org.eclipse.jdt.core.search包,在下文中一共展示了SearchMatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getITypeMainByWorkspaceScope
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
/**
* search the bundle that contains the Main class. The search is done in the
* workspace scope (ie. if it is defined in the current workspace it will
* find it
*
* @return the name of the bundle containing the Main class or null if not
* found
*/
private IType getITypeMainByWorkspaceScope(String className) {
SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
final List<IType> binaryType = new ArrayList<IType>();
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
binaryType.add((IType) match.getElement());
}
};
SearchEngine engine = new SearchEngine();
try {
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, null);
} catch (CoreException e1) {
throw new RuntimeException("Error while searching the bundle: " + e1.getMessage());
// return new Status(IStatus.ERROR, Activator.PLUGIN_ID, );
}
return binaryType.isEmpty() ? null : binaryType.get(0);
}
示例2: findAllDeclarations
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
fDeclarations = new ArrayList<>();
class MethodRequestor extends SearchRequestor {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IMethod method = (IMethod) match.getElement();
boolean isBinary = method.isBinary();
if (!isBinary) {
fDeclarations.add(method);
}
}
}
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
MethodRequestor requestor = new MethodRequestor();
SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor);
}
示例3: searchType
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private List<IType> searchType(String classFQN, IProgressMonitor monitor) {
classFQN = classFQN.replace('$', '.');
final List<IType> types = new ArrayList<IType>();
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
SearchEngine engine = new SearchEngine();
SearchPattern pattern = SearchPattern.createPattern(classFQN, IJavaSearchConstants.TYPE,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
SearchRequestor requestor = new SearchRequestor() {
public void acceptSearchMatch(final SearchMatch match) throws CoreException {
TypeDeclarationMatch typeMatch = (TypeDeclarationMatch) match;
IType type = (IType) typeMatch.getElement();
types.add(type);
}
};
try {
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
requestor, monitor);
} catch (final CoreException e) {
return types;
}
return types;
}
示例4: rewriteCompilationUnit
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
protected void rewriteCompilationUnit(ICompilationUnit unit,
Collection matches, CompilationUnit node, RefactoringStatus status,
IProgressMonitor monitor) throws CoreException {
final ASTRewrite astRewrite = ASTRewrite.create(node.getAST());
final ImportRewrite importRewrite = ImportRewrite.create(node, true);
for (final Iterator it = matches.iterator(); it.hasNext();) {
final SearchMatch match = (SearchMatch) it.next();
if (match.getAccuracy() == SearchMatch.A_ACCURATE
&& !match.isInsideDocComment())
if (this.matchToPurposeMap.get(match) == SearchMatchPurpose.ALTER_TYPE_DECLARATION
|| this.matchToPurposeMap.get(match) == SearchMatchPurpose.ALTER_NAMESPACE_PREFIX)
this.rewriteDeclarationsAndNamespaces(node, match, status,
astRewrite, importRewrite);
else if (this.matchToPurposeMap.get(match) == SearchMatchPurpose.ALTER_INFIX_EXPRESSION)
this.rewriteExpressions(node, match, status, astRewrite,
importRewrite);
}
this.rewriteAST(unit, astRewrite, importRewrite);
}
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:22,代码来源:ConvertConstantsToEnumRefactoring.java
示例5: search
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private static List<Controller> search(IJavaProject project, SearchPattern namePattern) throws JavaModelException, CoreException {
List<Controller> controllers = new ArrayList<Controller>();
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(project.getPackageFragments());
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) {
if (match.getElement() instanceof IJavaElement) {
IJavaElement element = (IJavaElement) match.getElement();
controllers.add(new Controller((IType) element));
}
}
};
SearchEngine searchEngine = new SearchEngine();
searchEngine.search(namePattern, new SearchParticipant[] {SearchEngine
.getDefaultSearchParticipant()}, scope, requestor,
null);
return controllers;
}
示例6: getCompilationUnit
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
/**
* @param match the search match
* @return the enclosing {@link ICompilationUnit} of the given match, or null iff none
*/
public static ICompilationUnit getCompilationUnit(SearchMatch match) {
IJavaElement enclosingElement = getEnclosingJavaElement(match);
if (enclosingElement != null) {
if (enclosingElement instanceof ICompilationUnit) return (ICompilationUnit) enclosingElement;
ICompilationUnit cu =
(ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT);
if (cu != null) return cu;
}
IJavaElement jElement = JavaCore.create(match.getResource());
if (jElement != null
&& jElement.exists()
&& jElement.getElementType() == IJavaElement.COMPILATION_UNIT)
return (ICompilationUnit) jElement;
return null;
}
示例7: addReferenceUpdates
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
SearchResultGroup[] grouped = getOccurrences();
for (int i = 0; i < grouped.length; i++) {
SearchResultGroup group = grouped[i];
SearchMatch[] results = group.getSearchResults();
ICompilationUnit cu = group.getCompilationUnit();
TextChange change = manager.get(cu);
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
if (!(match instanceof MethodDeclarationMatch)) {
ReplaceEdit replaceEdit = createReplaceEdit(match, cu);
String editName = RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
addTextEdit(change, editName, replaceEdit);
}
}
}
pm.done();
}
示例8: searchForOuterTypesOfReferences
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm)
throws CoreException {
final Set<IType> outerTypesOfReferences = new HashSet<IType>();
SearchPattern pattern =
RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
IJavaSearchScope scope = createRefactoringScope(getMethod());
SearchRequestor requestor =
new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object element = match.getElement();
if (!(element instanceof IMember))
return; // e.g. an IImportDeclaration for a static method import
IMember member = (IMember) element;
IType declaring = member.getDeclaringType();
if (declaring == null) return;
IType outer = declaring.getDeclaringType();
if (outer != null) outerTypesOfReferences.add(declaring);
}
};
new SearchEngine()
.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
示例9: searchForDeclarationsOfClashingMethods
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private IMethod[] searchForDeclarationsOfClashingMethods(IProgressMonitor pm)
throws CoreException {
final List<IMethod> results = new ArrayList<IMethod>();
SearchPattern pattern = createNewMethodPattern();
IJavaSearchScope scope = RefactoringScopeFactory.create(getMethod().getJavaProject());
SearchRequestor requestor =
new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object method = match.getElement();
if (method
instanceof
IMethod) // check for bug 90138: [refactoring] [rename] Renaming method throws
// internal exception
results.add((IMethod) method);
else
JavaPlugin.logErrorMessage(
"Unexpected element in search match: " + match.toString()); // $NON-NLS-1$
}
};
new SearchEngine()
.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return results.toArray(new IMethod[results.size()]);
}
示例10: 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());
}
}
示例11: 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);
}
}
示例12: analyzeRenameChanges
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
static RefactoringStatus analyzeRenameChanges(
TextChangeManager manager,
SearchResultGroup[] oldOccurrences,
SearchResultGroup[] newOccurrences) {
RefactoringStatus result = new RefactoringStatus();
for (int i = 0; i < oldOccurrences.length; i++) {
SearchResultGroup oldGroup = oldOccurrences[i];
SearchMatch[] oldSearchResults = oldGroup.getSearchResults();
ICompilationUnit cunit = oldGroup.getCompilationUnit();
if (cunit == null) continue;
for (int j = 0; j < oldSearchResults.length; j++) {
SearchMatch oldSearchResult = oldSearchResults[j];
if (!RenameAnalyzeUtil.existsInNewOccurrences(oldSearchResult, newOccurrences, manager)) {
addShadowsError(cunit, oldSearchResult, result);
}
}
}
return result;
}
示例13: addReferenceShadowedError
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private static void addReferenceShadowedError(
ICompilationUnit cu, SearchMatch newMatch, String newElementName, RefactoringStatus result) {
// Found a new match with no corresponding old match.
// -> The new match is a reference which was pointing to another element,
// but that other element has been shadowed
// TODO: should not have to filter declarations:
if (newMatch instanceof MethodDeclarationMatch || newMatch instanceof FieldDeclarationMatch)
return;
ISourceRange range = getOldSourceRange(newMatch);
RefactoringStatusContext context = JavaStatusContext.create(cu, range);
String message =
Messages.format(
RefactoringCoreMessages.RenameAnalyzeUtil_reference_shadowed,
new String[] {
BasicElementLabels.getFileName(cu),
BasicElementLabels.getJavaElementName(newElementName)
});
result.addError(message, context);
}
示例14: getResults
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
public List<V> getResults() {
while (!isDone) {
synchronized (this) {
try {
wait(50);
} catch (InterruptedException e) {
DataHierarchyPlugin.logError("getResults() interrupted...", e);
}
}
}
List<V> results = new ArrayList<V>();
for (SearchMatch match : searchResults) {
results.add((V) match.getElement());
}
return results;
}
示例15: getAllRippleMethods
import org.eclipse.jdt.core.search.SearchMatch; //导入依赖的package包/类
private IMethod[] getAllRippleMethods(IProgressMonitor pm, WorkingCopyOwner owner)
throws CoreException {
IMethod[] rippleMethods = findAllRippleMethods(pm, owner);
if (fDeclarationToMatch == null) return rippleMethods;
List<IMethod> rippleMethodsList = new ArrayList<IMethod>(Arrays.asList(rippleMethods));
for (Iterator<IMethod> iter = rippleMethodsList.iterator(); iter.hasNext(); ) {
Object match = fDeclarationToMatch.get(iter.next());
if (match != null) {
iter.remove();
fBinaryRefs.add((SearchMatch) match);
}
}
fDeclarationToMatch = null;
return rippleMethodsList.toArray(new IMethod[rippleMethodsList.size()]);
}