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>() { 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; } }; }
public ModuleItemsFilter() { super(new ModuleSearchPattern()); /* * If there is no filter pattern present, initialize the pattern to '*'. * This has the nice property of pre-populating the dialog list with all * possible matches when it is first shown. */ if (patternMatcher.getPattern() == null || patternMatcher.getPattern().length() == 0) { patternMatcher.setPattern("*"); } // If a package pattern is present in the filter text, then set up // a packageMatcher to do matching based on the module's package. String stringPackage = ((ModuleSearchPattern) patternMatcher).getPackagePattern(); if (stringPackage != null) { packageMatcher = new SearchPattern(); packageMatcher.setPattern(stringPackage); } else { packageMatcher = null; } }
private void refreshSearchIndices(IProgressMonitor monitor) throws InvocationTargetException { try { new SearchEngine().searchAllTypeNames( null, 0, // make sure we search a concrete name. This is faster // according to Kent "_______________".toCharArray(), //$NON-NLS-1$ SearchPattern.RULE_EXACT_MATCH | SearchPattern.RULE_CASE_SENSITIVE, IDLTKSearchConstants.TYPE, SearchEngine .createWorkspaceScope(tookit.getCoreToolkit()), new NopTypeNameRequestor(), IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); } catch (ModelException e) { throw new InvocationTargetException(e); } }
/** * Creates instance of TypeItemsFilter * * @param scope * @param elementKind * @param extension */ public TypeItemsFilter(IDLTKSearchScope scope, int elementKind, ITypeInfoFilterExtension extension) { super(new TypeSearchPattern()); fScope = scope; fIsWorkspaceScope = scope == null ? false : scope .equals(SearchEngine.createWorkspaceScope(fToolkit)); fElemKind = elementKind; fFilterExt = extension; String stringPackage = ((TypeSearchPattern) patternMatcher) .getPackagePattern(); if (stringPackage != null) { fPackageMatcher = new SearchPattern(); fPackageMatcher.setPattern(stringPackage); } else { fPackageMatcher = null; } }
protected boolean isTextMatchingSearchPattern(String text, String searchPattern) { SearchPattern matcher = new SearchPattern(SearchPattern.RULE_PATTERN_MATCH | SearchPattern.RULE_EXACT_MATCH | SearchPattern.RULE_PREFIX_MATCH | SearchPattern.RULE_BLANK_MATCH); matcher.setPattern("*" + searchPattern); return matcher.matches(text); }
protected boolean isTextMatchingSearchPattern(String text) { SearchPattern matcher = new SearchPattern(SearchPattern.RULE_PATTERN_MATCH | SearchPattern.RULE_EXACT_MATCH | SearchPattern.RULE_PREFIX_MATCH | SearchPattern.RULE_BLANK_MATCH); matcher.setPattern("*" + searchPattern); return matcher.matches(text); }
/** * Creates new instance of ItemsFilter. * * @param searchPattern * the pattern to be used when filtering */ public ItemsFilter(SearchPattern searchPattern) { patternMatcher = searchPattern; String stringPattern = ""; //$NON-NLS-1$ if (pattern != null && !pattern.getText().equals("*")) { //$NON-NLS-1$ stringPattern = pattern.getText(); } patternMatcher.setPattern(stringPattern); }
protected boolean isNameMatches(SearchPattern searchPattern, IEObjectDescription eObjectDescription, Collection<String> namespaceDelimiters) { String qualifiedName = qualifiedNameConverter.toString(eObjectDescription.getQualifiedName()); 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()); }
/** * Checks if equals considering scopes. */ public static boolean equalsFilter(String thisPattern, String otherPattern) { return checkPatternSubparts(thisPattern, otherPattern, new ICallback2<Boolean, SearchPattern, SearchPattern>() { @Override public Boolean call(SearchPattern thisP, SearchPattern otherP) { if (!(thisP.equalsPattern(otherP))) { return false; } return true; } }); }
/** * Checks if it's a sub-filter considering scopes. */ public static boolean isSubFilter(String thisPattern, String otherPattern) { return checkPatternSubparts(thisPattern, otherPattern, new ICallback2<Boolean, SearchPattern, SearchPattern>() { @Override public Boolean call(SearchPattern thisP, SearchPattern otherP) { if (!(thisP.isSubPattern(otherP))) { return false; } return true; } }); }
private static boolean checkPatternSubparts(String thisPattern, String otherPattern, ICallback2<Boolean, SearchPattern, SearchPattern> check) { boolean thisEndsWithPoint = thisPattern.endsWith("."); boolean otherEndsWithPoint = otherPattern.endsWith("."); if (thisEndsWithPoint != otherEndsWithPoint) { return false; } List<String> thisSplit = StringUtils.splitAndRemoveEmptyNotTrimmed(thisPattern, '.'); List<String> otherSplit = StringUtils.splitAndRemoveEmptyNotTrimmed(otherPattern, '.'); if (thisEndsWithPoint) { thisSplit.add(""); } if (otherEndsWithPoint) { otherSplit.add(""); } if (thisSplit.size() != otherSplit.size()) { return false; } for (int i = 0; i < thisSplit.size(); i++) { String thisStr = thisSplit.get(i); String otherStr = otherSplit.get(i); SearchPattern thisP = new SearchPattern(); thisP.setPattern(thisStr); SearchPattern otherP = new SearchPattern(); otherP.setPattern(otherStr); if (!check.call(thisP, otherP)) { return false; } } return true; }
private final int[] getMatchingRegions(String pattern, String name, int matchRule) { if (name == null) return null; final int nameLength = name.length(); if (pattern == null) { return new int[] { 0, nameLength }; } final int patternLength = pattern.length(); switch (matchRule) { case SearchPattern.RULE_EXACT_MATCH: if (patternLength == nameLength && pattern.equalsIgnoreCase(name)) { return new int[] { 0, patternLength }; } break; case SearchPattern.RULE_EXACT_MATCH | SearchPattern.RULE_CASE_SENSITIVE: if (patternLength == nameLength && pattern.equals(name)) { return new int[] { 0, patternLength }; } break; case SearchPattern.RULE_PREFIX_MATCH: if (patternLength <= nameLength && name.substring(0, patternLength).equalsIgnoreCase(pattern)) { return new int[] { 0, patternLength }; } break; case SearchPattern.RULE_PREFIX_MATCH | SearchPattern.RULE_CASE_SENSITIVE: if (name.startsWith(pattern)) { return new int[] { 0, patternLength }; } break; case SearchPattern.RULE_PATTERN_MATCH: return StringUtils.getPatternMatchingRegions(pattern, 0, patternLength, name, 0, nameLength, false); case SearchPattern.RULE_PATTERN_MATCH | SearchPattern.RULE_CASE_SENSITIVE: return StringUtils.getPatternMatchingRegions(pattern, 0, patternLength, name, 0, nameLength, true); } return null; }
public PipelineOptionsSelectionFilter() { super( new SearchPattern(SearchPattern.RULE_CAMELCASE_MATCH | SearchPattern.RULE_PATTERN_MATCH)); }
public ResourceFilter() { super(new SearchPattern(SearchPattern.RULE_PATTERN_MATCH)); String pattern = "*" + patternMatcher.getPattern() + "*"; patternMatcher.setPattern(pattern); }
/** * Creates new instance of ItemsFilter. */ public ItemsFilter() { this(new SearchPattern()); }
public void testPatternMatch() throws Exception { SearchPattern patternMatcher = new SearchPattern(); patternMatcher.setPattern("aa"); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aa", null, null, null))); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", null, null, null))); assertFalse(MatchHelper.matchItem(patternMatcher, new ClassInfo("baaa", null, null, null))); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "coi.foo", null, null))); patternMatcher.setPattern("xx.aa"); assertFalse(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "invalid.foo", null, null))); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "xx.foo", null, null))); patternMatcher.setPattern("xx.foo.aa"); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "xx.foo.bar", null, null))); patternMatcher.setPattern("xx.foo.bar.aa"); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "xx.foo.bar", null, null))); patternMatcher.setPattern("xx.foo.bar.aa.aa"); assertFalse(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "xx.foo.bar", null, null))); patternMatcher.setPattern("xx.foo.ba.aa"); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "xx.foo.bar", null, null))); patternMatcher.setPattern("xx.fo*o.ba.aa"); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("aaa", "xx.foo.bar", null, null))); patternMatcher.setPattern("coi*.intersection"); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("Intersection", "coilib50.basic.native", null, null))); patternMatcher.setPattern("coilib50.intersection"); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("Intersection", "coilib50.basic.native", null, null))); patternMatcher.setPattern("coilib50."); assertTrue(MatchHelper.matchItem(patternMatcher, new ClassInfo("Intersection", "coilib50.basic.native", null, null))); }
protected void fillContentProvider(AbstractContentProvider provider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException { TypeItemsFilter typeSearchFilter = (TypeItemsFilter) itemsFilter; TypeSearchRequestor requestor = new TypeSearchRequestor(provider, typeSearchFilter); String typePattern = itemsFilter.getPattern(); progressMonitor .setTaskName(DLTKUIMessages.FilteredTypesSelectionDialog_searchJob_taskName); IType[] types = new ModelAccess().findTypes(typePattern, ModelAccess .convertSearchRule(itemsFilter.getMatchRule()), 0, Modifiers.AccNameSpace, typeSearchFilter.getSearchScope(), progressMonitor); if (types != null) { for (IType type : types) { requestor.acceptTypeNameMatch(new DLTKSearchTypeNameMatch(type, type.getFlags())); } } else { SearchEngine engine = new SearchEngine((WorkingCopyOwner) null); String packPattern = typeSearchFilter.getPackagePattern(); /* * Setting the filter into match everything mode avoids filtering * twice by the same pattern (the search engine only provides * filtered matches). For the case when the pattern is a camel case * pattern with a terminator, the filter is not set to match * everything mode because jdt.core's SearchPattern does not support * that case. */ int matchRule = typeSearchFilter.getMatchRule(); if (matchRule == SearchPattern.RULE_CAMELCASE_MATCH) { // If the pattern is empty, the RULE_BLANK_MATCH will be chosen, // so // we don't have to check the pattern length char lastChar = typePattern.charAt(typePattern.length() - 1); if (lastChar == '<' || lastChar == ' ') { typePattern = typePattern.substring(0, typePattern.length() - 1); } else { typeSearchFilter.setMatchEverythingMode(true); } } else { typeSearchFilter.setMatchEverythingMode(true); } try { engine.searchAllTypeNames( packPattern == null ? null : packPattern.toCharArray(), typeSearchFilter.getPackageFlags(), // https://bugs.eclipse.org/bugs/show_bug.cgi?id=176017 typePattern.toCharArray(), matchRule, // https://bugs.eclipse.org/bugs/show_bug.cgi?id=176017 typeSearchFilter.getElementKind(), typeSearchFilter .getSearchScope(), requestor, IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, progressMonitor); } finally { typeSearchFilter.setMatchEverythingMode(false); } } }
public int getPackageFlags() { if (fPackageMatcher == null) return SearchPattern.RULE_EXACT_MATCH; return fPackageMatcher.getMatchRule(); }
/** * Checks whether the pattern's match rule is camel case. * * @return <code>true</code> if pattern's match rule is camel case, * <code>false</code> otherwise */ public boolean isCamelCasePattern() { return patternMatcher.getMatchRule() == SearchPattern.RULE_CAMELCASE_MATCH; }