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

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

Introduction

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

Prototype

char C_COLON

To view the source code for org.eclipse.jdt.core Signature C_COLON.

Click Source Link

Document

Character constant indicating the colon in a signature.

Usage

From source file:org.jboss.tools.common.java.ParametedTypeFactory.java

License:Open Source License

public ParametedType getParametedType(IMember context, IParametedType basetype, String typeSignature)
        throws JavaModelException {
    if (typeSignature == null)
        return null;
    if (basetype != null) {
        ParametedType param = ((ParametedType) basetype).findParameter(typeSignature);
        if (param != null)
            return param;
    }// w  w  w .  j  a  v  a  2 s. c  o m

    IType contextType = context instanceof IType ? (IType) context : context.getDeclaringType();

    String key = context == null || context.isBinary() || OBJECT.equals(typeSignature) ? typeSignature
            : contextType.getFullyQualifiedName() + "+" + typeSignature;
    if (cache.containsKey(key))
        return cache.get(key);
    ParametedType result = new ParametedType();
    result.setFactory(this);
    result.setSignature(typeSignature);

    typeSignature = typeSignature.substring(result.getArrayIndex());

    char c = typeSignature.length() == 0 ? '\0' : typeSignature.charAt(0);
    if (primitives.containsKey(c) && typeSignature.length() == 1) {
        typeSignature = primitives.get(c);
        result.setSignature(result.getArrayPrefix() + typeSignature);
        result.setPrimitive(true);
    } else if (c == Signature.C_EXTENDS) {
        typeSignature = typeSignature.substring(1);
        result.setUpper(true);
    } else if (c == Signature.C_SUPER) {
        typeSignature = typeSignature.substring(1);
        result.setLower(true);
    } else if (c == Signature.C_STAR && typeSignature.length() == 1) {
        result.setUpper(true);
        return result;
    }

    int startToken = typeSignature.indexOf(Signature.C_GENERIC_START);
    if (startToken < 0) {
        String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(contextType, typeSignature);
        if (resovedTypeName == null)
            return null;
        if (!context.isBinary() || typeSignature.charAt(0) == Signature.C_TYPE_VARIABLE) {
            StringBuffer ns = new StringBuffer();
            ns.append(result.getArrayPrefix());
            if (result.isLower())
                ns.append(Signature.C_SUPER);
            if (result.isUpper())
                ns.append(Signature.C_EXTENDS);
            ns.append(Signature.C_RESOLVED).append(resovedTypeName).append(Signature.C_SEMICOLON);
            result.setSignature(ns.toString());
        }
        IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
        if (type != null) {
            result.setType(type);
            cache.put(key, result);
            return result;
        }
        if (context instanceof IMethod) {
            String[] ps = ((IMethod) context).getTypeParameterSignatures();
            for (int i = 0; i < ps.length; i++) {
                ParametedType st = getParametedTypeForParameter(context, ps[i], result);
                if (st != null) {
                    if (st.getSignature().indexOf(Signature.C_COLON) >= 0) {
                        CommonCorePlugin.getDefault().logWarning("Wrong signature=" + st.getSignature());
                    }
                    return st;
                }
            }
        }
        String[] ps = contextType.getTypeParameterSignatures();
        for (int i = 0; i < ps.length; i++) {
            ParametedType st = getParametedTypeForParameter(contextType, ps[i], result);
            if (st != null)
                return st;
        }
    } else {
        int endToken = typeSignature.lastIndexOf(Signature.C_GENERIC_END);
        if (endToken < startToken)
            return null;
        String typeName = typeSignature.substring(0, startToken) + typeSignature.substring(endToken + 1);
        String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(contextType, typeName);
        if (resovedTypeName == null)
            return null;
        IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName);
        if (type != null) {
            result.setType(type);
            cache.put(key, result);
            StringBuffer newParams = new StringBuffer();
            String[] paramSignatures = null;
            try {
                paramSignatures = Signature.getTypeArguments(typeSignature);
            } catch (IllegalArgumentException e) {
                CommonCorePlugin.getDefault().logError(e);
            }
            if (paramSignatures != null)
                for (String paramSignature : paramSignatures) {
                    ParametedType param = getParametedType(context, basetype, paramSignature);
                    if (param == null) {
                        param = new ParametedType();
                        param.setSignature(paramSignature);
                    }
                    result.addParameter(param);
                    newParams.append(param.getSignature());
                }
            if (!context.isBinary()) {
                StringBuffer ns = new StringBuffer();
                ns.append(result.getArrayPrefix());
                if (result.isLower())
                    ns.append(Signature.C_SUPER);
                if (result.isUpper())
                    ns.append(Signature.C_EXTENDS);
                ns.append(Signature.C_RESOLVED).append(resovedTypeName).append(Signature.C_GENERIC_START)
                        .append(newParams).append(Signature.C_GENERIC_END).append(Signature.C_SEMICOLON);
                result.setSignature(ns.toString());
            }
            return result;
        }
    }
    return null;
}