Java Code Examples for org.eclipse.ui.dialogs.SearchPattern#matches()

The following examples show how to use org.eclipse.ui.dialogs.SearchPattern#matches() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IXtextEObjectSearch.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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;
		}
	};
}
 
Example 2
Source File: IXtextEObjectSearch.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: MatchHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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());
}