]> source.dussan.org Git - aspectj.git/commitdiff
Add missing cases to bcel constantToString
authorAndy Clement <aclement@pivotal.io>
Wed, 7 Feb 2018 20:38:52 +0000 (12:38 -0800)
committerAndy Clement <aclement@pivotal.io>
Wed, 7 Feb 2018 20:38:52 +0000 (12:38 -0800)
20 files changed:
bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java
bcel-builder/testdata/lambda.jar [new file with mode: 0644]
bcel-builder/testdata/lambda/cpl.sh [new file with mode: 0755]
bcel-builder/testdata/lambda/one/Code.class [new file with mode: 0644]
bcel-builder/testdata/lambda/one/Code.java [new file with mode: 0644]
bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java
bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ConstantPoolToStringTest.java [new file with mode: 0644]
lib/asm/asm-6.0.jar [new file with mode: 0644]
lib/asm/asm-6.0.renamed.jar [new file with mode: 0644]
lib/asm/asm-6.0_ALPHA.jar [deleted file]
lib/asm/asm-6.0_ALPHA.renamed.jar [deleted file]
lib/asm/asm-6.0_BETA.jar [deleted file]
lib/asm/asm-6.0_BETA.renamed.jar [deleted file]
lib/asm/build.xml
lib/asm/readme.txt [deleted file]
lib/bcel/bcel-src.zip
lib/bcel/bcel-verifier-src.zip
lib/bcel/bcel-verifier.jar
lib/bcel/bcel.jar
weaver/.classpath

index be5b8456438a5db18426418ec97859adffa3560e..0430e28ba3530ecd0978eb44895d4a7e45a1c8eb 100644 (file)
@@ -207,6 +207,26 @@ public class ConstantPool implements Node {
                        str = (constantToString(((ConstantCP) c).getClassIndex(), Constants.CONSTANT_Class) + "." + constantToString(
                                        ((ConstantCP) c).getNameAndTypeIndex(), Constants.CONSTANT_NameAndType));
                        break;
+                       
+               case Constants.CONSTANT_InvokeDynamic:
+                       ConstantInvokeDynamic cID = ((ConstantInvokeDynamic)c);
+                       return "#"+cID.getBootstrapMethodAttrIndex()+"."+constantToString(cID.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType);
+
+               case Constants.CONSTANT_MethodHandle:
+                       ConstantMethodHandle cMH = ((ConstantMethodHandle)c);
+                       return cMH.getReferenceKind()+":"+constantToString(cMH.getReferenceIndex(),Constants.CONSTANT_Methodref);
+
+               case Constants.CONSTANT_MethodType:
+                       ConstantMethodType cMT = (ConstantMethodType)c;
+                       return constantToString(cMT.getDescriptorIndex(),Constants.CONSTANT_Utf8);
+
+               case Constants.CONSTANT_Module:
+                       ConstantModule cM = (ConstantModule)c;
+                       return "Module:"+constantToString(cM.getNameIndex(),Constants.CONSTANT_Utf8);
+
+               case Constants.CONSTANT_Package:
+                       ConstantPackage cP = (ConstantPackage)c;
+                       return "Package:"+constantToString(cP.getNameIndex(),Constants.CONSTANT_Utf8);
 
                default: // Never reached
                        throw new RuntimeException("Unknown constant type " + c.tag);
@@ -254,6 +274,7 @@ public class ConstantPool implements Node {
                return constantToString(getConstant(index));
        }
 
+       @Override
        public void accept(ClassVisitor v) {
                v.visitConstantPool(this);
        }
diff --git a/bcel-builder/testdata/lambda.jar b/bcel-builder/testdata/lambda.jar
new file mode 100644 (file)
index 0000000..d470673
Binary files /dev/null and b/bcel-builder/testdata/lambda.jar differ
diff --git a/bcel-builder/testdata/lambda/cpl.sh b/bcel-builder/testdata/lambda/cpl.sh
new file mode 100755 (executable)
index 0000000..e598512
--- /dev/null
@@ -0,0 +1,8 @@
+
+# Use Java9 or later to compile this
+cd one
+javac Code.java
+
+jar -cvMf ../../lambda.jar Code.class
+rm Code.class
+cd ..
diff --git a/bcel-builder/testdata/lambda/one/Code.class b/bcel-builder/testdata/lambda/one/Code.class
new file mode 100644 (file)
index 0000000..4041bb1
Binary files /dev/null and b/bcel-builder/testdata/lambda/one/Code.class differ
diff --git a/bcel-builder/testdata/lambda/one/Code.java b/bcel-builder/testdata/lambda/one/Code.java
new file mode 100644 (file)
index 0000000..228136f
--- /dev/null
@@ -0,0 +1,7 @@
+public class Code {
+    public static void main(String[] args) {
+        Runnable r = () -> { System.out.println("hello world!"); };
+        r.run();
+    }
+
+}
index b12094ac2b31d32823b6519c1a8375ed708ea9ae..440a3ee17803615b187fff8311a93db177d47f09 100644 (file)
@@ -25,6 +25,7 @@ public class AllTests {
                suite.addTestSuite(Fundamentals.class);
                suite.addTestSuite(RuntimeVisibleParameterAnnotationAttributeTest.class);
                suite.addTestSuite(AnnotationDefaultAttributeTest.class);
+               suite.addTestSuite(ConstantPoolToStringTest.class);
                suite.addTestSuite(EnclosingMethodAttributeTest.class);
                suite.addTestSuite(MethodAnnotationsTest.class);
                suite.addTestSuite(RuntimeVisibleAnnotationAttributeTest.class);
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ConstantPoolToStringTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ConstantPoolToStringTest.java
new file mode 100644 (file)
index 0000000..3a41c6c
--- /dev/null
@@ -0,0 +1,54 @@
+/* *******************************************************************
+ * Copyright (c) 2018 Contributors
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *     Andy Clement -     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.tests;
+
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.Method;
+import org.aspectj.apache.bcel.util.SyntheticRepository;
+
+public class ConstantPoolToStringTest extends BcelTestCase {
+
+       @Override
+       protected void setUp() throws Exception {
+               super.setUp();
+       }
+
+       public void testToStringLambdaElements() throws ClassNotFoundException {
+               SyntheticRepository repos = createRepos("lambda.jar");
+               JavaClass clazz = repos.loadClass("Code");
+               ConstantPool pool = clazz.getConstantPool();
+               Method[] methods = clazz.getMethods();
+               String codeString = methods[1].getCode().getCodeString();
+               assertEquals("Code(max_stack = 1, max_locals = 2, code_length = 13)\n" + 
+                               "0:    invokedynamic    #0.run ()Ljava/lang/Runnable; (2)\n" + 
+                               "5:    astore_1\n" + 
+                               "6:    aload_1\n" + 
+                               "7:    invokeinterface  java.lang.Runnable.run ()V (3)  1       0\n" + 
+                               "12:   return\n",codeString);
+               
+               // #20 = MethodHandle       6:#32          // REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
+               String cts = pool.constantToString(pool.getConstant(20));
+               assertEquals("6:java.lang.invoke.LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;",cts);
+               
+               //              #21 = MethodType         #10            //  ()V
+               cts = pool.constantToString(pool.getConstant(21));
+               assertEquals("()V",cts);
+       }
+
+       @Override
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+
+}
diff --git a/lib/asm/asm-6.0.jar b/lib/asm/asm-6.0.jar
new file mode 100644 (file)
index 0000000..cf2de27
Binary files /dev/null and b/lib/asm/asm-6.0.jar differ
diff --git a/lib/asm/asm-6.0.renamed.jar b/lib/asm/asm-6.0.renamed.jar
new file mode 100644 (file)
index 0000000..c84e356
Binary files /dev/null and b/lib/asm/asm-6.0.renamed.jar differ
diff --git a/lib/asm/asm-6.0_ALPHA.jar b/lib/asm/asm-6.0_ALPHA.jar
deleted file mode 100644 (file)
index 72fd503..0000000
Binary files a/lib/asm/asm-6.0_ALPHA.jar and /dev/null differ
diff --git a/lib/asm/asm-6.0_ALPHA.renamed.jar b/lib/asm/asm-6.0_ALPHA.renamed.jar
deleted file mode 100644 (file)
index 1ad8b78..0000000
Binary files a/lib/asm/asm-6.0_ALPHA.renamed.jar and /dev/null differ
diff --git a/lib/asm/asm-6.0_BETA.jar b/lib/asm/asm-6.0_BETA.jar
deleted file mode 100644 (file)
index 6b2994d..0000000
Binary files a/lib/asm/asm-6.0_BETA.jar and /dev/null differ
diff --git a/lib/asm/asm-6.0_BETA.renamed.jar b/lib/asm/asm-6.0_BETA.renamed.jar
deleted file mode 100644 (file)
index 680ab77..0000000
Binary files a/lib/asm/asm-6.0_BETA.renamed.jar and /dev/null differ
index 5f9693b56b93a84f6c07cb1922d250e47f05dde9..fdd569cce80081ba729c9248c671040d37b6e7fe 100644 (file)
@@ -4,8 +4,8 @@
     <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"/>
 
        <target name="package" description="Jarjar asm-5.0.4.jar and prefix package name with aj">
-               <jarjar destfile="asm-6.0_BETA.renamed.jar">
-                 <zipfileset src="asm-6.0_BETA.jar" excludes="module-info.class"/>
+               <jarjar destfile="asm-6.0.renamed.jar">
+                 <zipfileset src="asm-6.0.jar" excludes="module-info.class"/>
                  <rule pattern="org.objectweb.asm.**" result="aj.org.objectweb.asm.@1"/>
                </jarjar>
        </target> 
diff --git a/lib/asm/readme.txt b/lib/asm/readme.txt
deleted file mode 100644 (file)
index 99c076d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-asm 2.0 is used by some tests
index e620936d06b4b964af25e59738c0ff689c8b5329..5a2fc5dc7aba9a860ef4d3c065e03ed05fc5b395 100644 (file)
Binary files a/lib/bcel/bcel-src.zip and b/lib/bcel/bcel-src.zip differ
index ed37bdfa6ccd210d7b8a04fb6c1335e43f5e4b61..f0704546c790a774fb3181f6a78460393548ca82 100644 (file)
Binary files a/lib/bcel/bcel-verifier-src.zip and b/lib/bcel/bcel-verifier-src.zip differ
index 0153468a9a135796ae142640594b1b3069ae7c35..1f9edfddcec61369ffb6b48cbd09aa72041db1ad 100644 (file)
Binary files a/lib/bcel/bcel-verifier.jar and b/lib/bcel/bcel-verifier.jar differ
index acadafd3e956b8cb4d4f7cc149e19d747feeb4fb..57f1b9c0a40c56e5eb1f8b263546ca8ae1c076bf 100644 (file)
Binary files a/lib/bcel/bcel.jar and b/lib/bcel/bcel.jar differ
index 78357b2534ae8bed0a19978ed9bd95203e1e1106..995d885a709c3b51fde32ebae204b7f8a65c62eb 100644 (file)
@@ -13,6 +13,6 @@
        <classpathentry kind="lib" path="/lib/bcel/bcel.jar" sourcepath="/lib/bcel/bcel-src.zip"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
        <classpathentry combineaccessrules="false" kind="src" path="/org.aspectj.matcher"/>
-       <classpathentry kind="lib" path="/lib/asm/asm-6.0_BETA.renamed.jar"/>
+       <classpathentry kind="lib" path="/lib/asm/asm-6.0.renamed.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>