List of usage examples for org.eclipse.jdt.core.compiler CharOperation toLowerCase
final static public char[] toLowerCase(char[] chars)
From source file:com.codenvy.ide.ext.java.server.core.search.SearchPattern.java
License:Open Source License
/** * Returns whether the given name matches the given pattern. * <p>/*from w w w. j a v a 2s . co m*/ * This method should be re-implemented in subclasses that need to define how * a name matches a pattern. * </p> * * @param pattern the given pattern, or <code>null</code> to represent "*" * @param name the given name * @return whether the given name matches the given pattern */ public boolean matchesName(char[] pattern, char[] name) { if (pattern == null) return true; // null is as if it was "*" if (name != null) { boolean isCaseSensitive = (this.matchRule & R_CASE_SENSITIVE) != 0; int matchMode = this.matchRule & MODE_MASK; boolean emptyPattern = pattern.length == 0; if (emptyPattern && (this.matchRule & R_PREFIX_MATCH) != 0) return true; boolean sameLength = pattern.length == name.length; boolean canBePrefix = name.length >= pattern.length; boolean matchFirstChar = !isCaseSensitive || emptyPattern || (name.length > 0 && pattern[0] == name[0]); switch (matchMode) { case R_EXACT_MATCH: if (sameLength && matchFirstChar) { return CharOperation.equals(pattern, name, isCaseSensitive); } break; case R_PREFIX_MATCH: if (canBePrefix && matchFirstChar) { return CharOperation.prefixEquals(pattern, name, isCaseSensitive); } break; case R_PATTERN_MATCH: if (!isCaseSensitive) pattern = CharOperation.toLowerCase(pattern); return CharOperation.match(pattern, name, isCaseSensitive); case SearchPattern.R_CAMELCASE_MATCH: if (matchFirstChar && CharOperation.camelCaseMatch(pattern, name, false)) { return true; } // only test case insensitive as CamelCase already verified prefix case sensitive if (!isCaseSensitive && matchFirstChar && CharOperation.prefixEquals(pattern, name, false)) { return true; } break; case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH: return matchFirstChar && CharOperation.camelCaseMatch(pattern, name, true); case R_REGEXP_MATCH: // TODO implement regular expression match return true; } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
boolean match(char patternTypeSuffix, char[] patternPkg, int matchRulePkg, char[] patternTypeName, int matchRuleType, int typeKind, char[] pkg, char[] typeName) { switch (patternTypeSuffix) { case IIndexConstants.CLASS_SUFFIX: if (typeKind != TypeDeclaration.CLASS_DECL) return false; break;/* w w w.java2 s . c om*/ case IIndexConstants.CLASS_AND_INTERFACE_SUFFIX: if (typeKind != TypeDeclaration.CLASS_DECL && typeKind != TypeDeclaration.INTERFACE_DECL) return false; break; case IIndexConstants.CLASS_AND_ENUM_SUFFIX: if (typeKind != TypeDeclaration.CLASS_DECL && typeKind != TypeDeclaration.ENUM_DECL) return false; break; case IIndexConstants.INTERFACE_SUFFIX: if (typeKind != TypeDeclaration.INTERFACE_DECL) return false; break; case IIndexConstants.INTERFACE_AND_ANNOTATION_SUFFIX: if (typeKind != TypeDeclaration.INTERFACE_DECL && typeKind != TypeDeclaration.ANNOTATION_TYPE_DECL) return false; break; case IIndexConstants.ENUM_SUFFIX: if (typeKind != TypeDeclaration.ENUM_DECL) return false; break; case IIndexConstants.ANNOTATION_TYPE_SUFFIX: if (typeKind != TypeDeclaration.ANNOTATION_TYPE_DECL) return false; break; case IIndexConstants.TYPE_SUFFIX: // nothing } boolean isPkgCaseSensitive = (matchRulePkg & SearchPattern.R_CASE_SENSITIVE) != 0; if (patternPkg != null && !CharOperation.equals(patternPkg, pkg, isPkgCaseSensitive)) return false; boolean isCaseSensitive = (matchRuleType & SearchPattern.R_CASE_SENSITIVE) != 0; if (patternTypeName != null) { boolean isCamelCase = (matchRuleType & (SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH)) != 0; int matchMode = matchRuleType & JavaSearchPattern.MATCH_MODE_MASK; if (!isCaseSensitive && !isCamelCase) { patternTypeName = CharOperation.toLowerCase(patternTypeName); } boolean matchFirstChar = !isCaseSensitive || patternTypeName[0] == typeName[0]; switch (matchMode) { case SearchPattern.R_EXACT_MATCH: return matchFirstChar && CharOperation.equals(patternTypeName, typeName, isCaseSensitive); case SearchPattern.R_PREFIX_MATCH: return matchFirstChar && CharOperation.prefixEquals(patternTypeName, typeName, isCaseSensitive); case SearchPattern.R_PATTERN_MATCH: return CharOperation.match(patternTypeName, typeName, isCaseSensitive); case SearchPattern.R_REGEXP_MATCH: // TODO (frederic) implement regular expression match break; case SearchPattern.R_CAMELCASE_MATCH: if (matchFirstChar && CharOperation.camelCaseMatch(patternTypeName, typeName, false)) { return true; } return !isCaseSensitive && matchFirstChar && CharOperation.prefixEquals(patternTypeName, typeName, false); case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH: return matchFirstChar && CharOperation.camelCaseMatch(patternTypeName, typeName, true); } } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorDeclarationPattern.java
License:Open Source License
public ConstructorDeclarationPattern(char[] declaringPackageName, char[] declaringSimpleName, int matchRule) { this(matchRule); this.declaringSimpleName = (this.isCaseSensitive || this.isCamelCase) ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName); this.declaringPackageName = declaringPackageName; this.findDeclarations = true; this.findReferences = false; this.parameterCount = -1; this.mustResolve = false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorPattern.java
License:Open Source License
public ConstructorPattern(char[] declaringSimpleName, char[] declaringQualification, char[][] parameterQualifications, char[][] parameterSimpleNames, int limitTo, int matchRule) { this(matchRule); this.fineGrain = limitTo & FINE_GRAIN_MASK; if (this.fineGrain == 0) { switch (limitTo) { case IJavaSearchConstants.DECLARATIONS: this.findReferences = false; break; case IJavaSearchConstants.REFERENCES: this.findDeclarations = false; break; case IJavaSearchConstants.ALL_OCCURRENCES: break; }//from w ww . ja va2s.c om } else { this.findDeclarations = false; } this.declaringQualification = this.isCaseSensitive ? declaringQualification : CharOperation.toLowerCase(declaringQualification); this.declaringSimpleName = (this.isCaseSensitive || this.isCamelCase) ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName); if (parameterSimpleNames != null) { this.parameterCount = parameterSimpleNames.length; boolean synthetic = this.parameterCount > 0 && declaringQualification != null && CharOperation.equals( CharOperation.concat(parameterQualifications[0], parameterSimpleNames[0], '.'), declaringQualification); int offset = 0; if (synthetic) { // skip first synthetic parameter this.parameterCount--; offset++; } this.parameterQualifications = new char[this.parameterCount][]; this.parameterSimpleNames = new char[this.parameterCount][]; for (int i = 0; i < this.parameterCount; i++) { this.parameterQualifications[i] = this.isCaseSensitive ? parameterQualifications[i + offset] : CharOperation.toLowerCase(parameterQualifications[i + offset]); this.parameterSimpleNames[i] = this.isCaseSensitive ? parameterSimpleNames[i + offset] : CharOperation.toLowerCase(parameterSimpleNames[i + offset]); } } else { this.parameterCount = -1; } this.mustResolve = mustResolve(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.FieldPattern.java
License:Open Source License
public FieldPattern(char[] name, char[] declaringQualification, char[] declaringSimpleName, char[] typeQualification, char[] typeSimpleName, int limitTo, int matchRule) { super(FIELD_PATTERN, name, limitTo, matchRule); this.declaringQualification = this.isCaseSensitive ? declaringQualification : CharOperation.toLowerCase(declaringQualification); this.declaringSimpleName = this.isCaseSensitive ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName); this.typeQualification = this.isCaseSensitive ? typeQualification : CharOperation.toLowerCase(typeQualification); this.typeSimpleName = (this.isCaseSensitive || this.isCamelCase) ? typeSimpleName : CharOperation.toLowerCase(typeSimpleName); this.mustResolve = mustResolve(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.JavaSearchNameEnvironment.java
License:Open Source License
/** * Must be used only by CompletionEngine. * The progress monitor is used to be able to cancel completion operations * * Find the top-level types that are defined * in the current environment and whose name starts with the * given prefix. The prefix is a qualified name separated by periods * or a simple name (ex. java.util.V or V). * * The types found are passed to one of the following methods (if additional * information is known about the types): * ISearchRequestor.acceptType(char[][] packageName, char[] typeName) * ISearchRequestor.acceptClass(char[][] packageName, char[] typeName, int modifiers) * ISearchRequestor.acceptInterface(char[][] packageName, char[] typeName, int modifiers) * * This method can not be used to find member types... member * types are found relative to their enclosing type. *///from ww w . j a v a 2s . co m public void findTypes(char[] prefix, final boolean findMembers, boolean camelCaseMatch, int searchFor, final ISearchRequestor storage, IProgressMonitor monitor) { try { int lastDotIndex = CharOperation.lastIndexOf('.', prefix); char[] qualification, simpleName; if (lastDotIndex < 0) { qualification = null; if (camelCaseMatch) { simpleName = prefix; } else { simpleName = CharOperation.toLowerCase(prefix); } } else { qualification = CharOperation.subarray(prefix, 0, lastDotIndex); if (camelCaseMatch) { simpleName = CharOperation.subarray(prefix, lastDotIndex + 1, prefix.length); } else { simpleName = CharOperation .toLowerCase(CharOperation.subarray(prefix, lastDotIndex + 1, prefix.length)); } } IProgressMonitor progressMonitor = new IProgressMonitor() { boolean isCanceled = false; public void beginTask(String name, int totalWork) { // implements interface method } public void done() { // implements interface method } public void internalWorked(double work) { // implements interface method } public boolean isCanceled() { return this.isCanceled; } public void setCanceled(boolean value) { this.isCanceled = value; } public void setTaskName(String name) { // implements interface method } public void subTask(String name) { // implements interface method } public void worked(int work) { // implements interface method } }; IRestrictedAccessTypeRequestor typeRequestor = new IRestrictedAccessTypeRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { // if (excludePath != null && excludePath.equals(path)) // return; if (!findMembers && enclosingTypeNames != null && enclosingTypeNames.length > 0) return; // accept only top level types storage.acceptType(packageName, simpleTypeName, enclosingTypeNames, modifiers, access); } }; int matchRule = SearchPattern.R_PREFIX_MATCH; if (camelCaseMatch) matchRule |= SearchPattern.R_CAMELCASE_MATCH; IndexManager indexManager = javaProject.getIndexManager(); if (monitor != null) { if (indexManager.awaitingJobsCount() == 0) { // indexes were already there, so perform an immediate search to avoid any index rebuilt new BasicSearchEngine(indexManager).searchAllTypeNames(qualification, SearchPattern.R_EXACT_MATCH, simpleName, matchRule, // not case sensitive searchFor, getSearchScope(), typeRequestor, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, progressMonitor); } else { // indexes were not ready, give the indexing a chance to finish small jobs by sleeping 100ms... try { Thread.sleep(100); } catch (InterruptedException e) { // Do nothing } if (monitor.isCanceled()) { throw new OperationCanceledException(); } if (indexManager.awaitingJobsCount() == 0) { // indexes are now ready, so perform an immediate search to avoid any index rebuilt new BasicSearchEngine(indexManager).searchAllTypeNames(qualification, SearchPattern.R_EXACT_MATCH, simpleName, matchRule, // not case sensitive searchFor, getSearchScope(), typeRequestor, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, progressMonitor); } //else { // Indexes are still not ready, so look for types in the model instead of a search request // findTypes( // new String(prefix), // storage, // convertSearchFilterToModelFilter(searchFor)); // } } } else { try { new BasicSearchEngine(indexManager).searchAllTypeNames(qualification, SearchPattern.R_EXACT_MATCH, simpleName, matchRule, // not case sensitive searchFor, getSearchScope(), typeRequestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, progressMonitor); } catch (OperationCanceledException e) { // findTypes( // new String(prefix), // storage, // convertSearchFilterToModelFilter(searchFor)); } } } catch (JavaModelException e) { // findTypes( // new String(prefix), // storage, // convertSearchFilterToModelFilter(searchFor)); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.JavaSearchNameEnvironment.java
License:Open Source License
/** * Must be used only by CompletionEngine. * The progress monitor is used to be able to cancel completion operations * * Find constructor declarations that are defined * in the current environment and whose name starts with the * given prefix. The prefix is a qualified name separated by periods * or a simple name (ex. java.util.V or V). * * The constructors found are passed to one of the following methods: * ISearchRequestor.acceptConstructor(...) */// w w w. jav a2 s. c om public void findConstructorDeclarations(char[] prefix, boolean camelCaseMatch, final ISearchRequestor storage, IProgressMonitor monitor) { try { int lastDotIndex = CharOperation.lastIndexOf('.', prefix); char[] qualification, simpleName; if (lastDotIndex < 0) { qualification = null; if (camelCaseMatch) { simpleName = prefix; } else { simpleName = CharOperation.toLowerCase(prefix); } } else { qualification = CharOperation.subarray(prefix, 0, lastDotIndex); if (camelCaseMatch) { simpleName = CharOperation.subarray(prefix, lastDotIndex + 1, prefix.length); } else { simpleName = CharOperation .toLowerCase(CharOperation.subarray(prefix, lastDotIndex + 1, prefix.length)); } } IProgressMonitor progressMonitor = new IProgressMonitor() { boolean isCanceled = false; public void beginTask(String name, int totalWork) { // implements interface method } public void done() { // implements interface method } public void internalWorked(double work) { // implements interface method } public boolean isCanceled() { return this.isCanceled; } public void setCanceled(boolean value) { this.isCanceled = value; } public void setTaskName(String name) { // implements interface method } public void subTask(String name) { // implements interface method } public void worked(int work) { // implements interface method } }; IRestrictedAccessConstructorRequestor constructorRequestor = new IRestrictedAccessConstructorRequestor() { public void acceptConstructor(int modifiers, char[] simpleTypeName, int parameterCount, char[] signature, char[][] parameterTypes, char[][] parameterNames, int typeModifiers, char[] packageName, int extraFlags, String path, AccessRestriction access) { storage.acceptConstructor(modifiers, simpleTypeName, parameterCount, signature, parameterTypes, parameterNames, typeModifiers, packageName, extraFlags, path, access); } }; int matchRule = SearchPattern.R_PREFIX_MATCH; if (camelCaseMatch) matchRule |= SearchPattern.R_CAMELCASE_MATCH; IndexManager indexManager = javaProject.getIndexManager(); if (monitor != null) { while (indexManager.awaitingJobsCount() > 0) { try { Thread.sleep(50); // indexes are not ready, sleep 50ms... } catch (InterruptedException e) { // Do nothing } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } new BasicSearchEngine(indexManager).searchAllConstructorDeclarations(qualification, simpleName, matchRule, getSearchScope(), constructorRequestor, IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, progressMonitor); } else { try { new BasicSearchEngine(indexManager).searchAllConstructorDeclarations(qualification, simpleName, matchRule, getSearchScope(), constructorRequestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, progressMonitor); } catch (OperationCanceledException e) { // Do nothing } } } catch (JavaModelException e) { // Do nothing } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodPattern.java
License:Open Source License
public MethodPattern(char[] selector, char[] declaringQualification, char[] declaringSimpleName, char[] returnQualification, char[] returnSimpleName, char[][] parameterQualifications, char[][] parameterSimpleNames, IType declaringType, int limitTo, int matchRule) { this(matchRule); this.fineGrain = limitTo & FINE_GRAIN_MASK; if (this.fineGrain == 0) { switch (limitTo & 0xF) { case IJavaSearchConstants.DECLARATIONS: this.findReferences = false; break; case IJavaSearchConstants.REFERENCES: this.findDeclarations = false; break; case IJavaSearchConstants.ALL_OCCURRENCES: break; }//from w w w . j a v a 2s .c om } else { this.findDeclarations = false; } this.selector = (this.isCaseSensitive || this.isCamelCase) ? selector : CharOperation.toLowerCase(selector); this.declaringQualification = this.isCaseSensitive ? declaringQualification : CharOperation.toLowerCase(declaringQualification); this.declaringSimpleName = this.isCaseSensitive ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName); this.returnQualification = this.isCaseSensitive ? returnQualification : CharOperation.toLowerCase(returnQualification); this.returnSimpleName = this.isCaseSensitive ? returnSimpleName : CharOperation.toLowerCase(returnSimpleName); if (parameterSimpleNames != null) { this.parameterCount = parameterSimpleNames.length; this.parameterQualifications = new char[this.parameterCount][]; this.parameterSimpleNames = new char[this.parameterCount][]; for (int i = 0; i < this.parameterCount; i++) { this.parameterQualifications[i] = this.isCaseSensitive ? parameterQualifications[i] : CharOperation.toLowerCase(parameterQualifications[i]); this.parameterSimpleNames[i] = this.isCaseSensitive ? parameterSimpleNames[i] : CharOperation.toLowerCase(parameterSimpleNames[i]); } } else { this.parameterCount = -1; } this.declaringType = declaringType; if (this.declaringType != null) { this.declaringPackageName = this.declaringType.getPackageFragment().getElementName().toCharArray(); } this.mustResolve = mustResolve(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MultiTypeDeclarationPattern.java
License:Open Source License
public MultiTypeDeclarationPattern(char[][] qualifications, char[][] simpleNames, char typeSuffix, int matchRule) { this(matchRule); if (this.isCaseSensitive || qualifications == null) { this.qualifications = qualifications; } else {/*from w w w .j a v a2 s . co m*/ int length = qualifications.length; this.qualifications = new char[length][]; for (int i = 0; i < length; i++) this.qualifications[i] = CharOperation.toLowerCase(qualifications[i]); } // null simple names are allowed (should return all names) if (simpleNames != null) { if (this.isCaseSensitive || this.isCamelCase) { this.simpleNames = simpleNames; } else { int length = simpleNames.length; this.simpleNames = new char[length][]; for (int i = 0; i < length; i++) this.simpleNames[i] = CharOperation.toLowerCase(simpleNames[i]); } } this.typeSuffix = typeSuffix; this.mustResolve = typeSuffix != TYPE_SUFFIX; // only used to report type declarations, not their positions }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PackageReferencePattern.java
License:Open Source License
public PackageReferencePattern(char[] pkgName, int matchRule) { this(matchRule); if (pkgName == null || pkgName.length == 0) { this.pkgName = null; this.segments = new char[][] { CharOperation.NO_CHAR }; this.mustResolve = false; } else {//from w w w . j av a2s .c o m this.pkgName = (this.isCaseSensitive || this.isCamelCase) ? pkgName : CharOperation.toLowerCase(pkgName); this.segments = CharOperation.splitOn('.', this.pkgName); this.mustResolve = true; } }