本文整理汇总了Java中org.eclipse.jdt.core.search.IJavaSearchConstants类的典型用法代码示例。如果您正苦于以下问题:Java IJavaSearchConstants类的具体用法?Java IJavaSearchConstants怎么用?Java IJavaSearchConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IJavaSearchConstants类属于org.eclipse.jdt.core.search包,在下文中一共展示了IJavaSearchConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getITypeMainByWorkspaceScope
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的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: findType
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
/**
* Find type
*
* @param className
* @param monitor
* @return type or <code>null</code>
*/
public IType findType(String className, IProgressMonitor monitor) {
final IType[] result = { null };
TypeNameMatchRequestor nameMatchRequestor = new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch match) {
result[0] = match.getType();
}
};
int lastDot = className.lastIndexOf('.');
char[] packageName = lastDot >= 0 ? className.substring(0, lastDot).toCharArray() : null;
char[] typeName = (lastDot >= 0 ? className.substring(lastDot + 1) : className).toCharArray();
SearchEngine engine = new SearchEngine();
int packageMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
try {
engine.searchAllTypeNames(packageName, packageMatchRule, typeName, packageMatchRule, IJavaSearchConstants.TYPE,
SearchEngine.createWorkspaceScope(), nameMatchRequestor,
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
} catch (JavaModelException e) {
EditorUtil.INSTANCE.logError("Was not able to search all type names",e);
}
return result[0];
}
示例3: findAllDeclarations
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的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);
}
示例4: createOccurrenceSearchPattern
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
protected SearchPattern createOccurrenceSearchPattern(IJavaElement[] elements) throws CoreException {
if (elements == null || elements.length == 0) {
return null;
}
Set<IJavaElement> set = new HashSet<>(Arrays.asList(elements));
Iterator<IJavaElement> iter = set.iterator();
IJavaElement first = iter.next();
SearchPattern pattern = SearchPattern.createPattern(first, IJavaSearchConstants.ALL_OCCURRENCES);
if (pattern == null) {
throw new CoreException(Status.CANCEL_STATUS);
}
while (iter.hasNext()) {
IJavaElement each = iter.next();
SearchPattern nextPattern = SearchPattern.createPattern(each, IJavaSearchConstants.ALL_OCCURRENCES);
if (nextPattern == null) {
throw new CoreException(Status.CANCEL_STATUS);
}
pattern = SearchPattern.createOrPattern(pattern, nextPattern);
}
return pattern;
}
示例5: getURI
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
public static String getURI(IProject project, String fqcn) throws JavaModelException {
Assert.isNotNull(project, "Project can't be null");
Assert.isNotNull(fqcn, "FQCN can't be null");
IJavaProject javaProject = JavaCore.create(project);
int lastDot = fqcn.lastIndexOf(".");
String packageName = lastDot > 0? fqcn.substring(0, lastDot):"";
String className = lastDot > 0? fqcn.substring(lastDot+1):fqcn;
ClassUriExtractor extractor = new ClassUriExtractor();
new SearchEngine().searchAllTypeNames(packageName.toCharArray(),SearchPattern.R_EXACT_MATCH,
className.toCharArray(), SearchPattern.R_EXACT_MATCH,
IJavaSearchConstants.TYPE,
JDTUtils.createSearchScope(javaProject),
extractor,
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
new NullProgressMonitor());
return extractor.uri;
}
示例6: searchType
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的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;
}
示例7: getSearchForConstant
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
private int getSearchForConstant(int typeKinds) {
final int CLASSES = SimilarElementsRequestor.CLASSES;
final int INTERFACES = SimilarElementsRequestor.INTERFACES;
final int ENUMS = SimilarElementsRequestor.ENUMS;
final int ANNOTATIONS = SimilarElementsRequestor.ANNOTATIONS;
switch (typeKinds & (CLASSES | INTERFACES | ENUMS | ANNOTATIONS)) {
case CLASSES:
return IJavaSearchConstants.CLASS;
case INTERFACES:
return IJavaSearchConstants.INTERFACE;
case ENUMS:
return IJavaSearchConstants.ENUM;
case ANNOTATIONS:
return IJavaSearchConstants.ANNOTATION_TYPE;
case CLASSES | INTERFACES:
return IJavaSearchConstants.CLASS_AND_INTERFACE;
case CLASSES | ENUMS:
return IJavaSearchConstants.CLASS_AND_ENUM;
default:
return IJavaSearchConstants.TYPE;
}
}
示例8: searchForOuterTypesOfReferences
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的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: findReferences
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
private SearchResultGroup[] findReferences(IProgressMonitor pm, RefactoringStatus status)
throws JavaModelException {
final RefactoringSearchEngine2 engine =
new RefactoringSearchEngine2(
SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES));
engine.setFiltering(true, true);
engine.setScope(RefactoringScopeFactory.create(fField));
engine.setStatus(status);
engine.setRequestor(
new IRefactoringSearchRequestor() {
public SearchMatch acceptSearchMatch(SearchMatch match) {
return match.isInsideDocComment() ? null : match;
}
});
engine.searchPattern(new SubProgressMonitor(pm, 1));
return (SearchResultGroup[]) engine.getResults();
}
示例10: createSearchPattern
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
/**
* @param ctor
* @param methodBinding
* @return a <code>SearchPattern</code> that finds all calls to the constructor identified by the
* argument <code>methodBinding</code>.
*/
private SearchPattern createSearchPattern(IMethod ctor, IMethodBinding methodBinding) {
Assert.isNotNull(
methodBinding, RefactoringCoreMessages.IntroduceFactory_noBindingForSelectedConstructor);
if (ctor != null)
return SearchPattern.createPattern(
ctor, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
else { // perhaps a synthetic method? (but apparently not always... hmmm...)
// Can't find an IMethod for this method, so build a string pattern instead
StringBuffer buf = new StringBuffer();
buf.append(methodBinding.getDeclaringClass().getQualifiedName()).append("("); // $NON-NLS-1$
for (int i = 0; i < fArgTypes.length; i++) {
if (i != 0) buf.append(","); // $NON-NLS-1$
buf.append(fArgTypes[i].getQualifiedName());
}
buf.append(")"); // $NON-NLS-1$
return SearchPattern.createPattern(
buf.toString(),
IJavaSearchConstants.CONSTRUCTOR,
IJavaSearchConstants.REFERENCES,
SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
}
}
示例11: getReferences
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
private static SearchResultGroup[] getReferences(
ICompilationUnit unit, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
final SearchPattern pattern =
RefactoringSearchEngine.createOrPattern(unit.getTypes(), IJavaSearchConstants.REFERENCES);
if (pattern != null) {
String binaryRefsDescription =
Messages.format(
RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description,
BasicElementLabels.getFileName(unit));
ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
Collector requestor = new Collector(((IPackageFragment) unit.getParent()), binaryRefs);
IJavaSearchScope scope = RefactoringScopeFactory.create(unit, true, false);
SearchResultGroup[] result =
RefactoringSearchEngine.search(
pattern, scope, requestor, new SubProgressMonitor(pm, 1), status);
binaryRefs.addErrorIfNecessary(status);
return result;
}
return new SearchResultGroup[] {};
}
示例12: isApplicable
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
@Override
public boolean isApplicable(JavaSearchQuery query) {
QuerySpecification spec = query.getSpecification();
switch (spec.getLimitTo()) {
case IJavaSearchConstants.REFERENCES:
case IJavaSearchConstants.ALL_OCCURRENCES:
if (spec instanceof ElementQuerySpecification) {
ElementQuerySpecification elementSpec = (ElementQuerySpecification) spec;
return elementSpec.getElement() instanceof IMethod;
} else if (spec instanceof PatternQuerySpecification) {
PatternQuerySpecification patternSpec = (PatternQuerySpecification) spec;
return patternSpec.getSearchFor() == IJavaSearchConstants.METHOD;
}
}
return false;
}
示例13: findTypeByFqn
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
private List<IType> findTypeByFqn(char[][] packages, char[][] names, IJavaSearchScope scope)
throws JavaModelException {
List<IType> result = new ArrayList<>();
SearchEngine searchEngine = new SearchEngine();
searchEngine.searchAllTypeNames(
packages,
names,
scope,
new TypeNameMatchRequestor() {
@Override
public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) {
result.add(typeNameMatch.getType());
}
},
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
new NullProgressMonitor());
return result;
}
示例14: getReferences
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
/**
* Blocks current thread until search is done
*/
public List<IJavaElement> getReferences(IProgressMonitor monitor) throws CoreException {
pattern = SearchPattern.createPattern(searchRoot.getJavaElement(),
IJavaSearchConstants.REFERENCES
| ~IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE,
// | IJavaSearchConstants.IGNORE_DECLARING_TYPE,
SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE
| SearchPattern.R_ERASURE_MATCH);
if (pattern == null) {
// this is packages???
// System.out.println("Search patter is null for: " + elt.getElementName());
return new ArrayList<IJavaElement>();
}
scope = conf.createScope(searchRoot.getJavaElement());
JavaReferencesRequestor searchRequestor = new JavaReferencesRequestor();
return search(searchRequestor, monitor);
}
示例15: createAnyFieldPattern
import org.eclipse.jdt.core.search.IJavaSearchConstants; //导入依赖的package包/类
private static SearchPattern createAnyFieldPattern(IType[] types) {
if (types.length == 0) {
return createAnyFieldPattern();
}
SearchPattern result = null;
for (IType type : types) {
SearchPattern searchPattern = SearchPattern.createPattern(type.getFullyQualifiedName()
+ ".*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS,
SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
if(result == null){
result = searchPattern;
} else {
result = SearchPattern.createOrPattern(result, searchPattern);
}
}
return result;
}