Java Code Examples for org.eclipse.jdt.core.compiler.CharOperation#toLowerCase()

The following examples show how to use org.eclipse.jdt.core.compiler.CharOperation#toLowerCase() . 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: TypeDeclarationPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeDeclarationPattern(
	char[] pkg,
	char[][] enclosingTypeNames,
	char[] simpleName,
	char typeSuffix,
	int matchRule) {

	this(matchRule);

	this.pkg = this.isCaseSensitive ? pkg : CharOperation.toLowerCase(pkg);
	if (this.isCaseSensitive || enclosingTypeNames == null) {
		this.enclosingTypeNames = enclosingTypeNames;
	} else {
		int length = enclosingTypeNames.length;
		this.enclosingTypeNames = new char[length][];
		for (int i = 0; i < length; i++)
			this.enclosingTypeNames[i] = CharOperation.toLowerCase(enclosingTypeNames[i]);
	}
	this.simpleName = (this.isCaseSensitive || this.isCamelCase) ? simpleName : CharOperation.toLowerCase(simpleName);
	this.typeSuffix = typeSuffix;

	this.mustResolve = (this.pkg != null && this.enclosingTypeNames != null) || typeSuffix != TYPE_SUFFIX;
}
 
Example 2
Source File: TypeReferencePattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeReferencePattern(char[] qualification, char[] simpleName, int matchRule) {
	this(matchRule);

	this.qualification = this.isCaseSensitive ? qualification : CharOperation.toLowerCase(qualification);
	this.simpleName = (this.isCaseSensitive || this.isCamelCase) ? simpleName : CharOperation.toLowerCase(simpleName);

	if (simpleName == null)
		this.segments = this.qualification == null ? ONE_STAR_CHAR : CharOperation.splitOn('.', this.qualification);
	else
		this.segments = null;

	if (this.segments == null)
		if (this.qualification == null)
			this.segmentsSize =  0;
		else
			this.segmentsSize =  CharOperation.occurencesOf('.', this.qualification) + 1;
	else
		this.segmentsSize = this.segments.length;

	this.mustResolve = true; // always resolve (in case of a simple name reference being a potential match)
}
 
Example 3
Source File: FieldPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: QualifiedTypeDeclarationPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public QualifiedTypeDeclarationPattern(char[] qualification, char[] simpleName, char typeSuffix, int matchRule) {
	this(matchRule);

	this.qualification = this.isCaseSensitive ? qualification : CharOperation.toLowerCase(qualification);
	this.simpleName = (this.isCaseSensitive || this.isCamelCase) ? simpleName : CharOperation.toLowerCase(simpleName);
	this.typeSuffix = typeSuffix;

	this.mustResolve = this.qualification != null || typeSuffix != TYPE_SUFFIX;
}
 
Example 5
Source File: VariablePattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public VariablePattern(int patternKind, char[] name, int limitTo, int matchRule) {
	super(patternKind, matchRule);

    this.fineGrain = limitTo & FINE_GRAIN_MASK;
    if (this.fineGrain == 0) {
		switch (limitTo & 0xF) {
			case IJavaSearchConstants.DECLARATIONS :
				this.findDeclarations = true;
				break;
			case IJavaSearchConstants.REFERENCES :
				this.readAccess = true;
				this.writeAccess = true;
				break;
			case IJavaSearchConstants.READ_ACCESSES :
				this.readAccess = true;
				break;
			case IJavaSearchConstants.WRITE_ACCESSES :
				this.writeAccess = true;
				break;
			case IJavaSearchConstants.ALL_OCCURRENCES :
				this.findDeclarations = true;
				this.readAccess = true;
				this.writeAccess = true;
				break;
		}
		this.findReferences = this.readAccess || this.writeAccess;
    }

	this.name = (this.isCaseSensitive || this.isCamelCase) ? name : CharOperation.toLowerCase(name);
}
 
Example 6
Source File: ConstructorDeclarationPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: PackageReferencePattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 {
		this.pkgName = (this.isCaseSensitive || this.isCamelCase) ? pkgName : CharOperation.toLowerCase(pkgName);
		this.segments = CharOperation.splitOn('.', this.pkgName);
		this.mustResolve = true;
	}
}
 
Example 8
Source File: InternalNamingConventions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static char[][] generateNonConstantName(char[][] nameParts, int namePartsPtr, boolean onlyLongest) {
	char[][] names;
	if (onlyLongest) {
		names = new char[1][];
	} else {
		names = new char[namePartsPtr + 1][];
	}
	
	char[] namePart = nameParts[0];
	
	char[] name = CharOperation.toLowerCase(namePart);
	
	if (!onlyLongest) {
		names[namePartsPtr] = name;
	}
	
	char[] nameSuffix = namePart;
	
	for (int i = 1; i <= namePartsPtr; i++) {
		namePart = nameParts[i];
		
		name = CharOperation.concat(CharOperation.toLowerCase(namePart), nameSuffix);
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=283539
		// Only the first word is converted to lower case and the rest of them are not changed for non-constants
		
		if (!onlyLongest) {
			names[namePartsPtr - i] = name;
		}
		
		nameSuffix = CharOperation.concat(namePart, nameSuffix);
	}
	if (onlyLongest) {
		names[0] = name;
	}
	return names;
}
 
Example 9
Source File: MethodFilter.java    From jdt-codemining with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 10
Source File: JavaRefIndex.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public Set<IIndexedJavaRef> findElementReferences(String pattern,
    int elementType, boolean caseSensitive) {
  boolean simpleTypeNameSearch = false;

  // Type matches can be found for either fully-qualified or simple type names
  if (elementType == IJavaElement.TYPE) {
    if (pattern.lastIndexOf('.') == -1) {
      /*
       * If the pattern has no dots, we assume the search pattern is an
       * unqualified type name, which means we'll need to compare the pattern
       * against the simple names of all the types in the index
       */
      simpleTypeNameSearch = true;
    }
  } else {
    if (elementType == IJavaElement.METHOD) {
      // Strip out the parameter list, if one was specified
      int paren = pattern.indexOf('(');
      if (paren > -1) {
        pattern = pattern.substring(0, paren);
      }

      // Make sure the pattern ends with a () to signify a method
      pattern += METHOD_KEY_SUFFIX;
    }

    /*
     * Remove the type name if it precedes the member name. For pattern
     * searching, we match members by name and ignore their type if specified.
     * This is the same behavior as the default JDT Java Search engine.
     */
    int lastDot = pattern.lastIndexOf('.');
    if (lastDot > -1) {
      pattern = pattern.substring(lastDot + 1);
    }

    // Finally, for member searches we need to generate the right kind of key
    // to search the element index with
    pattern = getElementMemberKey(pattern);
  }

  /*
   * If we don't have any wildcard chars and we're doing a case sensitive
   * search and we're not doing a search for a simple type name, we can
   * perform the search much faster by accessing the element index by a key
   */
  if (caseSensitive && !simpleTypeNameSearch && pattern.indexOf('*') == -1
      && pattern.indexOf('?') == -1) {
    return findElementReferences(pattern);
  }

  // Scan all the element index entries sequentially, since we need to do
  // pattern matching on each one to see if it's a match
  Set<IIndexedJavaRef> refs = new HashSet<IIndexedJavaRef>();
  for (String key : elementIndex.keySet()) {
    String element = key;
    if (simpleTypeNameSearch) {
      // Strip the qualifier off the index element before trying to match
      element = Signature.getSimpleName(element);
    }

    char[] patternChars = pattern.toCharArray();

    if (!caseSensitive) {
      /*
       * Convert the pattern to lower case if we're doing a case-insensitive
       * search. You would think the CharOperation.matched method called below
       * would take care of this, since it takes a caseSensitive parameter,
       * but for some reason it only uses that to convert the characters in
       * the 'name' parameter to lower case.
       */
      patternChars = CharOperation.toLowerCase(patternChars);
    }

    if (CharOperation.match(patternChars, element.toCharArray(),
        caseSensitive)) {
      refs.addAll(elementIndex.get(key));
    }
  }

  return refs;
}
 
Example 11
Source File: MethodPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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;
		}
    } 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();
}
 
Example 12
Source File: ConstructorPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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;
		}
    } 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();
}
 
Example 13
Source File: BasicSearchEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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;
		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;

}