Java Code Examples for org.eclipse.jdt.core.search.SearchPattern#R_CAMELCASE_SAME_PART_COUNT_MATCH

The following examples show how to use org.eclipse.jdt.core.search.SearchPattern#R_CAMELCASE_SAME_PART_COUNT_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: PatternMatcher.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 2
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 3
Source File: TypeInfoFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public boolean isCamelCasePattern() {
	int ccMask= SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH;
	return (fNameMatcher.getMatchKind() & ccMask) != 0;
}
 
Example 4
Source File: PatternMatcher.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 5
Source File: PatternMatcher.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 6
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;
}