Search in sources :

Example 1 with Attribute

use of com.sun.tools.classfile.Attribute in project jdk8u_jdk by JetBrains.

the class AnnotationsElementVisitor method readAttributesFor.

protected void readAttributesFor(ClassFile c, Attributes attrs, Element x) {
    Element container = new Element();
    AttributeVisitor av = new AttributeVisitor(this, c);
    for (Attribute a : attrs) {
        av.visit(a, container);
    }
    if (!keepOrder) {
        container.sort();
    }
    x.addAll(container);
}
Also used : Attribute(com.sun.tools.classfile.Attribute) DefaultAttribute(com.sun.tools.classfile.DefaultAttribute) Element(xmlkit.XMLKit.Element)

Example 2 with Attribute

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

the class SourceWriter method setLineMap.

private void setLineMap(Code_attribute attr) {
    SortedMap<Integer, SortedSet<Integer>> map = new TreeMap<Integer, SortedSet<Integer>>();
    SortedSet<Integer> allLines = new TreeSet<Integer>();
    for (Attribute a : attr.attributes) {
        if (a instanceof LineNumberTable_attribute) {
            LineNumberTable_attribute t = (LineNumberTable_attribute) a;
            for (LineNumberTable_attribute.Entry e : t.line_number_table) {
                int start_pc = e.start_pc;
                int line = e.line_number;
                SortedSet<Integer> pcLines = map.get(start_pc);
                if (pcLines == null) {
                    pcLines = new TreeSet<Integer>();
                    map.put(start_pc, pcLines);
                }
                pcLines.add(line);
                allLines.add(line);
            }
        }
    }
    lineMap = map;
    lineList = new ArrayList<Integer>(allLines);
}
Also used : Attribute(com.sun.tools.classfile.Attribute) TreeSet(java.util.TreeSet) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) LineNumberTable_attribute(com.sun.tools.classfile.LineNumberTable_attribute)

Example 3 with Attribute

use of com.sun.tools.classfile.Attribute 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)

Example 4 with Attribute

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

the class AttributeWriter method write.

public void write(Object owner, Attributes attrs, ConstantPool constant_pool) {
    if (attrs != null) {
        // null checks
        owner.getClass();
        constant_pool.getClass();
        this.constant_pool = constant_pool;
        this.owner = owner;
        for (Attribute attr : attrs) attr.accept(this, null);
    }
}
Also used : Attribute(com.sun.tools.classfile.Attribute) DefaultAttribute(com.sun.tools.classfile.DefaultAttribute)

Example 5 with Attribute

use of com.sun.tools.classfile.Attribute in project jdk8u_jdk by JetBrains.

the class LambdaAsm method checkMethod.

static int checkMethod(ClassFile cf, String mthd) throws Exception {
    if (cf.major_version < 52) {
        throw new RuntimeException("unexpected class file version, in " + cf.getName() + "expected 52, got " + cf.major_version);
    }
    int count = 0;
    for (Method m : cf.methods) {
        String mname = m.getName(cf.constant_pool);
        if (mname.equals(mthd)) {
            for (Attribute a : m.attributes) {
                if ("Code".equals(a.getName(cf.constant_pool))) {
                    count++;
                    checkMethod(cf.getName(), mname, cf.constant_pool, (Code_attribute) a);
                }
            }
        }
    }
    return count;
}
Also used : Attribute(com.sun.tools.classfile.Attribute) Method(com.sun.tools.classfile.Method)

Aggregations

Attribute (com.sun.tools.classfile.Attribute)7 AccessFlags (com.sun.tools.classfile.AccessFlags)3 ConstantPoolException (com.sun.tools.classfile.ConstantPoolException)3 Signature_attribute (com.sun.tools.classfile.Signature_attribute)3 Type (com.sun.tools.classfile.Type)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 DefaultAttribute (com.sun.tools.classfile.DefaultAttribute)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 LineNumberTable_attribute (com.sun.tools.classfile.LineNumberTable_attribute)1 Method (com.sun.tools.classfile.Method)1 Signature (com.sun.tools.classfile.Signature)1