From: Andy Clement Date: Tue, 5 Aug 2014 22:40:19 +0000 (-0700) Subject: Add toString to BootstrapMethods in BCEL X-Git-Tag: V1_8_2~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=25f3a34a0c1e2db9b34f00afdbfb2d15d89e6418;p=aspectj.git Add toString to BootstrapMethods in BCEL --- 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 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"; + } + } + } diff --git a/lib/bcel/bcel-src.zip b/lib/bcel/bcel-src.zip index d6745a981..7b2259ed0 100644 Binary files a/lib/bcel/bcel-src.zip and b/lib/bcel/bcel-src.zip differ diff --git a/lib/bcel/bcel-verifier.jar b/lib/bcel/bcel-verifier.jar index 1863f1ece..246522439 100644 Binary files a/lib/bcel/bcel-verifier.jar and b/lib/bcel/bcel-verifier.jar differ diff --git a/lib/bcel/bcel.jar b/lib/bcel/bcel.jar index 2db4a9983..f4b2cff65 100644 Binary files a/lib/bcel/bcel.jar and b/lib/bcel/bcel.jar differ