Example usage for org.eclipse.jdt.core.compiler CharOperation camelCaseMatch

List of usage examples for org.eclipse.jdt.core.compiler CharOperation camelCaseMatch

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler CharOperation camelCaseMatch.

Prototype

public static final boolean camelCaseMatch(char[] pattern, int patternStart, int patternEnd, char[] name,
        int nameStart, int nameEnd) 

Source Link

Document

Answers true if a sub-pattern matches the sub-part of the given name using CamelCase rules, or false otherwise.

Usage

From source file:org.eclipse.jst.common.internal.annotations.ui.AbstractAnnotationTagProposal.java

License:Open Source License

/**
 * Matches <code>prefix</code> against <code>string</code> and replaces the matched region
 * by prefix. Case is preserved as much as possible. This method returns <code>string</code> if camel case completion
 * is disabled. Examples when camel case completion is enabled:
 * <ul>//from   w  w  w  .  ja v  a 2 s  .c  om
 * <li>getCamelCompound("NuPo", "NullPointerException") -> "NuPointerException"</li>
 * <li>getCamelCompound("NuPoE", "NullPointerException") -> "NuPoException"</li>
 * <li>getCamelCompound("hasCod", "hashCode") -> "hasCode"</li>
 * </ul>
 * 
 * @param prefix the prefix to match against
 * @param string the string to match
 * @return a compound of prefix and any postfix taken from <code>string</code>
 * @since 3.2
 */
protected final String getCamelCaseCompound(String prefix, String string) {
    if (prefix.length() > string.length())
        return string;

    // a normal prefix - no camel case logic at all
    String start = string.substring(0, prefix.length());
    if (start.equalsIgnoreCase(prefix))
        return string;

    final char[] patternChars = prefix.toCharArray();
    final char[] stringChars = string.toCharArray();

    for (int i = 1; i <= stringChars.length; i++)
        if (CharOperation.camelCaseMatch(patternChars, 0, patternChars.length, stringChars, 0, i))
            return prefix + string.substring(i);

    // Not a camel case match at all.
    // This should not happen -> stay with the default behavior
    return string;
}