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();
}
}
}
}
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();
}
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;
}
}
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;
}
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;
}
Aggregations