use of com.sun.tools.classfile.Descriptor.InvalidDescriptor 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.Descriptor.InvalidDescriptor in project jdk8u_jdk by JetBrains.
the class AnnotationsElementVisitor method readFrom.
public Element readFrom(InputStream in) throws IOException {
try {
this.in = in;
ClassFile c = ClassFile.read(in);
// read the file header
if (c.magic != 0xCAFEBABE) {
throw new RuntimeException("bad magic number " + Integer.toHexString(c.magic));
}
cfile.setAttr("magic", "" + c.magic);
int minver = c.minor_version;
int majver = c.major_version;
cfile.setAttr("minver", "" + minver);
cfile.setAttr("majver", "" + majver);
readCP(c);
readClass(c);
return result();
} catch (InvalidDescriptor | ConstantPoolException ex) {
throw new IOException("Fatal error", ex);
}
}
use of com.sun.tools.classfile.Descriptor.InvalidDescriptor in project ceylon-compiler by ceylon.
the class AnnotationWriter method writeDescriptor.
private void writeDescriptor(int index, boolean resolveIndices) {
if (resolveIndices) {
try {
ConstantPool constant_pool = classWriter.getClassFile().constant_pool;
Descriptor d = new Descriptor(index);
print(d.getFieldType(constant_pool));
return;
} catch (ConstantPoolException ignore) {
} catch (InvalidDescriptor ignore) {
}
}
print("#" + index);
}
use of com.sun.tools.classfile.Descriptor.InvalidDescriptor in project ceylon-compiler by ceylon.
the class LocalVariableTypeTableWriter method writeLocalVariables.
public void writeLocalVariables(int pc, NoteKind kind) {
ConstantPool constant_pool = classWriter.getClassFile().constant_pool;
// get from Options?
String indent = space(2);
List<LocalVariableTypeTable_attribute.Entry> entries = pcMap.get(pc);
if (entries != null) {
for (ListIterator<LocalVariableTypeTable_attribute.Entry> iter = entries.listIterator(kind == NoteKind.END ? entries.size() : 0); kind == NoteKind.END ? iter.hasPrevious() : iter.hasNext(); ) {
LocalVariableTypeTable_attribute.Entry entry = kind == NoteKind.END ? iter.previous() : iter.next();
if (kind.match(entry, pc)) {
print(indent);
print(kind.text);
print(" generic local ");
print(entry.index);
print(" // ");
Descriptor d = new Signature(entry.signature_index);
try {
print(d.getFieldType(constant_pool).toString().replace("/", "."));
} 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.Descriptor.InvalidDescriptor in project ceylon-compiler by ceylon.
the class StackMapWriter method setStackMap.
void setStackMap(StackMapTable_attribute attr) {
if (attr == null) {
map = null;
return;
}
Method m = classWriter.getMethod();
Descriptor d = m.descriptor;
String[] args;
try {
ConstantPool cp = classWriter.getClassFile().constant_pool;
String argString = d.getParameterTypes(cp);
args = argString.substring(1, argString.length() - 1).split("[, ]+");
} catch (ConstantPoolException e) {
return;
} catch (InvalidDescriptor e) {
return;
}
boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC);
verification_type_info[] initialLocals = new verification_type_info[(isStatic ? 0 : 1) + args.length];
if (!isStatic)
initialLocals[0] = new CustomVerificationTypeInfo("this");
for (int i = 0; i < args.length; i++) {
initialLocals[(isStatic ? 0 : 1) + i] = new CustomVerificationTypeInfo(args[i].replace(".", "/"));
}
map = new HashMap<Integer, StackMap>();
StackMapBuilder builder = new StackMapBuilder();
// using -1 as the pc for the initial frame effectively compensates for
// the difference in behavior for the first stack map frame (where the
// pc offset is just offset_delta) compared to subsequent frames (where
// the pc offset is always offset_delta+1).
int pc = -1;
map.put(pc, new StackMap(initialLocals, empty));
for (int i = 0; i < attr.entries.length; i++) pc = attr.entries[i].accept(builder, pc);
}
Aggregations