]> source.dussan.org Git - aspectj.git/commitdiff
Add toString to BootstrapMethods in BCEL
authorAndy Clement <aclement@gopivotal.com>
Tue, 5 Aug 2014 22:40:19 +0000 (15:40 -0700)
committerAndy Clement <aclement@gopivotal.com>
Tue, 5 Aug 2014 22:40:19 +0000 (15:40 -0700)
bcel-builder/src/org/aspectj/apache/bcel/classfile/BootstrapMethods.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantMethodHandle.java
lib/bcel/bcel-src.zip
lib/bcel/bcel-verifier.jar
lib/bcel/bcel.jar

index 04b1c764b4e5da2d8177d93d3a78f0aaf9152d3c..b4638bc293f4226a92a8948a5240dfd43f8efd5b 100644 (file)
@@ -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();
        }
 
 
index fe5623f33aadd05985006293afb087f4108be863..712a13f4c573d10b568dadc95a9b8d3a85a9c224 100644 (file)
@@ -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";
+               }
+       }
+
 }
index d6745a98128d36b854dc83ffd136c141a8219706..7b2259ed01c9ff734ed7bc0896a9217d05b201c4 100644 (file)
Binary files a/lib/bcel/bcel-src.zip and b/lib/bcel/bcel-src.zip differ
index 1863f1ece224f750d22a6b7aa90b8d3d0f56e24a..2465224399ae156a7fdb4e8d81f9e4a771841b6a 100644 (file)
Binary files a/lib/bcel/bcel-verifier.jar and b/lib/bcel/bcel-verifier.jar differ
index 2db4a9983ad4398de2cae0cb09f82ac570e0e1fe..f4b2cff655ccd9fd7cf6a4ed4778d60662e6811d 100644 (file)
Binary files a/lib/bcel/bcel.jar and b/lib/bcel/bcel.jar differ