aboutsummaryrefslogtreecommitdiffstats
path: root/bcel-builder/src
diff options
context:
space:
mode:
authorAndy Clement <aclement@gopivotal.com>2014-08-05 15:40:19 -0700
committerAndy Clement <aclement@gopivotal.com>2014-08-05 15:40:19 -0700
commit25f3a34a0c1e2db9b34f00afdbfb2d15d89e6418 (patch)
tree271751fbd4360be4d8551be9ffff129501c1aa9f /bcel-builder/src
parenta040ec74209f82203f0f3aef1694c8a924f48216 (diff)
downloadaspectj-25f3a34a0c1e2db9b34f00afdbfb2d15d89e6418.tar.gz
aspectj-25f3a34a0c1e2db9b34f00afdbfb2d15d89e6418.zip
Add toString to BootstrapMethods in BCEL
Diffstat (limited to 'bcel-builder/src')
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java72
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java32
2 files changed, 67 insertions, 37 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java
index 04b1c764b..b4638bc29 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java
@@ -120,6 +120,14 @@ public final class BootstrapMethods extends Attribute {
this.bootstrapMethodRef = bootstrapMethodRef;
this.bootstrapArguments = bootstrapArguments;
}
+
+ public int getBootstrapMethodRef() {
+ return bootstrapMethodRef;
+ }
+
+ public int[] getBootstrapArguments() {
+ return bootstrapArguments;
+ }
public final void dump(DataOutputStream file) throws IOException {
file.writeShort(bootstrapMethodRef);
@@ -129,6 +137,7 @@ public final class BootstrapMethods extends Attribute {
file.writeShort(bootstrapArguments[i]);
}
}
+
}
// Unpacks the byte array into the table
@@ -137,9 +146,9 @@ public final class BootstrapMethods extends Attribute {
try {
ByteArrayInputStream bs = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bs);
- int bootstrapMethodCount = dis.readUnsignedShort();
- bootstrapMethods = new BootstrapMethod[bootstrapMethodCount];
- for (int i = 0; i < bootstrapMethodCount; i++) {
+ numBootstrapMethods = dis.readUnsignedShort();
+ bootstrapMethods = new BootstrapMethod[numBootstrapMethods];
+ for (int i = 0; i < numBootstrapMethods; i++) {
bootstrapMethods[i] = new BootstrapMethod(dis);
}
dis.close();
@@ -194,28 +203,41 @@ public final class BootstrapMethods extends Attribute {
*/
@Override
public final String toString() {
- throw new IllegalStateException("nyi");
-// unpack();
-// StringBuffer buf = new StringBuffer();
-// StringBuffer line = new StringBuffer();
-//
-// for (int i = 0; i < bootstrapMethodCount; i++) {
-// line.append(table[i].toString());
-//
-// if (i < bootstrapMethodCount - 1) {
-// line.append(", ");
-// }
-//
-// if (line.length() > 72) {
-// line.append('\n');
-// buf.append(line);
-// line.setLength(0);
-// }
-// }
-//
-// buf.append(line);
-//
-// return buf.toString();
+ unpack();
+ StringBuffer buf = new StringBuffer();
+ StringBuffer line = new StringBuffer();
+
+ for (int i = 0; i < numBootstrapMethods; i++) {
+ BootstrapMethod bm = bootstrapMethods[i];
+ line.append("BootstrapMethod[").append(i).append("]:");
+ int ref = bm.getBootstrapMethodRef();
+ ConstantMethodHandle mh = (ConstantMethodHandle)getConstantPool().getConstant(ref);
+ line.append("#"+ref+":");
+ line.append(ConstantMethodHandle.kindToString(mh.getReferenceKind()));
+ line.append(" ").append(getConstantPool().getConstant(mh.getReferenceIndex()));
+ int [] args = bm.getBootstrapArguments();
+ line.append(" argcount:").append(args==null?0:args.length).append(" ");
+ if (args!=null) {
+ for (int a=0;a<args.length;a++) {
+ line.append(args[a]).append("(").append(getConstantPool().getConstant(args[a])).append(") ");
+ }
+ }
+
+
+ if (i < numBootstrapMethods - 1) {
+ line.append(", ");
+ }
+
+ if (line.length() > 72) {
+ line.append('\n');
+ buf.append(line);
+ line.setLength(0);
+ }
+ }
+
+ buf.append(line);
+
+ return buf.toString();
}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java
index fe5623f33..712a13f4c 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java
@@ -93,18 +93,10 @@ public final class ConstantMethodHandle extends Constant {
public final byte getReferenceKind() {
return referenceKind;
}
-
-// public final String getName(ConstantPool cp) {
-// return cp.constantToString(getNameIndex(), Constants.CONSTANT_Utf8);
-// }
-//
-// public final int getSignatureIndex() {
-// return referenceIndex;
-// }
-//
-// public final String getSignature(ConstantPool cp) {
-// return cp.constantToString(getSignatureIndex(), Constants.CONSTANT_Utf8);
-// }
+
+ public final int getReferenceIndex() {
+ return referenceIndex;
+ }
@Override
public final String toString() {
@@ -121,4 +113,20 @@ public final class ConstantMethodHandle extends Constant {
v.visitConstantMethodHandle(this);
}
+ public static String kindToString(byte kind) {
+ switch (kind) {
+ case 1: return "getfield";
+ case 2: return "getstatic";
+ case 3: return "putfield";
+ case 4: return "putstatic";
+ case 5: return "invokevirtual";
+ case 6: return "invokestatic";
+ case 7: return "invokespecial";
+ case 8: return "newinvokespecial";
+ case 9: return "invokeinterface";
+ default:
+ return "nyi";
+ }
+ }
+
}