Search in sources :

Example 1 with Type

use of com.sun.tools.classfile.Type in project ceylon-compiler by ceylon.

the class Signature method getParameterTypes.

@Override
public String getParameterTypes(ConstantPool constant_pool) throws ConstantPoolException {
    MethodType m = (MethodType) getType(constant_pool);
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    String sep = "";
    for (Type paramType : m.paramTypes) {
        sb.append(sep);
        sb.append(paramType);
        sep = ", ";
    }
    sb.append(")");
    return sb.toString();
}
Also used : Type(com.sun.tools.classfile.Type)

Example 2 with Type

use of com.sun.tools.classfile.Type in project ceylon-compiler by ceylon.

the class Signature method parse.

private Type parse(String sig) {
    this.sig = sig;
    sigp = 0;
    List<TypeParamType> typeParamTypes = null;
    if (sig.charAt(sigp) == '<')
        typeParamTypes = parseTypeParamTypes();
    if (sig.charAt(sigp) == '(') {
        List<Type> paramTypes = parseTypeSignatures(')');
        Type returnType = parseTypeSignature();
        List<Type> throwsTypes = null;
        while (sigp < sig.length() && sig.charAt(sigp) == '^') {
            sigp++;
            if (throwsTypes == null)
                throwsTypes = new ArrayList<Type>();
            throwsTypes.add(parseTypeSignature());
        }
        return new MethodType(typeParamTypes, paramTypes, returnType, throwsTypes);
    } else {
        Type t = parseTypeSignature();
        if (typeParamTypes == null && sigp == sig.length())
            return t;
        Type superclass = t;
        List<Type> superinterfaces = null;
        while (sigp < sig.length()) {
            if (superinterfaces == null)
                superinterfaces = new ArrayList<Type>();
            superinterfaces.add(parseTypeSignature());
        }
        return new ClassSigType(typeParamTypes, superclass, superinterfaces);
    }
}
Also used : Type(com.sun.tools.classfile.Type) ArrayList(java.util.ArrayList)

Example 3 with Type

use of com.sun.tools.classfile.Type in project ceylon-compiler by ceylon.

the class Signature method parseTypeParamType.

private TypeParamType parseTypeParamType() {
    int sep = sig.indexOf(":", sigp);
    String name = sig.substring(sigp, sep);
    Type classBound = null;
    List<Type> interfaceBounds = null;
    sigp = sep + 1;
    if (sig.charAt(sigp) != ':')
        classBound = parseTypeSignature();
    while (sig.charAt(sigp) == ':') {
        sigp++;
        if (interfaceBounds == null)
            interfaceBounds = new ArrayList<Type>();
        interfaceBounds.add(parseTypeSignature());
    }
    return new TypeParamType(name, classBound, interfaceBounds);
}
Also used : Type(com.sun.tools.classfile.Type) ArrayList(java.util.ArrayList)

Example 4 with Type

use of com.sun.tools.classfile.Type in project ceylon-compiler by ceylon.

the class Signature method parseTypeVariableSignature.

private Type parseTypeVariableSignature() {
    sigp++;
    int sep = sig.indexOf(';', sigp);
    Type t = new SimpleType(sig.substring(sigp, sep));
    sigp = sep + 1;
    return t;
}
Also used : Type(com.sun.tools.classfile.Type)

Example 5 with Type

use of com.sun.tools.classfile.Type in project ceylon-compiler by ceylon.

the class ClassWriter method writeField.

protected void writeField(Field f) {
    if (!options.checkAccess(f.access_flags))
        return;
    AccessFlags flags = f.access_flags;
    writeModifiers(flags.getFieldModifiers());
    Signature_attribute sigAttr = getSignature(f.attributes);
    if (sigAttr == null)
        print(getJavaFieldType(f.descriptor));
    else {
        try {
            Type t = sigAttr.getParsedSignature().getType(constant_pool);
            print(getJavaName(t.toString()));
        } catch (ConstantPoolException e) {
            // report error?
            // fall back on non-generic descriptor
            print(getJavaFieldType(f.descriptor));
        }
    }
    print(" ");
    print(getFieldName(f));
    if (options.showConstants && !options.compat) {
        // BUG 4111861 print static final field contents
        Attribute a = f.attributes.get(Attribute.ConstantValue);
        if (a instanceof ConstantValue_attribute) {
            print(" = ");
            ConstantValue_attribute cv = (ConstantValue_attribute) a;
            print(getConstantValue(f.descriptor, cv.constantvalue_index));
        }
    }
    print(";");
    println();
    indent(+1);
    if (options.showInternalSignatures)
        println("Signature: " + getValue(f.descriptor));
    if (options.verbose && !options.compat)
        writeList("flags: ", flags.getFieldFlags(), NEWLINE);
    if (options.showAllAttrs) {
        for (Attribute attr : f.attributes) attrWriter.write(f, attr, constant_pool);
        println();
    }
    indent(-1);
    if (options.showDisassembled || options.showLineAndLocalVariableTables)
        println();
}
Also used : Type(com.sun.tools.classfile.Type) ArrayType(com.sun.tools.classfile.Type.ArrayType) ClassType(com.sun.tools.classfile.Type.ClassType) MethodType(com.sun.tools.classfile.Type.MethodType) WildcardType(com.sun.tools.classfile.Type.WildcardType) TypeParamType(com.sun.tools.classfile.Type.TypeParamType) SimpleType(com.sun.tools.classfile.Type.SimpleType) ClassSigType(com.sun.tools.classfile.Type.ClassSigType) ConstantValue_attribute(com.sun.tools.classfile.ConstantValue_attribute) Attribute(com.sun.tools.classfile.Attribute) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) Signature_attribute(com.sun.tools.classfile.Signature_attribute) AccessFlags(com.sun.tools.classfile.AccessFlags)

Aggregations

Type (com.sun.tools.classfile.Type)7 AccessFlags (com.sun.tools.classfile.AccessFlags)3 Attribute (com.sun.tools.classfile.Attribute)3 ConstantPoolException (com.sun.tools.classfile.ConstantPoolException)3 Signature_attribute (com.sun.tools.classfile.Signature_attribute)3 ArrayType (com.sun.tools.classfile.Type.ArrayType)3 ClassSigType (com.sun.tools.classfile.Type.ClassSigType)3 ClassType (com.sun.tools.classfile.Type.ClassType)3 MethodType (com.sun.tools.classfile.Type.MethodType)3 SimpleType (com.sun.tools.classfile.Type.SimpleType)3 TypeParamType (com.sun.tools.classfile.Type.TypeParamType)3 WildcardType (com.sun.tools.classfile.Type.WildcardType)3 ArrayList (java.util.ArrayList)2 Code_attribute (com.sun.tools.classfile.Code_attribute)1 ConstantValue_attribute (com.sun.tools.classfile.ConstantValue_attribute)1 Descriptor (com.sun.tools.classfile.Descriptor)1 Exceptions_attribute (com.sun.tools.classfile.Exceptions_attribute)1 Signature (com.sun.tools.classfile.Signature)1 SourceFile_attribute (com.sun.tools.classfile.SourceFile_attribute)1 DateFormat (java.text.DateFormat)1