Search in sources :

Example 6 with ConstantPoolException

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

the class LocalVariableTableWriter method writeLocalVariables.

public void writeLocalVariables(int pc, NoteKind kind) {
    ConstantPool constant_pool = classWriter.getClassFile().constant_pool;
    // get from Options?
    String indent = space(2);
    List<LocalVariableTable_attribute.Entry> entries = pcMap.get(pc);
    if (entries != null) {
        for (ListIterator<LocalVariableTable_attribute.Entry> iter = entries.listIterator(kind == NoteKind.END ? entries.size() : 0); kind == NoteKind.END ? iter.hasPrevious() : iter.hasNext(); ) {
            LocalVariableTable_attribute.Entry entry = kind == NoteKind.END ? iter.previous() : iter.next();
            if (kind.match(entry, pc)) {
                print(indent);
                print(kind.text);
                print(" local ");
                print(entry.index);
                print(" // ");
                Descriptor d = new Descriptor(entry.descriptor_index);
                try {
                    print(d.getFieldType(constant_pool));
                } catch (InvalidDescriptor e) {
                    print(report(e));
                } catch (ConstantPoolException e) {
                    print(report(e));
                }
                print(" ");
                try {
                    print(constant_pool.getUTF8Value(entry.name_index));
                } catch (ConstantPoolException e) {
                    print(report(e));
                }
                println();
            }
        }
    }
}
Also used : ConstantPool(com.sun.tools.classfile.ConstantPool) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor) Descriptor(com.sun.tools.classfile.Descriptor) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor) LocalVariableTable_attribute(com.sun.tools.classfile.LocalVariableTable_attribute)

Example 7 with ConstantPoolException

use of com.sun.tools.classfile.ConstantPoolException 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 8 with ConstantPoolException

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

the class SourceWriter method readSource.

private String readSource(ClassFile cf) {
    if (fileManager == null)
        return null;
    Location location;
    if (fileManager.hasLocation((StandardLocation.SOURCE_PATH)))
        location = StandardLocation.SOURCE_PATH;
    else
        location = StandardLocation.CLASS_PATH;
    // InnerClasses and EnclosingMethod attributes.
    try {
        String className = cf.getName();
        SourceFile_attribute sf = (SourceFile_attribute) cf.attributes.get(Attribute.SourceFile);
        if (sf == null) {
            report(messages.getMessage("err.no.SourceFile.attribute"));
            return null;
        }
        String sourceFile = sf.getSourceFile(cf.constant_pool);
        String fileBase = sourceFile.endsWith(".java") ? sourceFile.substring(0, sourceFile.length() - 5) : sourceFile;
        int sep = className.lastIndexOf("/");
        String pkgName = (sep == -1 ? "" : className.substring(0, sep + 1));
        String topClassName = (pkgName + fileBase).replace('/', '.');
        JavaFileObject fo = fileManager.getJavaFileForInput(location, topClassName, JavaFileObject.Kind.SOURCE);
        if (fo == null) {
            report(messages.getMessage("err.source.file.not.found"));
            return null;
        }
        return fo.getCharContent(true).toString();
    } catch (ConstantPoolException e) {
        report(e);
        return null;
    } catch (IOException e) {
        report(e.getLocalizedMessage());
        return null;
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) IOException(java.io.IOException) StandardLocation(javax.tools.StandardLocation) Location(javax.tools.JavaFileManager.Location) SourceFile_attribute(com.sun.tools.classfile.SourceFile_attribute)

Example 9 with ConstantPoolException

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

the class AnnotationsElementVisitor method visitMethodHandle.

@Override
public String visitMethodHandle(CONSTANT_MethodHandle_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = c.reference_kind.name();
            value = value.concat(" " + visit(cfpool.get(c.reference_index), c.reference_index));
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_MethodHandle", new String[] { "id", p.toString() }, value));
        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
Also used : Element(xmlkit.XMLKit.Element) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException)

Example 10 with ConstantPoolException

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

the class AnnotationsElementVisitor method visitFieldref.

@Override
public String visitFieldref(CONSTANT_Fieldref_info c, Integer p) {
    String value = slist.get(p);
    if (value == null) {
        try {
            value = visit(cfpool.get(c.class_index), c.class_index);
            value = value.concat(" " + visit(cfpool.get(c.name_and_type_index), c.name_and_type_index));
            slist.set(p, value);
            xpool.add(new Element("CONSTANT_Fieldref", new String[] { "id", p.toString() }, value));
        } catch (ConstantPoolException ex) {
            ex.printStackTrace();
        }
    }
    return value;
}
Also used : Element(xmlkit.XMLKit.Element) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException)

Aggregations

ConstantPoolException (com.sun.tools.classfile.ConstantPoolException)20 Element (xmlkit.XMLKit.Element)8 ConstantPool (com.sun.tools.classfile.ConstantPool)6 Descriptor (com.sun.tools.classfile.Descriptor)5 InvalidDescriptor (com.sun.tools.classfile.Descriptor.InvalidDescriptor)5 AccessFlags (com.sun.tools.classfile.AccessFlags)3 Attribute (com.sun.tools.classfile.Attribute)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 ClassFile (com.sun.tools.classfile.ClassFile)2 Method (com.sun.tools.classfile.Method)2 Signature (com.sun.tools.classfile.Signature)2 SourceFile_attribute (com.sun.tools.classfile.SourceFile_attribute)2