Example usage for org.eclipse.jdt.core Signature toString

List of usage examples for org.eclipse.jdt.core Signature toString

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Signature toString.

Prototype

public static String toString(String methodSignature, String methodName, String[] parameterNames,
        boolean fullyQualifyTypeNames, boolean includeReturnType, boolean isVarArgs) 

Source Link

Document

Converts the given method signature to a readable string.

Usage

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  w  w.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;
}