diff options
author | Andy Clement <aclement@pivotal.io> | 2018-02-07 12:38:52 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2018-02-07 12:38:52 -0800 |
commit | 19cfe0e1caa611180f3513400c31507ad924cae6 (patch) | |
tree | 3e447fce9bab7f87a4451659b781ac6beadb8268 /bcel-builder | |
parent | 031b2ed1aae5d49a3b9a393a3d0dcc01b2bbe34a (diff) | |
download | aspectj-19cfe0e1caa611180f3513400c31507ad924cae6.tar.gz aspectj-19cfe0e1caa611180f3513400c31507ad924cae6.zip |
Add missing cases to bcel constantToString
Diffstat (limited to 'bcel-builder')
-rw-r--r-- | bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java | 21 | ||||
-rw-r--r-- | bcel-builder/testdata/lambda.jar | bin | 0 -> 663 bytes | |||
-rwxr-xr-x | bcel-builder/testdata/lambda/cpl.sh | 8 | ||||
-rw-r--r-- | bcel-builder/testdata/lambda/one/Code.class | bin | 0 -> 1001 bytes | |||
-rw-r--r-- | bcel-builder/testdata/lambda/one/Code.java | 7 | ||||
-rw-r--r-- | bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java | 1 | ||||
-rw-r--r-- | bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ConstantPoolToStringTest.java | 54 |
7 files changed, 91 insertions, 0 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java index be5b84564..0430e28ba 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java @@ -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 Binary files differnew file mode 100644 index 000000000..d470673b7 --- /dev/null +++ b/bcel-builder/testdata/lambda.jar diff --git a/bcel-builder/testdata/lambda/cpl.sh b/bcel-builder/testdata/lambda/cpl.sh new file mode 100755 index 000000000..e59851298 --- /dev/null +++ b/bcel-builder/testdata/lambda/cpl.sh @@ -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 Binary files differnew file mode 100644 index 000000000..4041bb1a7 --- /dev/null +++ b/bcel-builder/testdata/lambda/one/Code.class diff --git a/bcel-builder/testdata/lambda/one/Code.java b/bcel-builder/testdata/lambda/one/Code.java new file mode 100644 index 000000000..228136f8a --- /dev/null +++ b/bcel-builder/testdata/lambda/one/Code.java @@ -0,0 +1,7 @@ +public class Code { + public static void main(String[] args) { + Runnable r = () -> { System.out.println("hello world!"); }; + r.run(); + } + +} diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java index b12094ac2..440a3ee17 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java @@ -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 index 000000000..3a41c6c70 --- /dev/null +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ConstantPoolToStringTest.java @@ -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(); + } + +} |