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

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

Introduction

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

Prototype

public static final char[] replaceOnCopy(char[] array, char toBeReplaced, char replacementChar) 

Source Link

Document

Replace all occurrence of the character to be replaced with the replacement character in a copy of the given array.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java

License:Open Source License

public static char[] getTypeSignature(TypeBinding typeBinding) {
    char[] result = typeBinding.signature();
    if (result != null) {
        result = CharOperation.replaceOnCopy(result, '/', '.');
    }//  www .ja  v  a  2  s .co  m
    return result;
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java

License:Open Source License

public static char[] getSignature(MethodBinding methodBinding) {
    char[] result = null;

    int oldMod = methodBinding.modifiers;
    //TODO remove the next line when method from binary type will be able to generate generic signature
    methodBinding.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
    result = methodBinding.genericSignature();
    if (result == null) {
        result = methodBinding.signature();
    }//from   w ww . ja v  a  2s .  c  o m
    methodBinding.modifiers = oldMod;

    if (result != null) {
        result = CharOperation.replaceOnCopy(result, '/', '.');
    }
    return result;
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java

License:Open Source License

public static char[] getSignature(TypeBinding typeBinding) {
    char[] result = null;

    result = typeBinding.genericTypeSignature();

    if (result != null) {
        result = CharOperation.replaceOnCopy(result, '/', '.');
    }//from  ww  w .j av a 2s  . co  m
    return result;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryMethod.java

License:Open Source License

public String[] getExceptionTypes() throws JavaModelException {
    if (this.exceptionTypes == null) {
        IBinaryMethod info = (IBinaryMethod) getElementInfo();
        char[] genericSignature = info.getGenericSignature();
        if (genericSignature != null) {
            char[] dotBasedSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.');
            this.exceptionTypes = Signature.getThrownExceptionTypes(new String(dotBasedSignature));
        }//w ww.  ja  v a  2s . com
        if (this.exceptionTypes == null || this.exceptionTypes.length == 0) {
            char[][] eTypeNames = info.getExceptionTypeNames();
            if (eTypeNames == null || eTypeNames.length == 0) {
                this.exceptionTypes = CharOperation.NO_STRINGS;
            } else {
                eTypeNames = ClassFile.translatedNames(eTypeNames);
                this.exceptionTypes = new String[eTypeNames.length];
                for (int j = 0, length = eTypeNames.length; j < length; j++) {
                    // 1G01HRY: ITPJCORE:WINNT - method.getExceptionType not in correct format
                    int nameLength = eTypeNames[j].length;
                    char[] convertedName = new char[nameLength + 2];
                    System.arraycopy(eTypeNames[j], 0, convertedName, 1, nameLength);
                    convertedName[0] = 'L';
                    convertedName[nameLength + 1] = ';';
                    this.exceptionTypes[j] = new String(convertedName);
                }
            }
        }
    }
    return this.exceptionTypes;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryMethod.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IMethod#getTypeParameterSignatures()
 * @since 3.0//from   www .  j  a v a  2 s. c o  m
 * @deprecated
 */
public String[] getTypeParameterSignatures() throws JavaModelException {
    IBinaryMethod info = (IBinaryMethod) getElementInfo();
    char[] genericSignature = info.getGenericSignature();
    if (genericSignature == null)
        return CharOperation.NO_STRINGS;
    char[] dotBasedSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.');
    char[][] typeParams = Signature.getTypeParameters(dotBasedSignature);
    return CharOperation.toStrings(typeParams);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryMethod.java

License:Open Source License

private String getReturnType(IBinaryMethod info) {
    char[] genericSignature = info.getGenericSignature();
    char[] signature = genericSignature == null ? info.getMethodDescriptor() : genericSignature;
    char[] dotBasedSignature = CharOperation.replaceOnCopy(signature, '/', '.');
    String returnTypeName = Signature.getReturnType(new String(dotBasedSignature));
    return new String(ClassFile.translatedName(returnTypeName.toCharArray()));
}

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IType#getTypeParameterSignatures()
 * @since 3.0//from   w  ww .jav a2s.  c om
 */
public String[] getTypeParameterSignatures() throws JavaModelException {
    IBinaryType info = (IBinaryType) getElementInfo();
    char[] genericSignature = info.getGenericSignature();
    if (genericSignature == null)
        return CharOperation.NO_STRINGS;

    char[] dotBaseSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.');
    char[][] typeParams = Signature.getTypeParameters(dotBaseSignature);
    return CharOperation.toStrings(typeParams);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFileInfo.java

License:Open Source License

private void generateAnnotationInfo(JavaElement parent, char[] parameterName, HashMap newElements,
        IBinaryAnnotation annotationInfo, String memberValuePairName) {
    char[] typeName = org.eclipse.jdt.core.Signature
            .toCharArray(CharOperation.replaceOnCopy(annotationInfo.getTypeName(), '/', '.'));
    Annotation annotation = new Annotation(parent, parent.manager, new String(typeName), memberValuePairName);
    while (newElements.containsKey(annotation)) {
        annotation.occurrenceCount++;/*  ww w.  j a  va 2 s. co m*/
    }
    newElements.put(annotation, annotationInfo);
    IBinaryElementValuePair[] pairs = annotationInfo.getElementValuePairs();
    for (int i = 0, length = pairs.length; i < length; i++) {
        Object value = pairs[i].getValue();
        if (value instanceof IBinaryAnnotation) {
            generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) value,
                    new String(pairs[i].getName()));
        } else if (value instanceof Object[]) {
            // if the value is an array, it can have no more than 1 dimension - no need to recurse
            Object[] valueArray = (Object[]) value;
            for (int j = 0, valueArrayLength = valueArray.length; j < valueArrayLength; j++) {
                Object nestedValue = valueArray[j];
                if (nestedValue instanceof IBinaryAnnotation) {
                    generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) nestedValue,
                            new String(pairs[i].getName()));
                }
            }
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.JavadocContents.java

License:Open Source License

private String computeMethodAnchorPrefixEnd(BinaryMethod method) throws JavaModelException {
    String typeQualifiedName = null;
    if (this.type.isMember()) {
        IType currentType = this.type;
        StringBuffer buffer = new StringBuffer();
        while (currentType != null) {
            buffer.insert(0, currentType.getElementName());
            currentType = currentType.getDeclaringType();
            if (currentType != null) {
                buffer.insert(0, '.');
            }/* w ww .  j av a 2  s. co  m*/
        }
        typeQualifiedName = new String(buffer.toString());
    } else {
        typeQualifiedName = this.type.getElementName();
    }

    String methodName = method.getElementName();
    if (method.isConstructor()) {
        methodName = typeQualifiedName;
    }
    IBinaryMethod info = (IBinaryMethod) method.getElementInfo();

    char[] genericSignature = info.getGenericSignature();
    String anchor = null;
    if (genericSignature != null) {
        genericSignature = CharOperation.replaceOnCopy(genericSignature, '/', '.');
        anchor = Util.toAnchor(0, genericSignature, methodName, Flags.isVarargs(method.getFlags()));
        if (anchor == null)
            throw new JavaModelException(
                    new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, method));
    } else {
        anchor = Signature.toString(method.getSignature().replace('/', '.'), methodName, null, true, false,
                Flags.isVarargs(method.getFlags()));
    }
    IType declaringType = this.type;
    if (declaringType.isMember()) {
        // might need to remove a part of the signature corresponding to the synthetic argument (only for constructor)
        if (method.isConstructor() && !Flags.isStatic(declaringType.getFlags())) {
            int indexOfOpeningParen = anchor.indexOf('(');
            if (indexOfOpeningParen == -1) {
                // should not happen as this is a method signature
                return null;
            }
            int index = indexOfOpeningParen;
            indexOfOpeningParen++;
            int indexOfComma = anchor.indexOf(',', index);
            if (indexOfComma != -1) {
                index = indexOfComma + 2;
            } else {
                // no argument, but a synthetic argument
                index = anchor.indexOf(')', index);
            }
            anchor = anchor.substring(0, indexOfOpeningParen) + anchor.substring(index);
        }
    }
    return anchor + JavadocConstants.ANCHOR_PREFIX_END;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.BinaryIndexer.java

License:Open Source License

public void addTypeReference(char[] typeName) {
    int length = typeName.length;
    if (length > 2 && typeName[length - 2] == '$') {
        switch (typeName[length - 1]) {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            return; // skip local type names
        }/*  w w  w  .  j  av  a 2 s  .  c o m*/
    }

    // consider that A$B is a member type: so replace '$' with '.'
    // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=40116)
    typeName = CharOperation.replaceOnCopy(typeName, '$', '.'); // copy it so the original is not modified

    super.addTypeReference(typeName);
}