下面列出了org.eclipse.ui.dialogs.SearchPattern#matches ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected Predicate<IEObjectDescription> getSearchPredicate(final String stringPattern,
final String typeStringPattern) {
final Collection<String> namespaceDelimiters = IXtextSearchFilter.Registry.allNamespaceDelimiters();
final SearchPattern searchPattern = new SearchPattern();
searchPattern.setPattern(stringPattern);
final SearchPattern typeSearchPattern = new SearchPattern();
typeSearchPattern.setPattern(typeStringPattern);
final Collection<IXtextSearchFilter> registeredFilters = IXtextSearchFilter.Registry.allFilters();
return new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
if (isNameMatches(searchPattern, input, namespaceDelimiters)
&& typeSearchPattern.matches(input.getEClass().getName())) {
for (IXtextSearchFilter xtextSearchFilter : registeredFilters) {
if (xtextSearchFilter.reject(input)) {
return false;
}
}
return true;
}
return false;
}
};
}
protected boolean isNameMatches(SearchPattern searchPattern, IEObjectDescription eObjectDescription, Collection<String> namespaceDelimiters) {
String qualifiedName = eObjectDescription.getQualifiedName().toString();
if (qualifiedName!=null) {
if(searchPattern.matches(qualifiedName)) {
return true;
}
for(String namespaceDelimiter : namespaceDelimiters) {
int index = qualifiedName.lastIndexOf(namespaceDelimiter);
if(index!=-1 && searchPattern.matches(qualifiedName.substring(index+1))) {
return true;
}
}
}
return false;
}
/**
* Matches according to scopes.
*/
public static boolean matchItem(SearchPattern patternMatcher, IInfo info) {
//We want to match the package name in the beggining too...
String pattern = patternMatcher.getPattern();
List<String> split = StringUtils.splitAndRemoveEmptyTrimmed(pattern, '.');
if (split.size() <= 1) {
if (pattern.endsWith(".")) {
split.add("");
} else {
return patternMatcher.matches(info.getName());
}
}
//Otherwise, we have more things to match... We could match something like:
//django.AAA -- which should match all the modules that start with django and the tokens that have AAA.
String declaringModuleName = info.getDeclaringModuleName();
if (declaringModuleName == null || declaringModuleName.length() == 0) {
return false;
}
List<String> moduleParts = StringUtils.splitAndRemoveEmptyTrimmed(declaringModuleName, '.');
while (split.size() > 1) {
String head = split.remove(0);
SearchPattern headPattern = new SearchPattern();
headPattern.setPattern(head);
if (moduleParts.size() == 0) {
return false; //we cannot match it anymore
}
if (!headPattern.matches(moduleParts.remove(0))) {
return false;
}
}
//if it got here, we've matched the module correctly... let's go on and check the name.
SearchPattern tailPattern = new SearchPattern();
tailPattern.setPattern(split.get(0));
return tailPattern.matches(info.getName());
}