Java Code Examples for org.eclipse.jdt.core.search.SearchPattern#R_EXACT_MATCH
The following examples show how to use
org.eclipse.jdt.core.search.SearchPattern#R_EXACT_MATCH .
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: TypeContextChecker.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static List<TypeNameMatch> findTypeInfos(String typeName, IType contextType, IProgressMonitor pm) throws JavaModelException { IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaProject[]{contextType.getJavaProject()}, true); IPackageFragment currPackage= contextType.getPackageFragment(); ArrayList<TypeNameMatch> collectedInfos= new ArrayList<TypeNameMatch>(); TypeNameMatchCollector requestor= new TypeNameMatchCollector(collectedInfos); int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; new SearchEngine().searchAllTypeNames(null, matchMode, typeName.toCharArray(), matchMode, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, pm); List<TypeNameMatch> result= new ArrayList<TypeNameMatch>(); for (Iterator<TypeNameMatch> iter= collectedInfos.iterator(); iter.hasNext();) { TypeNameMatch curr= iter.next(); IType type= curr.getType(); if (type != null) { boolean visible=true; try { visible= JavaModelUtil.isVisible(type, currPackage); } catch (JavaModelException e) { //Assume visibile if not available } if (visible) { result.add(curr); } } } return result; }
Example 2
Source File: AddImportsOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private TypeNameMatch[] findAllTypes(String simpleTypeName, IJavaSearchScope searchScope, SimpleName nameNode, IProgressMonitor monitor) throws JavaModelException { boolean is50OrHigher= JavaModelUtil.is50OrHigher(fCompilationUnit.getJavaProject()); int typeKinds= SimilarElementsRequestor.ALL_TYPES; if (nameNode != null) { typeKinds= ASTResolving.getPossibleTypeKinds(nameNode, is50OrHigher); } ArrayList<TypeNameMatch> typeInfos= new ArrayList<TypeNameMatch>(); TypeNameMatchCollector requestor= new TypeNameMatchCollector(typeInfos); int matchMode= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; new SearchEngine().searchAllTypeNames(null, matchMode, simpleTypeName.toCharArray(), matchMode, getSearchForConstant(typeKinds), searchScope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor); ArrayList<TypeNameMatch> typeRefsFound= new ArrayList<TypeNameMatch>(typeInfos.size()); for (int i= 0, len= typeInfos.size(); i < len; i++) { TypeNameMatch curr= typeInfos.get(i); if (curr.getPackageName().length() > 0) { // do not suggest imports from the default package if (isOfKind(curr, typeKinds, is50OrHigher) && isVisible(curr)) { typeRefsFound.add(curr); } } } return typeRefsFound.toArray(new TypeNameMatch[typeRefsFound.size()]); }
Example 3
Source File: PatternMatcher.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean matches(String text) { switch (fMatchKind) { case SearchPattern.R_PATTERN_MATCH: return fStringMatcher.match(text); case SearchPattern.R_EXACT_MATCH: return fPattern.equalsIgnoreCase(text); case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH: return SearchPattern.camelCaseMatch(fPattern, text, true); case SearchPattern.R_CAMELCASE_MATCH: if (SearchPattern.camelCaseMatch(fPattern, text)) { return true; } // fall back to prefix match if camel case failed (bug 137244) return Strings.startsWithIgnoreCase(text, fPattern); default: return Strings.startsWithIgnoreCase(text, fPattern); } }
Example 4
Source File: JavaSearchQuery.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int getMatchMode(String pattern) { if (pattern.indexOf('*') != -1 || pattern.indexOf('?') != -1) { return SearchPattern.R_PATTERN_MATCH; } else if (SearchUtils.isCamelCasePattern(pattern)) { return SearchPattern.R_CAMELCASE_MATCH; } return SearchPattern.R_EXACT_MATCH; }
Example 5
Source File: MethodFilter.java From jdt-codemining with Eclipse Public License 1.0 | 4 votes |
/** * Return how the given name matches the given pattern. * * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866" * * @param pattern * @param name * @return Possible values are: * <ul> * <li>{@link #ACCURATE_MATCH}</li> * <li>{@link #IMPOSSIBLE_MATCH}</li> * <li>{@link #POSSIBLE_MATCH} which may be flavored with following * values: * <ul> * <li>{@link #EXACT_FLAVOR}: Given name is equals to pattern</li> * <li>{@link #PREFIX_FLAVOR}: Given name prefix equals to pattern</li> * <li>{@link #CAMELCASE_FLAVOR}: Given name matches pattern as Camel * Case</li> * <li>{@link #PATTERN_FLAVOR}: Given name matches pattern as Pattern * (i.e. using '*' and '?' characters)</li> * </ul> * </li> * </ul> */ protected boolean matchNameValue(char[] pattern, char[] name) { if (pattern == null) return true; // ACCURATE_MATCH; // null is as if it was "*" if (name == null) return false; // IMPOSSIBLE_MATCH; // cannot match null name if (name.length == 0) { // empty name if (pattern.length == 0) { // can only matches empty pattern return true; // ACCURATE_MATCH; } return false; // IMPOSSIBLE_MATCH; } else if (pattern.length == 0) { return false; // IMPOSSIBLE_MATCH; // need to have both name and pattern length==0 to be // accurate } boolean matchFirstChar = !this.isCaseSensitive || pattern[0] == name[0]; boolean sameLength = pattern.length == name.length; boolean canBePrefix = name.length >= pattern.length; switch (this.matchMode) { case SearchPattern.R_EXACT_MATCH: if (sameLength && matchFirstChar && CharOperation.equals(pattern, name, this.isCaseSensitive)) { return true; // POSSIBLE_MATCH | EXACT_FLAVOR; } break; case SearchPattern.R_PREFIX_MATCH: if (canBePrefix && matchFirstChar && CharOperation.prefixEquals(pattern, name, this.isCaseSensitive)) { return true; // POSSIBLE_MATCH; } break; case SearchPattern.R_PATTERN_MATCH: // TODO_PERFS (frederic) Not sure this lowercase is necessary if (!this.isCaseSensitive) { pattern = CharOperation.toLowerCase(pattern); } if (CharOperation.match(pattern, name, this.isCaseSensitive)) { return true; // POSSIBLE_MATCH; } break; case SearchPattern.R_REGEXP_MATCH: if (Pattern.matches(new String(pattern), new String(name))) { return true; // POSSIBLE_MATCH; } break; case SearchPattern.R_CAMELCASE_MATCH: if (CharOperation.camelCaseMatch(pattern, name, false)) { return true; // POSSIBLE_MATCH; } // only test case insensitive as CamelCase same part count already verified // prefix case sensitive if (!this.isCaseSensitive && CharOperation.prefixEquals(pattern, name, false)) { return true; // POSSIBLE_MATCH; } break; case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH: if (CharOperation.camelCaseMatch(pattern, name, true)) { return true; // POSSIBLE_MATCH; } break; } return false; // IMPOSSIBLE_MATCH; }
Example 6
Source File: ProjectAwareUniqueClassNameValidator.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public boolean doCheckUniqueInProject(QualifiedName name, JvmDeclaredType type) throws JavaModelException { IJavaProject javaProject = javaProjectProvider.getJavaProject(type.eResource().getResourceSet()); getContext().put(ProjectAwareUniqueClassNameValidator.OUTPUT_CONFIGS, outputConfigurationProvider.getOutputConfigurations(type.eResource())); String packageName = type.getPackageName(); String typeName = type.getSimpleName(); IndexManager indexManager = JavaModelManager.getIndexManager(); List<IPackageFragmentRoot> sourceFolders = new ArrayList<>(); for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceFolders.add(root); } } if (sourceFolders.isEmpty() || indexManager.awaitingJobsCount() > 0) { // still indexing - don't enter a busy wait loop but ask the source folders directly SourceTraversal sourceTraversal = doCheckUniqueInProjectSource(packageName != null ? packageName : "", typeName, type, sourceFolders); if (sourceTraversal == SourceTraversal.DUPLICATE) { return false; } else if (sourceTraversal == SourceTraversal.UNIQUE) { return true; } } Set<String> workingCopyPaths = new HashSet<>(); ICompilationUnit[] copies = getWorkingCopies(type); if (copies != null) { for (ICompilationUnit workingCopy : copies) { IPath path = workingCopy.getPath(); if (javaProject.getPath().isPrefixOf(path) && !isDerived(workingCopy.getResource())) { if (workingCopy.getPackageDeclaration(packageName).exists()) { IType result = workingCopy.getType(typeName); if (result.exists()) { addIssue(type, workingCopy.getElementName()); return false; } } workingCopyPaths.add(workingCopy.getPath().toString()); } } } // The code below is adapted from BasicSearchEnginge.searchAllSecondaryTypes // The Index is ready, query it for a secondary type char[] pkg = packageName == null ? CharOperation.NO_CHAR : packageName.toCharArray(); TypeDeclarationPattern pattern = new TypeDeclarationPattern(pkg, // CharOperation.NO_CHAR_CHAR, // top level type - no enclosing type names typeName.toCharArray(), // IIndexConstants.TYPE_SUFFIX, // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); IndexQueryRequestor searchRequestor = new IndexQueryRequestor() { @Override public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { if (workingCopyPaths.contains(documentPath)) { return true; // filter out working copies } IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(documentPath)); if (!isDerived(file)) { addIssue(type, file.getName()); return false; } return true; } }; try { SearchParticipant searchParticipant = BasicSearchEngine.getDefaultSearchParticipant(); // Java search only IJavaSearchScope javaSearchScope = BasicSearchEngine.createJavaSearchScope(sourceFolders.toArray(new IJavaElement[0])); PatternSearchJob patternSearchJob = new PatternSearchJob(pattern, searchParticipant, javaSearchScope, searchRequestor); indexManager.performConcurrentJob(patternSearchJob, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return true; } catch (Throwable OperationCanceledException) { return false; } }
Example 7
Source File: TypeInfoFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public int getPackageFlags() { if (fPackageMatcher == null) return SearchPattern.R_EXACT_MATCH; return fPackageMatcher.getMatchKind(); }
Example 8
Source File: PatternMatcher.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public PatternMatcher(String pattern) { this(pattern, SearchPattern.R_EXACT_MATCH | SearchPattern.R_PREFIX_MATCH | SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH); }
Example 9
Source File: PatternMatcher.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void initializePatternAndMatchKind(String pattern) { int length= pattern.length(); if (length == 0) { fMatchKind= SearchPattern.R_EXACT_MATCH; fPattern= pattern; return; } char last= pattern.charAt(length - 1); if (pattern.indexOf('*') != -1 || pattern.indexOf('?') != -1) { fMatchKind= SearchPattern.R_PATTERN_MATCH; switch (last) { case END_SYMBOL: case BLANK: fPattern= pattern.substring(0, length - 1); break; case ANY_STRING: fPattern= pattern; break; default: fPattern= pattern + ANY_STRING; } return; } if (last == END_SYMBOL || last == BLANK) { fPattern= pattern.substring(0, length - 1); if (SearchPattern.validateMatchRule(fPattern,SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH) == SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH) { fMatchKind= SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH; } else { fMatchKind= SearchPattern.R_EXACT_MATCH; } return; } if (SearchUtils.isCamelCasePattern(pattern)) { fMatchKind= SearchPattern.R_CAMELCASE_MATCH; fPattern= pattern; return; } fMatchKind= SearchPattern.R_PREFIX_MATCH; fPattern= pattern; }
Example 10
Source File: PackageReferenceLocator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected int matchLevelForTokens(char[][] tokens) { if (this.pattern.pkgName == null) return ACCURATE_MATCH; switch (this.matchMode) { case SearchPattern.R_EXACT_MATCH: case SearchPattern.R_PREFIX_MATCH: if (CharOperation.prefixEquals(this.pattern.pkgName, CharOperation.concatWith(tokens, '.'), this.isCaseSensitive)) { return POSSIBLE_MATCH; } break; case SearchPattern.R_PATTERN_MATCH: char[] patternName = this.pattern.pkgName[this.pattern.pkgName.length - 1] == '*' ? this.pattern.pkgName : CharOperation.concat(this.pattern.pkgName, ".*".toCharArray()); //$NON-NLS-1$ if (CharOperation.match(patternName, CharOperation.concatWith(tokens, '.'), this.isCaseSensitive)) { return POSSIBLE_MATCH; } break; case SearchPattern.R_REGEXP_MATCH : // TODO (frederic) implement regular expression match break; case SearchPattern.R_CAMELCASE_MATCH: char[] packageName = CharOperation.concatWith(tokens, '.'); if (CharOperation.camelCaseMatch(this.pattern.pkgName, packageName, false)) { return POSSIBLE_MATCH; } // only test case insensitive as CamelCase already verified prefix case sensitive if (!this.isCaseSensitive && CharOperation.prefixEquals(this.pattern.pkgName, packageName, false)) { return POSSIBLE_MATCH; } break; case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH: if (CharOperation.camelCaseMatch(this.pattern.pkgName, CharOperation.concatWith(tokens, '.'), true)) { return POSSIBLE_MATCH; } break; } return IMPOSSIBLE_MATCH; }