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

The following examples show how to use org.eclipse.jdt.core.compiler.CharOperation#prefixEquals() . 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: CompletionParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean checkInstanceofKeyword() {
	if(isInsideMethod()) {
		int kind = topKnownElementKind(COMPLETION_OR_ASSIST_PARSER);
		int index;
		if(kind != K_BLOCK_DELIMITER
			&& (index = indexOfAssistIdentifier()) > -1
			&& this.expressionPtr > -1
			&& this.expressionLengthStack[this.expressionPtr] == 1) {

			int ptr = this.identifierPtr - this.identifierLengthStack[this.identifierLengthPtr] + index + 1;
			if(this.identifierStack[ptr].length > 0 && CharOperation.prefixEquals(this.identifierStack[ptr], Keywords.INSTANCEOF)) {
				this.assistNode = new CompletionOnKeyword3(
						this.identifierStack[ptr],
						this.identifierPositionStack[ptr],
						Keywords.INSTANCEOF);
				this.lastCheckPoint = this.assistNode.sourceEnd + 1;
				this.isOrphanCompletionNode = true;
				return true;
			}
		}
	}
	return false;
}
 
Example 2
Source File: SourceTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public FieldBinding getSyntheticField(ReferenceBinding targetEnclosingType, boolean onlyExactMatch) {
	if (!isPrototype()) throw new IllegalStateException();
	if (this.synthetics == null || this.synthetics[SourceTypeBinding.FIELD_EMUL] == null) return null;
	FieldBinding field = (FieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL].get(targetEnclosingType);
	if (field != null) return field;

	// type compatibility : to handle cases such as
	// class T { class M{}}
	// class S extends T { class N extends M {}} --> need to use S as a default enclosing instance for the super constructor call in N().
	if (!onlyExactMatch){
		Iterator accessFields = this.synthetics[SourceTypeBinding.FIELD_EMUL].values().iterator();
		while (accessFields.hasNext()) {
			field = (FieldBinding) accessFields.next();
			if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX, field.name)
				&& field.type.findSuperTypeOriginatingFrom(targetEnclosingType) != null)
					return field;
		}
	}
	return null;
}
 
Example 3
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void acceptName(char[] name) {
	// the null check is added to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=166570
	if (name == null) return;

	if (!CharOperation.prefixEquals(this.completionEngine.completionToken, name, false /* ignore case */)
			&& !(this.completionEngine.options.camelCaseMatch && CharOperation.camelCaseMatch(this.completionEngine.completionToken, name))) return;

	if (this.acceptedNames.includes(name)) return;

	this.acceptedNames.add(name);

	// accept result
	this.requestor.acceptName(name);
}
 
Example 4
Source File: Index.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isMatch(char[] pattern, char[] word, int matchRule) {
	if (pattern == null) return true;
	int patternLength = pattern.length;
	int wordLength = word.length;
	if (patternLength == 0) return matchRule != SearchPattern.R_EXACT_MATCH;
	if (wordLength == 0) return (matchRule & SearchPattern.R_PATTERN_MATCH) != 0 && patternLength == 1 && pattern[0] == '*';

	// need to mask some bits of pattern rule (bug 79790)
	switch(matchRule & MATCH_RULE_INDEX_MASK) {
		case SearchPattern.R_EXACT_MATCH :
			return patternLength == wordLength && CharOperation.equals(pattern, word, false);
		case SearchPattern.R_PREFIX_MATCH :
			return patternLength <= wordLength && CharOperation.prefixEquals(pattern, word, false);
		case SearchPattern.R_PATTERN_MATCH :
			return CharOperation.match(pattern, word, false);
		case SearchPattern.R_CAMELCASE_MATCH:
		// same part count is not activated because index key may have uppercase letters after the type name
		case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH:
			if (CharOperation.camelCaseMatch(pattern, word, false)) {
				return true;
			}
			return patternLength <= wordLength && CharOperation.prefixEquals(pattern, word, false);
		case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE :
			return pattern[0] == word[0] && patternLength == wordLength && CharOperation.equals(pattern, word);
		case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE :
			return pattern[0] == word[0] && patternLength <= wordLength && CharOperation.prefixEquals(pattern, word);
		case SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE :
			return CharOperation.match(pattern, word, true);
		case SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CASE_SENSITIVE :
		// same part count is not activated because index key may have uppercase letters after the type name
		case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH | SearchPattern.R_CASE_SENSITIVE :
			return (pattern[0] == word[0] && CharOperation.camelCaseMatch(pattern, word, false));
	}
	return false;
}
 
Example 5
Source File: Argument.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TypeBinding bind(MethodScope scope, TypeBinding typeBinding, boolean used) {
	TypeBinding newTypeBinding = createBinding(scope, typeBinding); // basically a no-op if createBinding() was called before

	// record the resolved type into the type reference
	Binding existingVariable = scope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/);
	if (existingVariable != null && existingVariable.isValidBinding()){
		final boolean localExists = existingVariable instanceof LocalVariableBinding;
		if (localExists && (this.bits & ASTNode.ShadowsOuterLocal) != 0 && scope.isLambdaSubscope()) {
			scope.problemReporter().lambdaRedeclaresArgument(this);
		} else if (localExists && this.hiddenVariableDepth == 0) {
			scope.problemReporter().redefineArgument(this);
		} else {
			boolean isSpecialArgument = false;
			if (existingVariable instanceof FieldBinding) {
				if (scope.isInsideConstructor()) {
					isSpecialArgument = true; // constructor argument
				} else {
					AbstractMethodDeclaration methodDecl = scope.referenceMethod();
					if (methodDecl != null && CharOperation.prefixEquals(SET, methodDecl.selector)) {
						isSpecialArgument = true; // setter argument
					}
				}
			}
			scope.problemReporter().localVariableHiding(this, existingVariable, isSpecialArgument);
		}
	}
	scope.addLocalVariable(this.binding);
	this.binding.useFlag = used ? LocalVariableBinding.USED : LocalVariableBinding.UNUSED;
	return newTypeBinding;
}
 
Example 6
Source File: TypeBound.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TypeBinding safeType(TypeBinding type) {
	if (type != null && type.isLocalType()) {
		MethodBinding enclosingMethod = ((LocalTypeBinding) type.original()).enclosingMethod;
		if (enclosingMethod != null && CharOperation.prefixEquals(TypeConstants.ANONYMOUS_METHOD, enclosingMethod.selector))
			return type.superclass(); // don't use local class inside lambda: lambda is copied, type will be re-created and thus is unmatchable
	}
	return type;
}
 
Example 7
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 8
Source File: PackageReferenceLocator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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;
}
 
Example 9
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;

}
 
Example 10
Source File: InternalNamingConventions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static char[] removePrefix(char[] name, char[][] prefixes) {
		// remove longer prefix
		char[] withoutPrefixName = name;
		if (prefixes != null) {
			int bestLength = 0;
			int nameLength = name.length;
			for (int i= 0; i < prefixes.length; i++) {
				char[] prefix = prefixes[i];

				int prefixLength = prefix.length;
				if(prefixLength <= nameLength) {
					if(CharOperation.prefixEquals(prefix, name, false)) {
						if (prefixLength > bestLength) {
							bestLength = prefixLength;
						}
					}
				} else {
					int currLen = 0;
					for (; currLen < nameLength; currLen++) {
						if(ScannerHelper.toLowerCase(prefix[currLen]) != ScannerHelper.toLowerCase(name[currLen])) {
							if (currLen > bestLength) {
								bestLength = currLen;
							}
							break;
						}
					}
					if(currLen == nameLength && currLen > bestLength) {
						bestLength = currLen;
					}
				}
			}
			if(bestLength > 0) {
				if(bestLength == nameLength) {
					withoutPrefixName = CharOperation.NO_CHAR;
				} else {
					withoutPrefixName = CharOperation.subarray(name, bestLength, nameLength);
				}
			}
		}
//
//
//		// remove longer prefix
//		char[] withoutPrefixName = name;
//		if (prefixes != null) {
//			int bestLength = 0;
//			for (int i= 0; i < prefixes.length; i++) {
//				char[] prefix = prefixes[i];
//				int max = prefix.length < name.length ? prefix.length : name.length;
//				int currLen = 0;
//				for (; currLen < max; currLen++) {
//					if(Character.toLowerCase(prefix[currLen]) != Character.toLowerCase(name[currLen])) {
//						if (currLen > bestLength) {
//							bestLength = currLen;
//						}
//						break;
//					}
//				}
//				if(currLen == max && currLen > bestLength) {
//					bestLength = max;
//				}
//			}
//			if(bestLength > 0) {
//				if(bestLength == name.length) {
//					withoutPrefixName = CharOperation.NO_CHAR;
//				} else {
//					withoutPrefixName = CharOperation.subarray(name, bestLength, name.length);
//				}
//			}
//		}

		return withoutPrefixName;
	}
 
Example 11
Source File: NamingConventions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Suggest name for a getter method. The name is computed from field's name
 * and possible prefixes or suffixes are removed.
 * <p>
 * If the field name is <code>preFieldNamesuf</code> and the prefix for field is <code>pre</code> and
 * the suffix for field is <code>suf</code> then the prosposed name is <code>isFieldName</code> for boolean field or
 * <code>getFieldName</code> for others. If there is no prefix and suffix the proposal is <code>isPreFieldNamesuf</code>
 * for boolean field or <code>getPreFieldNamesuf</code> for others.
 * </p>
 * <p>
 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_FIELD_PREFIXES},
 *  {@link JavaCore#CODEASSIST_FIELD_SUFFIXES} for instance field and  {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES},
 *  {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES} for static field.
 * </p>
 * <p>
 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
 * </p>
 *
 * @param project project which contains the field.
 * @param fieldName field's name's.
 * @param modifiers field's modifiers as defined by the class
 * <code>Flags</code>.
 * @param isBoolean <code>true</code> if the field's type is boolean
 * @param excludedNames a list of names which cannot be suggested (already used names).
 *         Can be <code>null</code> if there is no excluded names.
 * @return char[] a name.
 * @see Flags
 * @see JavaCore#setOptions(java.util.Hashtable)
 * @see JavaCore#getDefaultOptions()
 */
public static char[] suggestGetterName(IJavaProject project, char[] fieldName, int modifiers, boolean isBoolean, char[][] excludedNames) {
	if (isBoolean) {
		char[] name = InternalNamingConventions.getBaseName(getFieldVariableKind(modifiers), project, fieldName, false);
		int prefixLen =  GETTER_BOOL_NAME.length;
		if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name)
			&& name.length > prefixLen && ScannerHelper.isUpperCase(name[prefixLen])) {
			return suggestNewName(name, excludedNames);
		} else {
			return suggestNewName(
				CharOperation.concat(GETTER_BOOL_NAME, suggestAccessorName(project, fieldName, modifiers)),
				excludedNames
			);
		}
	} else {
		return suggestNewName(
			CharOperation.concat(GETTER_NAME, suggestAccessorName(project, fieldName, modifiers)),
			excludedNames
		);
	}
}
 
Example 12
Source File: NamingConventions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Suggest name for a setter method. The name is computed from field's name
 * and possible prefixes or suffixes are removed.
 * <p>
 * If the field name is <code>preFieldNamesuf</code> and the prefix for field is <code>pre</code> and
 * the suffix for field is <code>suf</code> then the proposed name is <code>setFieldName</code>.
 * If there is no prefix and suffix the proposal is <code>setPreFieldNamesuf</code>.
 * </p>
 * <p>
 * This method is affected by the following JavaCore options :  {@link JavaCore#CODEASSIST_FIELD_PREFIXES},
 *  {@link JavaCore#CODEASSIST_FIELD_SUFFIXES} for instance field and  {@link JavaCore#CODEASSIST_STATIC_FIELD_PREFIXES},
 *  {@link JavaCore#CODEASSIST_STATIC_FIELD_SUFFIXES} for static field.
 * </p>
 * <p>
 * For a complete description of these configurable options, see <code>getDefaultOptions</code>.
 * For programmaticaly change these options, see <code>JavaCore#setOptions()</code>.
 * </p>
 *
 * @param project project which contains the field.
 * @param fieldName field's name's.
 * @param modifiers field's modifiers as defined by the class
 * <code>Flags</code>.
 * @param isBoolean <code>true</code> if the field's type is boolean
 * @param excludedNames a list of names which cannot be suggested (already used names).
 *         Can be <code>null</code> if there is no excluded names.
 * @return char[] a name.
 * @see Flags
 * @see JavaCore#setOptions(java.util.Hashtable)
 * @see JavaCore#getDefaultOptions()
 */
public static char[] suggestSetterName(IJavaProject project, char[] fieldName, int modifiers, boolean isBoolean, char[][] excludedNames) {

	if (isBoolean) {
		char[] name = InternalNamingConventions.getBaseName(getFieldVariableKind(modifiers), project, fieldName, false);
		int prefixLen =  GETTER_BOOL_NAME.length;
		if (CharOperation.prefixEquals(GETTER_BOOL_NAME, name)
			&& name.length > prefixLen && ScannerHelper.isUpperCase(name[prefixLen])) {
			name = CharOperation.subarray(name, prefixLen, name.length);
			return suggestNewName(
				CharOperation.concat(SETTER_NAME, suggestAccessorName(project, name, modifiers)),
				excludedNames
			);
		} else {
			return suggestNewName(
				CharOperation.concat(SETTER_NAME, suggestAccessorName(project, fieldName, modifiers)),
				excludedNames
			);
		}
	} else {
		return suggestNewName(
			CharOperation.concat(SETTER_NAME, suggestAccessorName(project, fieldName, modifiers)),
			excludedNames
		);
	}
}
 
Example 13
Source File: FileSystem.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void initializeKnownFileNames(String[] initialFileNames) {
	if (initialFileNames == null) {
		this.knownFileNames = new HashSet(0);
		return;
	}
	this.knownFileNames = new HashSet(initialFileNames.length * 2);
	for (int i = initialFileNames.length; --i >= 0;) {
		File compilationUnitFile = new File(initialFileNames[i]);
		char[] fileName = null;
		try {
			fileName = compilationUnitFile.getCanonicalPath().toCharArray();
		} catch (IOException e) {
			// this should not happen as the file exists
			continue;
		}
		char[] matchingPathName = null;
		final int lastIndexOf = CharOperation.lastIndexOf('.', fileName);
		if (lastIndexOf != -1) {
			fileName = CharOperation.subarray(fileName, 0, lastIndexOf);
		}
		CharOperation.replace(fileName, '\\', '/');
		boolean globalPathMatches = false;
		// the most nested path should be the selected one
		for (int j = 0, max = this.classpaths.length; j < max; j++) {
			char[] matchCandidate = this.classpaths[j].normalizedPath();
			boolean currentPathMatch = false;
			if (this.classpaths[j] instanceof ClasspathDirectory
					&& CharOperation.prefixEquals(matchCandidate, fileName)) {
				currentPathMatch = true;
				if (matchingPathName == null) {
					matchingPathName = matchCandidate;
				} else {
					if (currentPathMatch) {
						// we have a second source folder that matches the path of the source file
						if (matchCandidate.length > matchingPathName.length) {
							// we want to preserve the shortest possible path
							matchingPathName = matchCandidate;
						}
					} else {
						// we want to preserve the shortest possible path
						if (!globalPathMatches && matchCandidate.length < matchingPathName.length) {
							matchingPathName = matchCandidate;
						}
					}
				}
				if (currentPathMatch) {
					globalPathMatches = true;
				}
			}
		}
		if (matchingPathName == null) {
			this.knownFileNames.add(new String(fileName)); // leave as is...
		} else {
			this.knownFileNames.add(new String(CharOperation.subarray(fileName, matchingPathName.length, fileName.length)));
		}
		matchingPathName = null;
	}
}