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

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

Introduction

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

Prototype

public static final char[] append(char[] target, char[] suffix) 

Source Link

Document

Answers a new array with appending the sub-array at the end of the array.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MultiTypeDeclarationPattern.java

License:Open Source License

public EntryResult[] queryIn(Index index) throws IOException {
    if (this.simpleNames == null) {
        // if no simple names then return all possible ones from index
        return index.query(getIndexCategories(), null, -1); // match rule is irrelevant when the key is null
    }// w  ww  .  j  a  v a 2s .com

    int count = -1;
    int numOfNames = this.simpleNames.length;
    EntryResult[][] allResults = numOfNames > 1 ? new EntryResult[numOfNames][] : null;
    for (int i = 0; i < numOfNames; i++) {
        char[] key = this.simpleNames[i];
        int matchRule = getMatchRule();

        switch (getMatchMode()) {
        case R_PREFIX_MATCH:
            // do a prefix query with the simpleName
            break;
        case R_EXACT_MATCH:
            // do a prefix query with the simpleName
            matchRule &= ~R_EXACT_MATCH;
            matchRule |= R_PREFIX_MATCH;
            key = CharOperation.append(key, SEPARATOR);
            break;
        case R_PATTERN_MATCH:
            if (key[key.length - 1] != '*')
                key = CharOperation.concat(key, ONE_STAR, SEPARATOR);
            break;
        case R_REGEXP_MATCH:
            // TODO (frederic) implement regular expression match
            break;
        case R_CAMELCASE_MATCH:
        case R_CAMELCASE_SAME_PART_COUNT_MATCH:
            // do a prefix query with the simpleName
            break;
        }

        EntryResult[] entries = index.query(getIndexCategories(), key, matchRule); // match rule is irrelevant when the key is null
        if (entries != null) {
            if (allResults == null)
                return entries;
            allResults[++count] = entries;
        }
    }

    if (count == -1)
        return null;
    int total = 0;
    for (int i = 0; i <= count; i++)
        total += allResults[i].length;
    EntryResult[] allEntries = new EntryResult[total];
    int next = 0;
    for (int i = 0; i <= count; i++) {
        EntryResult[] entries = allResults[i];
        System.arraycopy(entries, 0, allEntries, next, entries.length);
        next += entries.length;
    }
    return allEntries;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeReferencePattern.java

License:Open Source License

public EntryResult[] queryIn(Index index) throws IOException {
    char[] key = this.superSimpleName; // can be null
    int matchRule = getMatchRule();

    // cannot include the superQualification since it may not exist in the index
    switch (getMatchMode()) {
    case R_EXACT_MATCH:
        // do a prefix query with the superSimpleName
        matchRule &= ~R_EXACT_MATCH;
        matchRule |= R_PREFIX_MATCH;/*from   ww w .  j  av a2s. co  m*/
        if (this.superSimpleName != null)
            key = CharOperation.append(this.superSimpleName, SEPARATOR);
        break;
    case R_PREFIX_MATCH:
        // do a prefix query with the superSimpleName
        break;
    case R_PATTERN_MATCH:
        // do a pattern query with the superSimpleName
        break;
    case R_REGEXP_MATCH:
        // TODO (frederic) implement regular expression match
        break;
    case R_CAMELCASE_MATCH:
    case R_CAMELCASE_SAME_PART_COUNT_MATCH:
        // do a prefix query with the superSimpleName
        break;
    }

    return index.query(getIndexCategories(), key, matchRule); // match rule is irrelevant when the key is null
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeDeclarationPattern.java

License:Open Source License

public EntryResult[] queryIn(Index index) throws IOException {
    char[] key = this.simpleName; // can be null
    int matchRule = getMatchRule();

    switch (getMatchMode()) {
    case R_PREFIX_MATCH:
        // do a prefix query with the simpleName
        break;//from w  w w . ja v a 2 s.  co  m
    case R_EXACT_MATCH:
        matchRule &= ~R_EXACT_MATCH;
        if (this.simpleName != null) {
            matchRule |= R_PREFIX_MATCH;
            key = this.pkg == null ? CharOperation.append(this.simpleName, SEPARATOR)
                    : CharOperation.concat(this.simpleName, SEPARATOR, this.pkg, SEPARATOR,
                            CharOperation.NO_CHAR);
            break; // do a prefix query with the simpleName and possibly the pkg
        }
        matchRule |= R_PATTERN_MATCH;
        // $FALL-THROUGH$ - fall thru to encode the key and do a pattern query
    case R_PATTERN_MATCH:
        if (this.pkg == null) {
            if (this.simpleName == null) {
                switch (this.typeSuffix) {
                case CLASS_SUFFIX:
                case INTERFACE_SUFFIX:
                case ENUM_SUFFIX:
                case ANNOTATION_TYPE_SUFFIX:
                case CLASS_AND_INTERFACE_SUFFIX:
                case CLASS_AND_ENUM_SUFFIX:
                case INTERFACE_AND_ANNOTATION_SUFFIX:
                    // null key already returns all types
                    // key = new char[] {ONE_STAR[0],  SEPARATOR, ONE_STAR[0]};
                    break;
                }
            } else if (this.simpleName[this.simpleName.length - 1] != '*') {
                key = CharOperation.concat(this.simpleName, ONE_STAR, SEPARATOR);
            }
            break; // do a pattern query with the current encoded key
        }
        // must decode to check enclosingTypeNames due to the encoding of local types
        key = CharOperation.concat(this.simpleName == null ? ONE_STAR : this.simpleName, SEPARATOR, this.pkg,
                SEPARATOR, ONE_STAR);
        break;
    case R_REGEXP_MATCH:
        // TODO (frederic) implement regular expression match
        break;
    case R_CAMELCASE_MATCH:
    case R_CAMELCASE_SAME_PART_COUNT_MATCH:
        // do a prefix query with the simpleName
        break;
    }

    return index.query(getIndexCategories(), key, matchRule); // match rule is irrelevant when the key is null
}

From source file:com.ibm.research.tours.content.url.Signature.java

License:Open Source License

/**
 * Creates a new type parameter signature with the given name and bounds.
 *
 * @param typeParameterName the type parameter name
 * @param boundSignatures the signatures of associated bounds or empty array if none
 * @return the encoded type parameter signature
 * /*from   w w  w  .j a v  a  2 s  . c om*/
 * @since 3.1
 */
public static char[] createTypeParameterSignature(char[] typeParameterName, char[][] boundSignatures) {
    int length = boundSignatures.length;
    if (length == 0) {
        return CharOperation.append(typeParameterName, C_COLON); // param signature with no bounds still gets trailing colon
    }
    int boundsSize = 0;
    for (int i = 0; i < length; i++) {
        boundsSize += boundSignatures[i].length + 1;
    }
    int nameLength = typeParameterName.length;
    char[] result = new char[nameLength + boundsSize];
    System.arraycopy(typeParameterName, 0, result, 0, nameLength);
    int index = nameLength;
    for (int i = 0; i < length; i++) {
        result[index++] = C_COLON;
        int boundLength = boundSignatures[i].length;
        System.arraycopy(boundSignatures[i], 0, result, index, boundLength);
        index += boundLength;
    }
    return result;
}

From source file:org.codehaus.groovy.eclipse.codeassist.completions.GroovyJavaGuessingCompletionProposal.java

License:Open Source License

/**
 * Creates the completion string. Offsets and Lengths are set to the offsets
 * and lengths of the/*w ww .  j a v a 2s  .  co m*/
 * parameters.
 *
 * @return the completion string
 * @throws JavaModelException if parameter guessing failed
 */
private String computeGuessingCompletion() throws JavaModelException {
    StringBuffer buffer = new StringBuffer();
    char[] proposalName = fProposal.getName();
    boolean hasWhitespace = false;
    for (int i = 0; i < proposalName.length; i++) {
        if (CharOperation.isWhitespace(proposalName[i])) {
            hasWhitespace = true;
        }
    }
    char[] newProposalName;
    if (hasWhitespace) {
        newProposalName = CharOperation.concat(new char[] { '"' }, CharOperation.append(proposalName, '"'));
    } else {
        newProposalName = proposalName;
    }
    fProposal.setName(newProposalName);
    appendMethodNameReplacement(buffer);
    fProposal.setName(proposalName);

    FormatterPrefs prefs = getFormatterPrefs();
    if (proposalOptions.noParens) {
        // eat the opening paren replace with a space if there isn't one
        // already
        buffer.replace(buffer.length() - 1, buffer.length(), prefs.beforeOpeningParen ? "" : " ");
    }

    setCursorPosition(buffer.length());

    // groovy doesn't require parens around closures if it is the last
    // argument
    // If the option is set, then we follow that heuristic
    char[][] regularParameterTypes = ((GroovyCompletionProposal) fProposal).getRegularParameterTypeNames();

    // check if the last regular parameter is a closure. If so, it must be
    // moved to the end
    boolean lastArgIsClosure = lastArgIsClosure(regularParameterTypes);
    int indexOfLastClosure = lastArgIsClosure ? regularParameterTypes.length - 1 : -1;

    char[][] namedParameterNames = ((GroovyCompletionProposal) fProposal).getNamedParameterNames();
    char[][] regularParameterNames = ((GroovyCompletionProposal) fProposal).getRegularParameterNames();
    int namedCount = namedParameterNames.length;
    int argCount = regularParameterNames.length;
    int allCount = argCount + namedCount;

    if (proposalOptions.noParensAroundClosures) {

        // remove the opening paren only if there is a single closure
        // parameter
        if (indexOfLastClosure == 0 && namedCount == 0) {
            buffer.replace(buffer.length() - 1, buffer.length(), "");

            // add space if not already there
            // would be added by call to appendMethodNameReplacement
            if (!prefs.beforeOpeningParen) {
                buffer.append(SPACE);
            }
        } else {
            if (prefs.afterOpeningParen)
                buffer.append(SPACE);
        }
    } else {
        if (prefs.afterOpeningParen)
            buffer.append(SPACE);
    }

    // now add the parameters
    int replacementOffset = getReplacementOffset();
    fChoices = guessParameters(namedParameterNames, regularParameterNames);

    for (int i = 0; i < allCount; i++) {
        if (i == indexOfLastClosure) {
            // handle the last closure separately
            continue;
        }

        char[] nextName;
        if (i < argCount) {
            nextName = regularParameterNames[i];
        } else {
            nextName = namedParameterNames[i - argCount];
        }
        if (i >= argCount || proposalOptions.useNamedArguments) {
            buffer.append(nextName).append(":");
        }

        // handle the value
        ICompletionProposal proposal = fChoices[i][0];
        String argument = proposal.getDisplayString();

        Position position = fPositions[i];
        position.setOffset(replacementOffset + buffer.length());
        position.setLength(argument.length());

        // handle the "unknown" case where we only insert a proposal.
        if (proposal instanceof JavaCompletionProposal) {
            ((JavaCompletionProposal) proposal).setReplacementOffset(replacementOffset + buffer.length());
        }
        buffer.append(argument);

        // check what to add after argument
        if (i == allCount - 1 || (i == allCount - 2 && i == indexOfLastClosure - 1)) {
            if (prefs.beforeClosingParen || proposalOptions.noParens) {
                buffer.append(SPACE);
            }
            if (!proposalOptions.noParens) {
                buffer.append(RPAREN);
            }
        } else if (i < allCount - 1) {
            if (prefs.beforeComma)
                buffer.append(SPACE);
            buffer.append(COMMA);
            if (prefs.afterComma)
                buffer.append(SPACE);
        }
    }

    // closures at the end are added in an idiomatic groovy way
    if (indexOfLastClosure >= 0) {
        if (allCount > 1) {
            if (!proposalOptions.noParensAroundClosures) {
                buffer.append(COMMA);
            }
            buffer.append(SPACE);
        }
        Position position = fPositions[indexOfLastClosure];
        position.setOffset(replacementOffset + buffer.length());
        position.setLength(LAST_CLOSURE_TEXT.length());
        buffer.append(LAST_CLOSURE_TEXT);

        if (!proposalOptions.noParensAroundClosures) {
            buffer.append(" }");
            buffer.append(RPAREN);
        }
    }

    return buffer.toString();
}

From source file:org.codehaus.groovy.eclipse.codeassist.proposals.GroovyJavaGuessingCompletionProposal.java

License:Open Source License

/**
 * Creates the completion string. Offsets and Lengths are set to the offsets
 * and lengths of the/* ww w  .  j  a  va 2  s .  com*/
 * parameters.
 *
 * @return the completion string
 * @throws JavaModelException if parameter guessing failed
 */
private String computeGuessingCompletion() throws JavaModelException {

    StringBuffer buffer = new StringBuffer();
    char[] proposalName = fProposal.getName();
    boolean hasWhitespace = false;
    for (int i = 0; i < proposalName.length; i++) {
        if (CharOperation.isWhitespace(proposalName[i])) {
            hasWhitespace = true;
        }
    }
    char[] newProposalName;
    if (hasWhitespace) {
        newProposalName = CharOperation.concat(new char[] { '"' }, CharOperation.append(proposalName, '"'));
    } else {
        newProposalName = proposalName;
    }
    fProposal.setName(newProposalName);
    appendMethodNameReplacement(buffer);
    fProposal.setName(proposalName);

    FormatterPrefs prefs = getFormatterPrefs();

    setCursorPosition(buffer.length());

    // groovy doesn't require parens around closures if it is the last
    // argument
    // If the option is set, then we follow that heuristic
    int indexOfLastClosure = -1;
    String[] parameterTypes = getParameterTypes();
    if (proposalOptions.noParensAroundClosures) {
        if (lastArgIsClosure(parameterTypes)) {
            indexOfLastClosure = parameterTypes.length - 1;
        }

        // remove the opening paren only if there is a single closure
        // parameter
        if (indexOfLastClosure == 0) {
            buffer.replace(buffer.length() - 1, buffer.length(), "");

            // add space if not already there
            // would be added by call to appendMethodNameReplacement
            if (!prefs.beforeOpeningParen) {
                buffer.append(SPACE);
            }
        }
    } else {
        if (prefs.afterOpeningParen)
            buffer.append(SPACE);
    }

    char[][] parameterNames = fProposal.findParameterNames(null);
    fChoices = guessParameters(parameterNames);
    int count = fChoices.length;
    int replacementOffset = getReplacementOffset();

    for (int i = 0; i < count; i++) {

        if (proposalOptions.useNamedArguments) {
            buffer.append(parameterNames[i]).append(":");
        }

        // handle the argument name
        if (proposalOptions.useBracketsForClosures
                && Signature.getSimpleName(parameterTypes[i]).equals("Closure")) {
            // closure
            Position position = fPositions[i];
            position.setOffset(replacementOffset + buffer.length() + 2);
            buffer.append(CLOSURE_TEXT);
            position.setLength(0);

        } else {
            // regular argument
            ICompletionProposal proposal = fChoices[i][0];
            String argument = proposal.getDisplayString();

            Position position = fPositions[i];
            position.setOffset(replacementOffset + buffer.length());
            position.setLength(argument.length());

            // handle the "unknown" case where we only insert a proposal.
            if (proposal instanceof JavaCompletionProposal)
                ((JavaCompletionProposal) proposal).setReplacementOffset(replacementOffset + buffer.length());
            buffer.append(argument);
        }

        if (i == indexOfLastClosure - 1 || (i != indexOfLastClosure && i == count - 1)) {
            if (prefs.beforeClosingParen) {
                buffer.append(SPACE);
            }
            buffer.append(RPAREN);
            if (i == indexOfLastClosure - 1) {
                buffer.append(SPACE);
            }
        } else if (i < count - 1) {
            if (prefs.beforeComma)
                buffer.append(SPACE);
            buffer.append(COMMA);
            if (prefs.afterComma)
                buffer.append(SPACE);
        }

    }

    return buffer.toString();
}

From source file:org.eclipse.ajdt.internal.core.search.TargetTypeUtils.java

License:Open Source License

static char[] getName(char[] qual, char[] name) {
    if (name == null) {
        return null;
    }//from   w w w.j  av  a 2  s .c om

    char[] targetTypeName;
    if (qual != null && qual.length > 0) {
        qual = CharOperation.append(qual, '.');
        targetTypeName = CharOperation.append(qual, qual.length, name, 0, name.length);
    } else {
        targetTypeName = name;
    }
    // trim any \0 that are added to the end of target type
    int lastChar = targetTypeName.length;
    while (targetTypeName[lastChar - 1] == '\0' && lastChar > 0)
        lastChar--;

    targetTypeName = CharOperation.subarray(targetTypeName, 0, lastChar);

    return targetTypeName;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CopyInheritanceSourceAttribute.java

License:Open Source License

/**
 * Create a new "CopyInheritanceSrc" attribute.
 *//*  www.  ja  va2 s  .  c o  m*/
public static AbstractAttribute copyInherSrcAttribute(MethodBinding srcMethod, MethodModel destModel) {
    if (srcMethod.declaringClass instanceof LocalTypeBinding)
        ((LocalTypeBinding) srcMethod.declaringClass).computeConstantPoolName();
    char[] name = srcMethod.declaringClass.constantPoolName();//CharOperation.concatWith(srcMethod.declaringClass.compoundName, '.');
    name = CharOperation.append(name, '.');
    name = CharOperation.concat(name, srcMethod.selector);
    name = CharOperation.concat(name, srcMethod.signature());
    int offset = 0;
    MethodModel model = srcMethod.model;
    if (model != null)
        offset = model._lineOffset;
    // offset in destModel and attribute will be updated by BytecodeTransformer (needs full line number info of source)
    return new CopyInheritanceSourceAttribute(name, offset);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.TThisBinding.java

License:Open Source License

public char[] readableName() {
    if (this.name != IOTConstants.TTHIS)
        return this.name;
    char[] tmp = CharOperation.concat(this.name, this.type.sourceName(), '[');
    return CharOperation.append(tmp, ']');
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel.java

License:Open Source License

/** The Attributename of this role's baseclass as it is used in bytecode attributes.
 *  PRE: this is a bound role./*from   w  w w .  ja  va 2s  .  c o m*/
 *  @param includeAnchor should anchored types be encoded in full?
 */
public char[] getBaseclassAttributename(boolean includeAnchor) {
    ReferenceBinding baseclass = getBinding().baseclass();
    char[] baseName = baseclass.getRealClass().attributeName();
    if (includeAnchor && RoleTypeBinding.isRoleWithExplicitAnchor(baseclass))
        return CharOperation.concat(baseName, CharOperation.concat(SingleValueAttribute.ANCHOR_DELIM,
                CharOperation.append(((RoleTypeBinding) baseclass)._teamAnchor.getBestName(), '>')));
    return baseName;
}