summaryrefslogtreecommitdiffstats
path: root/bcel-builder/testsrc/org/aspectj/apache
diff options
context:
space:
mode:
authoraclement <aclement>2008-05-28 23:52:53 +0000
committeraclement <aclement>2008-05-28 23:52:53 +0000
commit1fe2cde76555ab272b986fc2249ab35145f87b63 (patch)
tree0738ff850d0916989291e0bf01a2041478673467 /bcel-builder/testsrc/org/aspectj/apache
parent2e138e485900fa4b2c8483f13e989f649832950d (diff)
downloadaspectj-1fe2cde76555ab272b986fc2249ab35145f87b63.tar.gz
aspectj-1fe2cde76555ab272b986fc2249ab35145f87b63.zip
231396: Comment #4: Big Refactoring
Diffstat (limited to 'bcel-builder/testsrc/org/aspectj/apache')
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java3
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationDefaultAttributeTest.java8
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java16
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/BcelTestCase.java24
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassPrinter.java21
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java34
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/FieldAnnotationsTest.java15
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/Fundamentals.java319
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GeneratingAnnotatedClassesTest.java96
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java286
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/MethodAnnotationsTest.java14
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java95
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java110
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleParameterAnnotationAttributeTest.java26
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java2
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java12
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/VarargsTest.java8
17 files changed, 832 insertions, 257 deletions
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 da406e725..cf270b5b0 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
@@ -31,8 +31,9 @@ import org.aspectj.apache.bcel.classfile.tests.VarargsTest;
public class AllTests {
public static Test suite() {
- TestSuite suite = new TestSuite("Tests for BCEL Java5 support");
+ TestSuite suite = new TestSuite("Tests for BCEL");
//$JUnit-BEGIN$
+ suite.addTestSuite(Fundamentals.class);
suite.addTestSuite(RuntimeVisibleParameterAnnotationAttributeTest.class);
suite.addTestSuite(AnnotationDefaultAttributeTest.class);
suite.addTestSuite(EnclosingMethodAttributeTest.class);
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationDefaultAttributeTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationDefaultAttributeTest.java
index ced29d489..2a57bbaac 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationDefaultAttributeTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationDefaultAttributeTest.java
@@ -15,8 +15,8 @@ package org.aspectj.apache.bcel.classfile.tests;
import org.aspectj.apache.bcel.classfile.AnnotationDefault;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
public class AnnotationDefaultAttributeTest extends BcelTestCase {
@@ -35,9 +35,9 @@ public class AnnotationDefaultAttributeTest extends BcelTestCase {
Method m = getMethod(clazz,"fruit");
AnnotationDefault a = (AnnotationDefault) findAttribute("AnnotationDefault",m.getAttributes());
- SimpleElementValue val = (SimpleElementValue) a.getElementValue();
+ SimpleElementValueGen val = (SimpleElementValueGen) a.getElementValue();
assertTrue("Should be STRING but is "+val.getElementValueType(),
- val.getElementValueType()==ElementValue.STRING);
+ val.getElementValueType()==ElementValueGen.STRING);
assertTrue("Should have default of bananas but default is "+val.getValueString(),
val.getValueString().equals("bananas"));
}
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
index c863fda83..306a1a387 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
@@ -21,16 +21,16 @@ import java.util.Vector;
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementNameValuePairGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.SimpleElementValueGen;
public class AnnotationGenTest extends BcelTestCase {
@@ -50,7 +50,7 @@ public class AnnotationGenTest extends BcelTestCase {
// Create the containing class
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
// Create the simple primitive value '4' of type 'int'
SimpleElementValueGen evg =
@@ -81,7 +81,7 @@ public class AnnotationGenTest extends BcelTestCase {
// Create the containing class
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
// Create the simple primitive value '4' of type 'int'
SimpleElementValueGen evg =
@@ -138,7 +138,7 @@ public class AnnotationGenTest extends BcelTestCase {
////
// Helper methods
- private void checkSerialize(AnnotationGen a,ConstantPoolGen cpg) {
+ private void checkSerialize(AnnotationGen a,ConstantPool cpg) {
try {
String beforeName = a.getTypeName();
List beforeValues = a.getValues();
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/BcelTestCase.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/BcelTestCase.java
index db2d1c78c..b8a0b503f 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/BcelTestCase.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/BcelTestCase.java
@@ -19,13 +19,12 @@ import java.util.List;
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementNameValuePairGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.util.ClassPath;
import org.aspectj.apache.bcel.util.SyntheticRepository;
@@ -100,17 +99,6 @@ public class BcelTestCase extends TestCase {
return (Attribute)chosenAttrsList.get(0);
}
- protected String dumpAnnotations(Annotation[] as) {
- StringBuffer result = new StringBuffer();
- result.append("[");
- for (int i = 0; i < as.length; i++) {
- Annotation annotation = as[i];
- result.append(annotation.toShortString());
- if (i+1<as.length) result.append(",");
- }
- result.append("]");
- return result.toString();
- }
protected String dumpAnnotations(AnnotationGen[] as) {
StringBuffer result = new StringBuffer();
@@ -136,7 +124,7 @@ public class BcelTestCase extends TestCase {
return result.toString();
}
- public AnnotationGen createFruitAnnotation(ConstantPoolGen cp, String aFruit, boolean visibility) {
+ public AnnotationGen createFruitAnnotation(ConstantPool cp, String aFruit, boolean visibility) {
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.STRING,cp,aFruit);
ElementNameValuePairGen nvGen = new ElementNameValuePairGen("fruit",evg,cp);
ObjectType t = new ObjectType("SimpleStringAnnotation");
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassPrinter.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassPrinter.java
deleted file mode 100644
index 2efd1ae44..000000000
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ClassPrinter.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.aspectj.apache.bcel.classfile.tests;
-
-import java.io.File;
-
-import org.aspectj.apache.bcel.classfile.JavaClass;
-import org.aspectj.apache.bcel.util.ClassPath;
-import org.aspectj.apache.bcel.util.SyntheticRepository;
-
-public class ClassPrinter extends BcelTestCase {
-
- public static void main(String[] args) throws ClassNotFoundException {
- new ClassPrinter().run(args);
- }
-
- public void run(String[] args) throws ClassNotFoundException {
- ClassPath cp = new ClassPath(args[0]+File.pathSeparator+System.getProperty("java.class.path"));
- SyntheticRepository sr = SyntheticRepository.getInstance(cp);
- JavaClass clazz = sr.loadClass(args[1]);
- System.err.println(clazz.toString());
- }
-}
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java
index fa0f437e2..8fc5207bd 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java
@@ -17,12 +17,12 @@ import java.io.IOException;
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.ClassElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.EnumElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.annotation.ClassElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.EnumElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.SimpleElementValueGen;
public class ElementValueGenTest extends BcelTestCase {
@@ -40,7 +40,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateIntegerElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_INT,cp,555);
// Creation of an element like that should leave a new entry in the cpool
@@ -51,7 +51,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateFloatElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_FLOAT,cp,111.222f);
// Creation of an element like that should leave a new entry in the cpool
@@ -62,7 +62,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateDoubleElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_DOUBLE,cp,333.44);
// Creation of an element like that should leave a new entry in the cpool
@@ -74,7 +74,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateLongElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_LONG,cp,3334455L);
// Creation of an element like that should leave a new entry in the cpool
@@ -86,7 +86,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateCharElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_CHAR,cp,(char)'t');
// Creation of an element like that should leave a new entry in the cpool
@@ -98,7 +98,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateByteElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_CHAR,cp,(byte)'z');
// Creation of an element like that should leave a new entry in the cpool
@@ -110,7 +110,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateBooleanElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_BOOLEAN,cp,true);
// Creation of an element like that should leave a new entry in the cpool
@@ -122,7 +122,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateShortElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_SHORT,cp,(short)42);
// Creation of an element like that should leave a new entry in the cpool
@@ -139,7 +139,7 @@ public class ElementValueGenTest extends BcelTestCase {
// Create HelloWorld
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.STRING,cp,"hello");
// Creation of an element like that should leave a new entry in the cpool
@@ -153,7 +153,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateEnumElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
ObjectType enumType = new ObjectType("SimpleEnum"); // Supports rainbow :)
@@ -176,7 +176,7 @@ public class ElementValueGenTest extends BcelTestCase {
public void testCreateClassElementValue() {
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
ObjectType classType = new ObjectType("java.lang.Integer");
@@ -192,7 +192,7 @@ public class ElementValueGenTest extends BcelTestCase {
////
// Helper methods
- private void checkSerialize(ElementValueGen evgBefore,ConstantPoolGen cpg) {
+ private void checkSerialize(ElementValueGen evgBefore,ConstantPool cpg) {
try {
String beforeValue = evgBefore.stringifyValue();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/FieldAnnotationsTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/FieldAnnotationsTest.java
index b62e5d88f..0bcf1ac81 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/FieldAnnotationsTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/FieldAnnotationsTest.java
@@ -18,11 +18,10 @@ import java.util.Iterator;
import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.classfile.JavaClass;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
import org.aspectj.apache.bcel.generic.ClassGen;
import org.aspectj.apache.bcel.generic.FieldGen;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
import org.aspectj.apache.bcel.util.SyntheticRepository;
@@ -105,7 +104,7 @@ public class FieldAnnotationsTest extends BcelTestCase {
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
- Annotation[] fieldAnnotations = f.getAnnotations();
+ AnnotationGen[] fieldAnnotations = f.getAnnotations();
if (f.getName().equals(fieldname)) {
checkAnnotation(fieldAnnotations[0],annotationName,annotationElementName,annotationElementValue);
@@ -113,11 +112,11 @@ public class FieldAnnotationsTest extends BcelTestCase {
}
}
- private void checkAnnotation(Annotation a,String name,String elementname,String elementvalue) {
+ private void checkAnnotation(AnnotationGen a,String name,String elementname,String elementvalue) {
assertTrue("Expected annotation to have name "+name+" but it had name "+a.getTypeName(),
a.getTypeName().equals(name));
assertTrue("Expected annotation to have one element but it had "+a.getValues().size(),a.getValues().size()==1);
- ElementNameValuePair envp = (ElementNameValuePair)a.getValues().get(0);
+ ElementNameValuePairGen envp = (ElementNameValuePairGen)a.getValues().get(0);
assertTrue("Expected element name "+elementname+" but was "+envp.getNameString(),
elementname.equals(envp.getNameString()));
assertTrue("Expected element value "+elementvalue+" but was "+envp.getValue().stringifyValue(),
@@ -127,9 +126,9 @@ public class FieldAnnotationsTest extends BcelTestCase {
// helper methods
- public void checkValue(Annotation a,String name,String tostring) {
+ public void checkValue(AnnotationGen a,String name,String tostring) {
for (Iterator i = a.getValues().iterator(); i.hasNext();) {
- ElementNameValuePair element = (ElementNameValuePair) i.next();
+ ElementNameValuePairGen element = (ElementNameValuePairGen) i.next();
if (element.getNameString().equals(name)) {
if (!element.getValue().stringifyValue().equals(tostring)) {
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue());
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/Fundamentals.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/Fundamentals.java
new file mode 100644
index 000000000..c54beb5b3
--- /dev/null
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/Fundamentals.java
@@ -0,0 +1,319 @@
+package org.aspectj.apache.bcel.classfile.tests;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.generic.FieldInstruction;
+import org.aspectj.apache.bcel.generic.IINC;
+import org.aspectj.apache.bcel.generic.INVOKEINTERFACE;
+import org.aspectj.apache.bcel.generic.Instruction;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
+import org.aspectj.apache.bcel.generic.InstructionByte;
+import org.aspectj.apache.bcel.generic.InstructionCP;
+import org.aspectj.apache.bcel.generic.InstructionConstants;
+import org.aspectj.apache.bcel.generic.InstructionHandle;
+import org.aspectj.apache.bcel.generic.InstructionLV;
+import org.aspectj.apache.bcel.generic.InstructionShort;
+import org.aspectj.apache.bcel.generic.InvokeInstruction;
+import org.aspectj.apache.bcel.generic.LOOKUPSWITCH;
+import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
+import org.aspectj.apache.bcel.generic.RET;
+import org.aspectj.apache.bcel.generic.TABLESWITCH;
+
+import junit.framework.TestCase;
+
+// Check things that have to be true based on the specification
+public class Fundamentals extends TestCase {
+
+ // Checking: opcode, length, consumed stack entries, produced stack entries
+ public void testInstructions() {
+
+ // Instructions 000-009
+ checkInstruction(InstructionConstants.NOP,0,1,0,0);
+ checkInstruction(InstructionConstants.ACONST_NULL,1,1,0,1);
+ checkInstruction(InstructionConstants.ICONST_M1,2,1,0,1);
+ checkInstruction(InstructionConstants.ICONST_0,3,1,0,1);
+ checkInstruction(InstructionConstants.ICONST_1,4,1,0,1);
+ checkInstruction(InstructionConstants.ICONST_2,5,1,0,1);
+ checkInstruction(InstructionConstants.ICONST_3,6,1,0,1);
+ checkInstruction(InstructionConstants.ICONST_4,7,1,0,1);
+ checkInstruction(InstructionConstants.ICONST_5,8,1,0,1);
+ checkInstruction(InstructionConstants.LCONST_0,9,1,0,2);
+
+ // Instructions 010-019
+ checkInstruction(InstructionConstants.LCONST_1,10,1,0,2);
+ checkInstruction(InstructionConstants.FCONST_0,11,1,0,1);
+ checkInstruction(InstructionConstants.FCONST_1,12,1,0,1);
+ checkInstruction(InstructionConstants.FCONST_2,13,1,0,1);
+ checkInstruction(InstructionConstants.DCONST_0,14,1,0,2);
+ checkInstruction(InstructionConstants.DCONST_1,15,1,0,2);
+ checkInstruction(new InstructionByte(Constants.BIPUSH,b0),16,2,0,1);
+ checkInstruction(new InstructionShort(Constants.SIPUSH,s0),17,3,0,1);
+ checkInstruction(new InstructionCP(Constants.LDC,b0),18,2,0,1);
+ checkInstruction(new InstructionCP(Constants.LDC_W,s0),19,2,0,1);
+
+ // Instructions 020-029
+ checkInstruction(new InstructionCP(Constants.LDC2_W,s0),20,3,0,2);
+ checkInstruction(new InstructionLV(Constants.ILOAD,s20),21,2,0,1);
+ checkInstruction(new InstructionLV(Constants.LLOAD,s20),22,2,0,2);
+ checkInstruction(new InstructionLV(Constants.FLOAD,s20),23,2,0,1);
+ checkInstruction(new InstructionLV(Constants.DLOAD,s20),24,2,0,2);
+ checkInstruction(new InstructionLV(Constants.ALOAD,s20),25,2,0,1);
+ checkInstruction(InstructionConstants.ILOAD_0,26,1,0,1);
+ checkInstruction(InstructionConstants.ILOAD_1,27,1,0,1);
+ checkInstruction(InstructionConstants.ILOAD_2,28,1,0,1);
+ checkInstruction(InstructionConstants.ILOAD_3,29,1,0,1);
+
+ // Instructions 030-039
+ checkInstruction(InstructionConstants.LLOAD_0,30,1,0,2);
+ checkInstruction(InstructionConstants.LLOAD_1,31,1,0,2);
+ checkInstruction(InstructionConstants.LLOAD_2,32,1,0,2);
+ checkInstruction(InstructionConstants.LLOAD_3,33,1,0,2);
+ checkInstruction(InstructionConstants.FLOAD_0,34,1,0,1);
+ checkInstruction(InstructionConstants.FLOAD_1,35,1,0,1);
+ checkInstruction(InstructionConstants.FLOAD_2,36,1,0,1);
+ checkInstruction(InstructionConstants.FLOAD_3,37,1,0,1);
+ checkInstruction(InstructionConstants.DLOAD_0,38,1,0,2);
+ checkInstruction(InstructionConstants.DLOAD_1,39,1,0,2);
+
+ // Instructions 040-049
+ checkInstruction(InstructionConstants.DLOAD_2,40,1,0,2);
+ checkInstruction(InstructionConstants.DLOAD_3,41,1,0,2);
+ checkInstruction(InstructionConstants.ALOAD_0,42,1,0,1);
+ checkInstruction(InstructionConstants.ALOAD_1,43,1,0,1);
+ checkInstruction(InstructionConstants.ALOAD_2,44,1,0,1);
+ checkInstruction(InstructionConstants.ALOAD_3,45,1,0,1);
+ checkInstruction(InstructionConstants.IALOAD,46,1,2,1);
+ checkInstruction(InstructionConstants.LALOAD,47,1,2,2);
+ checkInstruction(InstructionConstants.FALOAD,48,1,2,1);
+ checkInstruction(InstructionConstants.DALOAD,49,1,2,2);
+
+ // Instructions 050-059
+ checkInstruction(InstructionConstants.AALOAD,50,1,2,1);
+ checkInstruction(InstructionConstants.BALOAD,51,1,2,1);
+ checkInstruction(InstructionConstants.CALOAD,52,1,2,1);
+ checkInstruction(InstructionConstants.SALOAD,53,1,2,1);
+ checkInstruction(new InstructionLV(Constants.ISTORE,s20),54,2,1,0);
+ checkInstruction(new InstructionLV(Constants.LSTORE,s20),55,2,2,0);
+ checkInstruction(new InstructionLV(Constants.FSTORE,s20),56,2,1,0);
+ checkInstruction(new InstructionLV(Constants.DSTORE,s20),57,2,2,0);
+ checkInstruction(new InstructionLV(Constants.ASTORE,s20),58,2,1,0);
+ checkInstruction(InstructionConstants.ISTORE_0,59,1,1,0);
+
+ // Instructions 060-069
+ checkInstruction(InstructionConstants.ISTORE_1,60,1,1,0);
+ checkInstruction(InstructionConstants.ISTORE_2,61,1,1,0);
+ checkInstruction(InstructionConstants.ISTORE_3,62,1,1,0);
+ checkInstruction(InstructionConstants.LSTORE_0,63,1,2,0);
+ checkInstruction(InstructionConstants.LSTORE_1,64,1,2,0);
+ checkInstruction(InstructionConstants.LSTORE_2,65,1,2,0);
+ checkInstruction(InstructionConstants.LSTORE_3,66,1,2,0);
+ checkInstruction(InstructionConstants.FSTORE_0,67,1,1,0);
+ checkInstruction(InstructionConstants.FSTORE_1,68,1,1,0);
+ checkInstruction(InstructionConstants.FSTORE_2,69,1,1,0);
+
+ // Instructions 070-079
+ checkInstruction(InstructionConstants.FSTORE_3,70,1,1,0);
+ checkInstruction(InstructionConstants.DSTORE_0,71,1,2,0);
+ checkInstruction(InstructionConstants.DSTORE_1,72,1,2,0);
+ checkInstruction(InstructionConstants.DSTORE_2,73,1,2,0);
+ checkInstruction(InstructionConstants.DSTORE_3,74,1,2,0);
+ checkInstruction(InstructionConstants.ASTORE_0,75,1,1,0);
+ checkInstruction(InstructionConstants.ASTORE_1,76,1,1,0);
+ checkInstruction(InstructionConstants.ASTORE_2,77,1,1,0);
+ checkInstruction(InstructionConstants.ASTORE_3,78,1,1,0);
+ checkInstruction(InstructionConstants.IASTORE,79,1,3,0);
+
+ // Instructions 080-089
+ checkInstruction(InstructionConstants.LASTORE,80,1,4,0);
+ checkInstruction(InstructionConstants.FASTORE,81,1,3,0);
+ checkInstruction(InstructionConstants.DASTORE,82,1,4,0);
+ checkInstruction(InstructionConstants.AASTORE,83,1,3,0);
+ checkInstruction(InstructionConstants.BASTORE,84,1,3,0);
+ checkInstruction(InstructionConstants.CASTORE,85,1,3,0);
+ checkInstruction(InstructionConstants.SASTORE,86,1,3,0);
+ checkInstruction(InstructionConstants.POP,87,1,1,0);
+ checkInstruction(InstructionConstants.POP2,88,1,2,0);
+ checkInstruction(InstructionConstants.DUP,89,1,1,2);
+
+ // Instructions 090-099
+ checkInstruction(InstructionConstants.DUP_X1,90,1,2,3);
+ checkInstruction(InstructionConstants.DUP_X2,91,1,3,4);
+ checkInstruction(InstructionConstants.DUP2,92,1,2,4);
+ checkInstruction(InstructionConstants.DUP2_X1,93,1,3,5);
+ checkInstruction(InstructionConstants.DUP2_X2,94,1,4,6);
+ checkInstruction(InstructionConstants.SWAP,95,1,2,2);
+ checkInstruction(InstructionConstants.IADD,96,1,2,1);
+ checkInstruction(InstructionConstants.LADD,97,1,4,2);
+ checkInstruction(InstructionConstants.FADD,98,1,2,1);
+ checkInstruction(InstructionConstants.DADD,99,1,4,2);
+
+ // Instructions 100-109
+ checkInstruction(InstructionConstants.ISUB,100,1,2,1);
+ checkInstruction(InstructionConstants.LSUB,101,1,4,2);
+ checkInstruction(InstructionConstants.FSUB,102,1,2,1);
+ checkInstruction(InstructionConstants.DSUB,103,1,4,2);
+ checkInstruction(InstructionConstants.IMUL,104,1,2,1);
+ checkInstruction(InstructionConstants.LMUL,105,1,4,2);
+ checkInstruction(InstructionConstants.FMUL,106,1,2,1);
+ checkInstruction(InstructionConstants.DMUL,107,1,4,2);
+ checkInstruction(InstructionConstants.IDIV,108,1,2,1);
+ checkInstruction(InstructionConstants.LDIV,109,1,4,2);
+
+ // Instructions 110-119
+ checkInstruction(InstructionConstants.FDIV,110,1,2,1);
+ checkInstruction(InstructionConstants.DDIV,111,1,4,2);
+ checkInstruction(InstructionConstants.IREM,112,1,2,1);
+ checkInstruction(InstructionConstants.LREM,113,1,4,2);
+ checkInstruction(InstructionConstants.FREM,114,1,2,1);
+ checkInstruction(InstructionConstants.DREM,115,1,4,2);
+ checkInstruction(InstructionConstants.INEG,116,1,1,1);
+ checkInstruction(InstructionConstants.LNEG,117,1,2,2);
+ checkInstruction(InstructionConstants.FNEG,118,1,1,1);
+ checkInstruction(InstructionConstants.DNEG,119,1,2,2);
+
+ // Instructions 120-129
+ checkInstruction(InstructionConstants.ISHL,120,1,2,1);
+ checkInstruction(InstructionConstants.LSHL,121,1,3,2);
+ checkInstruction(InstructionConstants.ISHR,122,1,2,1);
+ checkInstruction(InstructionConstants.LSHR,123,1,3,2);
+ checkInstruction(InstructionConstants.IUSHR,124,1,2,1);
+ checkInstruction(InstructionConstants.LUSHR,125,1,3,2);
+ checkInstruction(InstructionConstants.IAND,126,1,2,1);
+ checkInstruction(InstructionConstants.LAND,127,1,4,2);
+ checkInstruction(InstructionConstants.IOR,128,1,2,1);
+ checkInstruction(InstructionConstants.LOR,129,1,4,2);
+
+ // Instructions 130-139
+ checkInstruction(InstructionConstants.IXOR,130,1,2,1);
+ checkInstruction(InstructionConstants.LXOR,131,1,4,2);
+ checkInstruction(new IINC(0,0,false),132,3,0,0);
+ checkInstruction(InstructionConstants.I2L,133,1,1,2);
+ checkInstruction(InstructionConstants.I2F,134,1,1,1);
+ checkInstruction(InstructionConstants.I2D,135,1,1,2);
+ checkInstruction(InstructionConstants.L2I,136,1,2,1);
+ checkInstruction(InstructionConstants.L2F,137,1,2,1);
+ checkInstruction(InstructionConstants.L2D,138,1,2,2);
+ checkInstruction(InstructionConstants.F2I,139,1,1,1);
+
+ // Instructions 140-149
+ checkInstruction(InstructionConstants.F2L,140,1,1,2);
+ checkInstruction(InstructionConstants.F2D,141,1,1,2);
+ checkInstruction(InstructionConstants.D2I,142,1,2,1);
+ checkInstruction(InstructionConstants.D2L,143,1,2,2);
+ checkInstruction(InstructionConstants.D2F,144,1,2,1);
+ checkInstruction(InstructionConstants.I2B,145,1,1,1);
+ checkInstruction(InstructionConstants.I2C,146,1,1,1);
+ checkInstruction(InstructionConstants.I2S,147,1,1,1);
+ checkInstruction(InstructionConstants.LCMP,148,1,4,1);
+ checkInstruction(InstructionConstants.FCMPL,149,1,2,1);
+
+ // Instructions 150-159
+ checkInstruction(InstructionConstants.FCMPG,150,1,2,1);
+ checkInstruction(InstructionConstants.DCMPL,151,1,4,1);
+ checkInstruction(InstructionConstants.DCMPG,152,1,4,1);
+ checkInstruction(new InstructionBranch(Constants.IFEQ,s0),153,3,1,0);
+ checkInstruction(new InstructionBranch(Constants.IFNE,s0),154,3,1,0);
+ checkInstruction(new InstructionBranch(Constants.IFLT,s0),155,3,1,0);
+ checkInstruction(new InstructionBranch(Constants.IFGE,s0),156,3,1,0);
+ checkInstruction(new InstructionBranch(Constants.IFGT,s0),157,3,1,0);
+ checkInstruction(new InstructionBranch(Constants.IFLE,s0),158,3,1,0);
+ checkInstruction(new InstructionBranch(Constants.IF_ICMPEQ,s0),159,3,2,0);
+
+ // Instructions 160-169
+ checkInstruction(new InstructionBranch(Constants.IF_ICMPNE,s0),160,3,2,0);
+ checkInstruction(new InstructionBranch(Constants.IF_ICMPLT,s0),161,3,2,0);
+ checkInstruction(new InstructionBranch(Constants.IF_ICMPGE,s0),162,3,2,0);
+ checkInstruction(new InstructionBranch(Constants.IF_ICMPGT,s0),163,3,2,0);
+ checkInstruction(new InstructionBranch(Constants.IF_ICMPLE,s0),164,3,2,0);
+ checkInstruction(new InstructionBranch(Constants.IF_ACMPEQ,s0),165,3,2,0);
+ checkInstruction(new InstructionBranch(Constants.IF_ACMPNE,s0),166,3,2,0);
+ checkInstruction(new InstructionBranch(Constants.GOTO,s0),167,3,0,0);
+ checkInstruction(new InstructionBranch(Constants.JSR,s0),168,3,0,1);
+ checkInstruction(new RET(0,false),169,2,0,0);
+
+ // Instructions 170-179
+ checkInstruction(new TABLESWITCH(new int[]{},new InstructionHandle[]{},null),170,VARIES,1,0);
+ checkInstruction(new LOOKUPSWITCH(new int[]{},new InstructionHandle[]{},null),171,VARIES,1,0);
+ checkInstruction(InstructionConstants.IRETURN,172,1,1,0);
+ checkInstruction(InstructionConstants.LRETURN,173,1,2,0);
+ checkInstruction(InstructionConstants.FRETURN,174,1,1,0);
+ checkInstruction(InstructionConstants.DRETURN,175,1,2,0);
+ checkInstruction(InstructionConstants.ARETURN,176,1,1,0);
+ checkInstruction(InstructionConstants.RETURN,177,1,0,0);
+ checkInstruction(new FieldInstruction(Constants.GETSTATIC,0),178,3,0,VARIES);
+ checkInstruction(new FieldInstruction(Constants.PUTSTATIC,0),179,3,VARIES,0);
+
+ // Instructions 180-189
+ checkInstruction(new FieldInstruction(Constants.GETFIELD,0),180,3,1,VARIES);
+ checkInstruction(new FieldInstruction(Constants.PUTFIELD,0),181,3,VARIES,0);
+ checkInstruction(new InvokeInstruction(Constants.INVOKEVIRTUAL,0),182,3,VARIES,VARIES); // PRODUCE STACK VARIES OK HERE? (AND NEXT COUPLE)
+ checkInstruction(new InvokeInstruction(Constants.INVOKESPECIAL,0),183,3,VARIES,VARIES);
+ checkInstruction(new InvokeInstruction(Constants.INVOKESTATIC,0),184,3,VARIES,VARIES);
+ checkInstruction(new INVOKEINTERFACE(0,1,0),185,5,VARIES,VARIES);
+ // 186 does not exist
+ checkInstruction(new InstructionCP(Constants.NEW,b0),187,3,0,1);
+ checkInstruction(new InstructionByte(Constants.NEWARRAY,b0),188,2,1,1);
+ checkInstruction(new InstructionCP(Constants.ANEWARRAY,0),189,3,1,1);
+
+ // Instructions 190-199
+ checkInstruction(InstructionConstants.ARRAYLENGTH,190,1,1,1);
+ checkInstruction(InstructionConstants.ATHROW,191,1,1,1);
+ checkInstruction(new InstructionCP(Constants.CHECKCAST,s0),192,3,1,1);
+ checkInstruction(new InstructionCP(Constants.INSTANCEOF,s0),193,3,1,1);
+ checkInstruction(InstructionConstants.MONITORENTER,194,1,1,0);
+ checkInstruction(InstructionConstants.MONITOREXIT,195,1,1,0);
+ // 196 is 'wide' tag
+ checkInstruction(new MULTIANEWARRAY(s0,b0),197,4,VARIES,1);
+ checkInstruction(new InstructionBranch(Constants.IFNULL,s0),198,3,1,0);
+ checkInstruction(new InstructionBranch(Constants.IFNONNULL,s0),199,3,1,0);
+
+ // Instructions 200-209
+ checkInstruction(new InstructionBranch(Constants.GOTO_W,0),200,5,0,0);
+ checkInstruction(new InstructionBranch(Constants.JSR_W,0),201,5,0,1);
+
+ // Internally used instructions skipped
+ }
+
+ public void checkInstruction(Instruction i,int opcode, int length, int stackConsumed, int stackProduced) {
+ String header = new String("Checking instruction '"+i+"' ");
+ if (i.opcode!=opcode)
+ fail(header+" expected opcode "+opcode+" but it is "+i.opcode);
+
+ if (length!=VARIES && i.getLength()!=length)
+ fail(header+" expected length "+length+" but it is "+i.getLength());
+// if (stackConsumed>0) {
+// if ((Constants.instFlags[opcode]&Constants.STACK_CONSUMER)==0)
+// fail(header+" expected it to be a STACK_CONSUMER but it is not");
+// } else {
+// if ((Constants.instFlags[opcode]&Constants.STACK_CONSUMER)!=0)
+// fail(header+" expected it not to be a STACK_CONSUMER but it is");
+// }
+ if (stackConsumed==VARIES) {
+ if (Constants.CONSUME_STACK[opcode]!=Constants.UNPREDICTABLE)
+ fail("Instruction '"+i+"' should be consuming some unpredictable number of stack entries but it says it will consume "+Constants.CONSUME_STACK[opcode]);
+
+ } else {
+ if (Constants.CONSUME_STACK[opcode]!=stackConsumed)
+ fail("Instruction '"+i+"' should be consuming "+stackConsumed+" stack entries but it says it will consume "+Constants.CONSUME_STACK[opcode]);
+ }
+// if (stackProduced>0) {
+// if ((Constants.instFlags[opcode]&Constants.STACK_PRODUCER)==0)
+// fail(header+" expected it to be a STACK_PRODUCER but it is not");
+// } else {
+// if ((Constants.instFlags[opcode]&Constants.STACK_PRODUCER)!=0)
+// fail(header+" expected it not to be a STACK_PRODUCER but it is");
+// }
+ if (stackProduced==VARIES) {
+ if (Constants.stackEntriesProduced[opcode]!=Constants.UNPREDICTABLE)
+ fail(header+" should be producing some unpredictable number of stack entries but it says it will produce "+Constants.stackEntriesProduced[opcode]);
+
+ } else {
+ if (Constants.stackEntriesProduced[opcode]!=stackProduced)
+ fail(header+" should be producing "+stackProduced+" stack entries but it says it will produce "+Constants.stackEntriesProduced[opcode]);
+ }
+ }
+
+ private final static byte b0 = 0;
+ private final static short s0 = 0;
+ private final static short s20 = 20;
+ private final static int VARIES = -1;
+}
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GeneratingAnnotatedClassesTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GeneratingAnnotatedClassesTest.java
index 6c0258beb..6306c3edc 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GeneratingAnnotatedClassesTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GeneratingAnnotatedClassesTest.java
@@ -17,15 +17,16 @@ import java.util.List;
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
-import org.aspectj.apache.bcel.generic.ALOAD;
-import org.aspectj.apache.bcel.generic.ASTORE;
import org.aspectj.apache.bcel.generic.ArrayType;
import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
-import org.aspectj.apache.bcel.generic.GOTO;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
@@ -33,14 +34,7 @@ import org.aspectj.apache.bcel.generic.InstructionList;
import org.aspectj.apache.bcel.generic.LocalVariableGen;
import org.aspectj.apache.bcel.generic.MethodGen;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUSH;
import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.generic.annotation.ArrayElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementNameValuePairGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.util.SyntheticRepository;
/**
@@ -76,7 +70,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
// Create HelloWorld
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
InstructionList il = new InstructionList();
cg.addAnnotation(createSimpleVisibleAnnotation(cp));
@@ -88,21 +82,21 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
JavaClass jc = getClassFrom(".","HelloWorld");
- Annotation[] as = jc.getAnnotations();
+ AnnotationGen[] as = jc.getAnnotations();
assertTrue("Should be two annotations but found "+as.length,as.length==2);
- Annotation one = as[0];
- Annotation two = as[1];
+ AnnotationGen one = as[0];
+ AnnotationGen two = as[1];
assertTrue("Name of annotation 1 should be SimpleAnnotation but it is "+as[0].getTypeName(),
as[0].getTypeName().equals("SimpleAnnotation"));
assertTrue("Name of annotation 2 should be SimpleAnnotation but it is "+as[1].getTypeName(),
as[1].getTypeName().equals("SimpleAnnotation"));
List vals = as[0].getValues();
- ElementNameValuePair nvp = (ElementNameValuePair) vals.get(0);
+ ElementNameValuePairGen nvp = (ElementNameValuePairGen) vals.get(0);
assertTrue("Name of element in SimpleAnnotation should be 'id' but it is "+
nvp.getNameString(),nvp.getNameString().equals("id"));
- ElementValue ev = nvp.getValue();
+ ElementValueGen ev = nvp.getValue();
assertTrue("Type of element value should be int but it is "+ev.getElementValueType(),
- ev.getElementValueType()==ElementValue.PRIMITIVE_INT);
+ ev.getElementValueType()==ElementValueGen.PRIMITIVE_INT);
assertTrue("Value of element should be 4 but it is "+ev.stringifyValue(),
ev.stringifyValue().equals("4"));
assertTrue(createTestdataFile("HelloWorld.class").delete());
@@ -117,7 +111,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
public void testGenerateMethodLevelAnnotations1() throws ClassNotFoundException {
// Create HelloWorld
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
InstructionList il = new InstructionList();
buildClassContentsWithAnnotatedMethods(cg, cp, il);
@@ -158,7 +152,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
public void testGenerateMethodLevelAnnotations2() throws ClassNotFoundException {
// Create HelloWorld
ClassGen cg = createClassGen("HelloWorld");
- ConstantPoolGen cp = cg.getConstantPool();
+ ConstantPool cp = cg.getConstantPool();
InstructionList il = new InstructionList();
buildClassContentsWithAnnotatedMethods(cg, cp, il);
@@ -247,9 +241,9 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
ElementValueGen value = (ElementValueGen)nvp.getValue();
assertTrue("Value should be ArrayElementValueGen but is "+value,value instanceof ArrayElementValueGen);
ArrayElementValueGen arrayValue = (ArrayElementValueGen)value;
- assertTrue("Array value should be size one but is "+arrayValue.getElementValuesSize(),
- arrayValue.getElementValuesSize()==1);
- ElementValueGen innerValue = (ElementValueGen)arrayValue.getElementValues().get(0);
+ assertTrue("Array value should be size one but is "+arrayValue.getElementValuesArraySize(),
+ arrayValue.getElementValuesArraySize()==1);
+ ElementValueGen innerValue = (ElementValueGen)arrayValue.getElementValuesArray()[0];
assertTrue("Value in the array should be AnnotationElementValueGen but is "+innerValue,
innerValue instanceof AnnotationElementValueGen);
AnnotationElementValueGen innerAnnotationValue = (AnnotationElementValueGen)innerValue;
@@ -287,7 +281,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
public void testModifyingClasses1() throws ClassNotFoundException {
JavaClass jc = getClassFrom("testcode.jar","SimpleAnnotatedClass");
ClassGen cgen = new ClassGen(jc);
- ConstantPoolGen cp = cgen.getConstantPool();
+ ConstantPool cp = cgen.getConstantPool();
cgen.addAnnotation(createFruitAnnotation(cp,"Pineapple"));
assertTrue("Should now have two annotations but has "+cgen.getAnnotations().length,
cgen.getAnnotations().length==2);
@@ -301,7 +295,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
public void testModifyingClasses2() throws ClassNotFoundException {
JavaClass jc = getClassFrom("testcode.jar","SimpleAnnotatedClass");
ClassGen cgen = new ClassGen(jc);
- ConstantPoolGen cp = cgen.getConstantPool();
+ ConstantPool cp = cgen.getConstantPool();
cgen.addAnnotation(createCombinedAnnotation(cp));
assertTrue("Should now have two annotations but has "+cgen.getAnnotations().length,
cgen.getAnnotations().length==2);
@@ -327,7 +321,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
dumpClass(cg,dir+File.separator+fname);
}
- private void buildClassContentsWithAnnotatedMethods(ClassGen cg, ConstantPoolGen cp, InstructionList il) {
+ private void buildClassContentsWithAnnotatedMethods(ClassGen cg, ConstantPool cp, InstructionList il) {
// Create method 'public static void main(String[]argv)'
MethodGen mg = createMethodGen("main",il,cp);
InstructionFactory factory = new InstructionFactory(cg);
@@ -356,14 +350,14 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
LocalVariableGen lg = mg.addLocalVariable("in", new ObjectType(
"java.io.BufferedReader"), null, null);
int in = lg.getIndex();
- lg.setStart(il.append(new ASTORE(in))); // "in" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(in))); // "in" valid from here
// Create local variable name and initialize it to null
lg = mg.addLocalVariable("name", Type.STRING, null, null);
int name = lg.getIndex();
il.append(InstructionConstants.ACONST_NULL);
- lg.setStart(il.append(new ASTORE(name))); // "name" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(name))); // "name" valid from here
// Create try-catch block: We remember the start of the block, read a
// line from the standard input and store it into the variable name .
@@ -378,13 +372,13 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
// il.append(new ALOAD(in));
// il.append(factory.createInvoke("java.io.BufferedReader", "readLine",
// Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
- InstructionHandle try_start = il.append(new PUSH(cp,"Andy"));
- il.append(new ASTORE(name));
+ InstructionHandle try_start = il.append(InstructionFactory.PUSH(cp,"Andy"));
+ il.append(InstructionFactory.createASTORE(name));
// Upon normal execution we jump behind exception handler, the target
// address is not known yet.
- GOTO g = new GOTO(null);
+ InstructionBranch g = new InstructionBranch(Constants.GOTO);
InstructionHandle try_end = il.append(g);
// We add the exception handler which simply returns from the method.
@@ -392,7 +386,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
LocalVariableGen var_ex = mg.addLocalVariable("ex",Type.getType("Ljava.io.IOException;"),null,null);
int var_ex_slot = var_ex.getIndex();
- InstructionHandle handler = il.append(new ASTORE(var_ex_slot));
+ InstructionHandle handler = il.append(InstructionFactory.createASTORE(var_ex_slot));
var_ex.setStart(handler);
var_ex.setEnd(il.append(InstructionConstants.RETURN));
@@ -411,12 +405,12 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
il.append(factory.createNew(Type.STRINGBUFFER));
il.append(InstructionConstants.DUP);
- il.append(new PUSH(cp, "Hello, "));
+ il.append(InstructionFactory.PUSH(cp, "Hello, "));
il
.append(factory.createInvoke("java.lang.StringBuffer",
"<init>", Type.VOID, new Type[] { Type.STRING },
Constants.INVOKESPECIAL));
- il.append(new ALOAD(name));
+ il.append(InstructionFactory.createALOAD(name));
il.append(factory.createInvoke("java.lang.StringBuffer", "append",
Type.STRINGBUFFER, new Type[] { Type.STRING },
Constants.INVOKEVIRTUAL));
@@ -439,7 +433,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
cg.addEmptyConstructor(Constants.ACC_PUBLIC);
}
- private void buildClassContents(ClassGen cg, ConstantPoolGen cp, InstructionList il) {
+ private void buildClassContents(ClassGen cg, ConstantPool cp, InstructionList il) {
// Create method 'public static void main(String[]argv)'
MethodGen mg = createMethodGen("main",il,cp);
InstructionFactory factory = new InstructionFactory(cg);
@@ -467,14 +461,14 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
LocalVariableGen lg = mg.addLocalVariable("in", new ObjectType(
"java.io.BufferedReader"), null, null);
int in = lg.getIndex();
- lg.setStart(il.append(new ASTORE(in))); // "in" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(in))); // "in" valid from here
// Create local variable name and initialize it to null
lg = mg.addLocalVariable("name", Type.STRING, null, null);
int name = lg.getIndex();
il.append(InstructionConstants.ACONST_NULL);
- lg.setStart(il.append(new ASTORE(name))); // "name" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(name))); // "name" valid from here
// Create try-catch block: We remember the start of the block, read a
// line from the standard input and store it into the variable name .
@@ -489,13 +483,13 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
// il.append(new ALOAD(in));
// il.append(factory.createInvoke("java.io.BufferedReader", "readLine",
// Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
- InstructionHandle try_start = il.append(new PUSH(cp,"Andy"));
- il.append(new ASTORE(name));
+ InstructionHandle try_start = il.append(InstructionFactory.PUSH(cp,"Andy"));
+ il.append(InstructionFactory.createASTORE(name));
// Upon normal execution we jump behind exception handler, the target
// address is not known yet.
- GOTO g = new GOTO(null);
+ InstructionBranch g = new InstructionBranch(Constants.GOTO);
InstructionHandle try_end = il.append(g);
// We add the exception handler which simply returns from the method.
@@ -503,7 +497,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
LocalVariableGen var_ex = mg.addLocalVariable("ex",Type.getType("Ljava.io.IOException;"),null,null);
int var_ex_slot = var_ex.getIndex();
- InstructionHandle handler = il.append(new ASTORE(var_ex_slot));
+ InstructionHandle handler = il.append(InstructionFactory.createASTORE(var_ex_slot));
var_ex.setStart(handler);
var_ex.setEnd(il.append(InstructionConstants.RETURN));
@@ -522,12 +516,12 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
il.append(factory.createNew(Type.STRINGBUFFER));
il.append(InstructionConstants.DUP);
- il.append(new PUSH(cp, "Hello, "));
+ il.append(InstructionFactory.PUSH(cp, "Hello, "));
il
.append(factory.createInvoke("java.lang.StringBuffer",
"<init>", Type.VOID, new Type[] { Type.STRING },
Constants.INVOKESPECIAL));
- il.append(new ALOAD(name));
+ il.append(InstructionFactory.createALOAD(name));
il.append(factory.createInvoke("java.lang.StringBuffer", "append",
Type.STRINGBUFFER, new Type[] { Type.STRING },
Constants.INVOKEVIRTUAL));
@@ -566,7 +560,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
"<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
}
- private MethodGen createMethodGen(String methodname,InstructionList il,ConstantPoolGen cp) {
+ private MethodGen createMethodGen(String methodname,InstructionList il,ConstantPool cp) {
return new MethodGen(
Constants.ACC_STATIC | Constants.ACC_PUBLIC, // access flags
Type.VOID, // return type
@@ -577,7 +571,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
}
- public AnnotationGen createSimpleVisibleAnnotation(ConstantPoolGen cp) {
+ public AnnotationGen createSimpleVisibleAnnotation(ConstantPool cp) {
SimpleElementValueGen evg = new SimpleElementValueGen(
ElementValueGen.PRIMITIVE_INT, cp, 4);
@@ -592,7 +586,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
return a;
}
- public AnnotationGen createFruitAnnotation(ConstantPoolGen cp,String aFruit) {
+ public AnnotationGen createFruitAnnotation(ConstantPool cp,String aFruit) {
SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.STRING,cp,aFruit);
ElementNameValuePairGen nvGen = new ElementNameValuePairGen("fruit",evg,cp);
ObjectType t = new ObjectType("SimpleStringAnnotation");
@@ -601,7 +595,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
return new AnnotationGen(t,elements,true,cp);
}
- public AnnotationGen createCombinedAnnotation(ConstantPoolGen cp) {
+ public AnnotationGen createCombinedAnnotation(ConstantPool cp) {
// Create an annotation instance
AnnotationGen a = createSimpleVisibleAnnotation(cp);
ArrayElementValueGen array = new ArrayElementValueGen(cp);
@@ -612,7 +606,7 @@ public class GeneratingAnnotatedClassesTest extends BcelTestCase {
return new AnnotationGen(new ObjectType("CombinedAnnotation"),elements,true,cp);
}
- public AnnotationGen createSimpleInvisibleAnnotation(ConstantPoolGen cp) {
+ public AnnotationGen createSimpleInvisibleAnnotation(ConstantPool cp) {
SimpleElementValueGen evg = new SimpleElementValueGen(
ElementValueGen.PRIMITIVE_INT, cp, 4);
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java
index b4b8dbce3..dbc3ae154 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParsingTest.java
@@ -11,11 +11,16 @@
* ******************************************************************/
package org.aspectj.apache.bcel.classfile.tests;
+import java.util.ArrayList;
+
+import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.ClassFormatException;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.classfile.Utility;
+import org.aspectj.apache.bcel.classfile.Utility.ResultHolder;
/**
* Generics introduces more complex signature possibilities, they are no longer just
@@ -149,27 +154,27 @@ public class GenericSignatureParsingTest extends BcelTestCase {
// These routines call BCEL to determine if it can correctly translate from one form to the other.
private void checkClassTypeSignature(String sig, String expected) {
StringBuffer result = new StringBuffer();
- int p = Utility.readClassTypeSignatureFrom(sig,0,result,false);
+ int p = GenericSignatureParsingTest.readClassTypeSignatureFrom(sig,0,result,false);
assertTrue("Only swallowed "+p+" chars of this sig "+sig+" (len="+sig.length()+")",p==sig.length());
assertTrue("Expected '"+expected+"' but got '"+result.toString()+"'",result.toString().equals(expected));
}
private void checkMethodTypeToSignature(String ret,String[] args,String expected) {
- String res = Utility.methodTypeToSignature(ret,args);
+ String res = GenericSignatureParsingTest.methodTypeToSignature(ret,args);
if (!res.equals(expected)) {
fail("Should match. Got: "+res+" Expected:"+expected);
}
}
private void checkMethodSignatureReturnType(String sig,String expected) {
- String result = Utility.methodSignatureReturnType(sig,false);
+ String result = GenericSignatureParsingTest.methodSignatureReturnType(sig,false);
if (!result.equals(expected)) {
fail("Should match. Got: "+result+" Expected:"+expected);
}
}
private void checkMethodSignatureArgumentTypes(String in,String[] expected) {
- String[] result = Utility.methodSignatureArgumentTypes(in,false);
+ String[] result = GenericSignatureParsingTest.methodSignatureArgumentTypes(in,false);
if (result.length!=expected.length) {
fail("Expected "+expected.length+" entries to be returned but only got "+result.length);
}
@@ -191,5 +196,278 @@ public class GenericSignatureParsingTest extends BcelTestCase {
}
return null;
}
+
+
+ /**
+ * Takes a string and consumes a single complete signature from it, returning
+ * how many chars it consumed. The chopit flag indicates whether to shorten
+ * type references ( java/lang/String => String )
+ *
+ * FIXME asc this should also create some kind of object you can query for information about whether its parameterized, what the bounds are, etc...
+ */
+ public static final int readClassTypeSignatureFrom(String signature, int posn, StringBuffer result, boolean chopit) {
+ int idx = posn;
+ try {
+ switch (signature.charAt(idx)) {
+ case 'B' : result.append("byte"); return 1;
+ case 'C' : result.append("char"); return 1;
+ case 'D' : result.append("double"); return 1;
+ case 'F' : result.append("float"); return 1;
+ case 'I' : result.append("int"); return 1;
+ case 'J' : result.append("long"); return 1;
+ case 'S' : result.append("short"); return 1;
+ case 'Z' : result.append("boolean");return 1;
+ case 'V' : result.append("void"); return 1;
+
+
+ //FIXME ASC Need a state machine to check we are parsing the right stuff here !
+ case 'T' :
+ idx++;
+ int nextSemiIdx = signature.indexOf(';',idx);
+ result.append(signature.substring(idx,nextSemiIdx));
+ return nextSemiIdx+1-posn;
+
+ case '+' :
+ result.append("? extends ");
+ return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1;
+
+ case '-' :
+ result.append("? super ");
+ return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1;
+
+ case '*' :
+ result.append("?");
+ return 1;
+
+ case 'L' : // Full class name
+ boolean parameterized = false;
+ int idxSemicolon = signature.indexOf(';',idx); // Look for closing ';' or '<'
+ int idxAngly = signature.indexOf('<',idx);
+ int endOfSig = idxSemicolon;
+ if ((idxAngly!=-1) && idxAngly<endOfSig) { endOfSig = idxAngly; parameterized = true; }
+
+ String p = signature.substring(idx+1,endOfSig);
+ String t = Utility.compactClassName(p,chopit);
+
+ result.append(t);
+ idx=endOfSig;
+ // we might have finished now, depending on whether this is a parameterized type...
+ if (parameterized) {
+ idx++;
+ result.append("<");
+ while (signature.charAt(idx)!='>') {
+ idx+=readClassTypeSignatureFrom(signature,idx,result,chopit);
+ if (signature.charAt(idx)!='>') result.append(",");
+ }
+ result.append(">");idx++;
+ }
+ if (signature.charAt(idx)!=';') throw new RuntimeException("Did not find ';' at end of signature, found "+signature.charAt(idx));
+ idx++;
+ return idx-posn;
+
+
+ case '[' : // Array declaration
+ int dim = 0;
+ while (signature.charAt(idx)=='[') {dim++;idx++;}
+ idx+=readClassTypeSignatureFrom(signature,idx,result,chopit);
+ while (dim>0) {result.append("[]");dim--;}
+ return idx-posn;
+
+ default : throw new ClassFormatException("Invalid signature: `" +
+ signature + "'");
+ }
+ } catch(StringIndexOutOfBoundsException e) { // Should never occur
+ throw new ClassFormatException("Invalid signature: " + e + ":" + signature);
+ }
+ }
+
+
+ public static final String readClassTypeSignatureFrom(String signature) {
+ StringBuffer sb = new StringBuffer();
+ GenericSignatureParsingTest.readClassTypeSignatureFrom(signature,0,sb,false);
+ return sb.toString();
+ }
+
+
+ public static int countBrackets(String brackets) {
+ char[] chars = brackets.toCharArray();
+ int count = 0;
+ boolean open = false;
+
+ for(int i=0; i<chars.length; i++) {
+ switch(chars[i]) {
+ case '[':
+ if (open) throw new RuntimeException("Illegally nested brackets:" + brackets);
+ open = true;
+ break;
+
+ case ']':
+ if (!open) throw new RuntimeException("Illegally nested brackets:" + brackets);
+ open = false;
+ count++;
+ break;
+
+ default:
+ }
+ }
+
+ if (open) throw new RuntimeException("Illegally nested brackets:" + brackets);
+
+ return count;
+ }
+
+
+ /**
+ * Parse Java type such as "char", or "java.lang.String[]" and return the
+ * signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively.
+ *
+ * @param type Java type
+ * @return byte code signature
+ */
+ public static String getSignature(String type) {
+ StringBuffer buf = new StringBuffer();
+ char[] chars = type.toCharArray();
+ boolean char_found = false, delim = false;
+ int index = -1;
+
+ loop:
+ for (int i=0; i < chars.length; i++) {
+ switch (chars[i]) {
+ case ' ': case '\t': case '\n': case '\r': case '\f':
+ if (char_found) delim = true;
+ break;
+
+ case '[':
+ if (!char_found) throw new RuntimeException("Illegal type: " + type);
+ index = i;
+ break loop;
+
+ default:
+ char_found = true;
+ if (!delim) buf.append(chars[i]);
+ }
+ }
+
+ int brackets = 0;
+
+ if(index > 0) brackets = GenericSignatureParsingTest.countBrackets(type.substring(index));
+
+ type = buf.toString();
+ buf.setLength(0);
+
+ for (int i=0; i < brackets; i++) buf.append('[');
+
+ boolean found = false;
+
+ for(int i=Constants.T_BOOLEAN; (i <= Constants.T_VOID) && !found; i++) {
+ if (Constants.TYPE_NAMES[i].equals(type)) {
+ found = true;
+ buf.append(Constants.SHORT_TYPE_NAMES[i]);
+ }
+ }
+
+ // Class name
+ if (!found) buf.append('L' + type.replace('.', '/') + ';');
+
+ return buf.toString();
+ }
+
+
+ /**
+ * For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns
+ * the string representing the return type its 'normal' form, e.g. 'boolean'
+ *
+ * @param signature Method signature
+ * @param chopit Shorten class names
+ * @return return type of method
+ */
+ public static final String methodSignatureReturnType(String signature,boolean chopit) throws ClassFormatException {
+ int index;
+ String type;
+ try {
+ // Read return type after `)'
+ index = signature.lastIndexOf(')') + 1;
+ type = Utility.signatureToString(signature.substring(index), chopit);
+ } catch (StringIndexOutOfBoundsException e) {
+ throw new ClassFormatException("Invalid method signature: " + signature);
+ }
+ return type;
+ }
+
+
+ /**
+ * For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns
+ * the string representing the return type its 'normal' form, e.g. 'boolean'
+ *
+ * @param signature Method signature
+ * @return return type of method
+ * @throws ClassFormatException
+ */
+ public static final String methodSignatureReturnType(String signature) throws ClassFormatException {
+ return GenericSignatureParsingTest.methodSignatureReturnType(signature, true);
+ }
+
+
+ /**
+ * For some method signature (class file format) like '([Ljava/lang/String;Z)V' this returns an array
+ * of strings representing the arguments in their 'normal' form, e.g. '{java.lang.String[],boolean}'
+ *
+ * @param signature Method signature
+ * @param chopit Shorten class names
+ * @return Array of argument types
+ */
+ public static final String[] methodSignatureArgumentTypes(String signature,boolean chopit) throws ClassFormatException {
+ ArrayList vec = new ArrayList();
+ int index;
+ String[] types;
+
+ try { // Read all declarations between for `(' and `)'
+ if (signature.charAt(0) != '(')
+ throw new ClassFormatException("Invalid method signature: " + signature);
+
+ index = 1; // current string position
+
+ while(signature.charAt(index) != ')') {
+ Utility.ResultHolder rh = Utility.signatureToStringInternal(signature.substring(index),chopit);
+ vec.add(rh.getResult());
+ index += rh.getConsumedChars();
+ }
+ } catch(StringIndexOutOfBoundsException e) {
+ throw new ClassFormatException("Invalid method signature: " + signature);
+ }
+
+ types = new String[vec.size()];
+ vec.toArray(types);
+ return types;
+ }
+
+
+ /**
+ * Converts string containing the method return and argument types
+ * to a byte code method signature.
+ *
+ * @param returnType Return type of method (e.g. "char" or "java.lang.String[]")
+ * @param methodArgs Types of method arguments
+ * @return Byte code representation of method signature
+ */
+ public final static String methodTypeToSignature(String returnType, String[] methodArgs) throws ClassFormatException {
+
+ StringBuffer buf = new StringBuffer("(");
+
+ if (methodArgs != null) {
+ for (int i=0; i < methodArgs.length; i++) {
+ String str = GenericSignatureParsingTest.getSignature(methodArgs[i]);
+
+ if (str.equals("V")) // void can't be a method argument
+ throw new ClassFormatException("Invalid type: " + methodArgs[i]);
+
+ buf.append(str);
+ }
+ }
+
+ buf.append(")" + GenericSignatureParsingTest.getSignature(returnType));
+
+ return buf.toString();
+ }
}
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/MethodAnnotationsTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/MethodAnnotationsTest.java
index 5b4bbbaa9..005eb3f69 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/MethodAnnotationsTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/MethodAnnotationsTest.java
@@ -18,8 +18,8 @@ import java.util.Iterator;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
import org.aspectj.apache.bcel.util.SyntheticRepository;
@@ -65,7 +65,7 @@ public class MethodAnnotationsTest extends BcelTestCase {
for (int i = 0; i < methods.length; i++) {
Method m = methods[i];
- Annotation[] methodAnnotations = m.getAnnotations();
+ AnnotationGen[] methodAnnotations = m.getAnnotations();
if (m.getName().equals(methodname)) {
checkAnnotation(methodAnnotations[0],annotationName,annotationElementName,annotationElementValue);
@@ -73,11 +73,11 @@ public class MethodAnnotationsTest extends BcelTestCase {
}
}
- private void checkAnnotation(Annotation a,String name,String elementname,String elementvalue) {
+ private void checkAnnotation(AnnotationGen a,String name,String elementname,String elementvalue) {
assertTrue("Expected annotation to have name "+name+" but it had name "+a.getTypeName(),
a.getTypeName().equals(name));
assertTrue("Expected annotation to have one element but it had "+a.getValues().size(),a.getValues().size()==1);
- ElementNameValuePair envp = (ElementNameValuePair)a.getValues().get(0);
+ ElementNameValuePairGen envp = (ElementNameValuePairGen)a.getValues().get(0);
assertTrue("Expected element name "+elementname+" but was "+envp.getNameString(),
elementname.equals(envp.getNameString()));
assertTrue("Expected element value "+elementvalue+" but was "+envp.getValue().stringifyValue(),
@@ -87,9 +87,9 @@ public class MethodAnnotationsTest extends BcelTestCase {
// helper methods
- public void checkValue(Annotation a,String name,String tostring) {
+ public void checkValue(AnnotationGen a,String name,String tostring) {
for (Iterator i = a.getValues().iterator(); i.hasNext();) {
- ElementNameValuePair element = (ElementNameValuePair) i.next();
+ ElementNameValuePairGen element = (ElementNameValuePairGen) i.next();
if (element.getNameString().equals(name)) {
if (!element.getValue().stringifyValue().equals(tostring)) {
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue());
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java
index d0afaef41..1ba040ea0 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java
@@ -17,28 +17,25 @@ import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.generic.ALOAD;
-import org.aspectj.apache.bcel.generic.ASTORE;
import org.aspectj.apache.bcel.generic.ArrayType;
import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.ConstantPoolGen;
-import org.aspectj.apache.bcel.generic.GOTO;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
+import org.aspectj.apache.bcel.generic.InstructionBranch;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
+import org.aspectj.apache.bcel.generic.InstructionLV;
import org.aspectj.apache.bcel.generic.InstructionList;
import org.aspectj.apache.bcel.generic.LocalVariableGen;
import org.aspectj.apache.bcel.generic.MethodGen;
import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.PUSH;
import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.generic.annotation.ArrayElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementNameValuePairGen;
-import org.aspectj.apache.bcel.generic.annotation.ElementValueGen;
-import org.aspectj.apache.bcel.generic.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.util.SyntheticRepository;
/**
@@ -66,7 +63,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
*/
public void testParameterAnnotations_builtOK() {
ClassGen clg = createClassGen("HelloWorld");
- ConstantPoolGen cpg = clg.getConstantPool();
+ ConstantPool cpg = clg.getConstantPool();
InstructionList il = new InstructionList();
buildClassContentsWithAnnotatedMethods(clg,cpg,il,true);
@@ -75,7 +72,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
assertTrue("Class should have 2 methods but has "+i,i==2);
Method mainMethod = clg.getMethods()[0];
- Annotation[] annos = mainMethod.getAnnotationsOnParameter(0);
+ AnnotationGen[] annos = mainMethod.getAnnotationsOnParameter(0);
assertTrue("Should be two annotation on the 'argv' parameter to main() but there are "+annos.length,annos.length==2);
assertTrue("This annotation should contain the string 'fruit=Apples' but it is "+annos[0].toString(),
annos[0].toString().indexOf("fruit=Apples")!=-1);
@@ -90,7 +87,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
*/
public void testParameterAnnotations_savedAndLoadedOK() throws ClassNotFoundException {
ClassGen clg = createClassGen("HelloWorld");
- ConstantPoolGen cpg = clg.getConstantPool();
+ ConstantPool cpg = clg.getConstantPool();
InstructionList il = new InstructionList();
buildClassContentsWithAnnotatedMethods(clg,cpg,il,true);
@@ -105,7 +102,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
assertTrue("Class should have 2 methods but has "+i,i==2);
Method mainMethod = clg.getMethods()[0];
- Annotation[] annos = mainMethod.getAnnotationsOnParameter(0);
+ AnnotationGen[] annos = mainMethod.getAnnotationsOnParameter(0);
assertTrue("Should be two annotation on the 'argv' parameter to main() but there are "+annos.length,annos.length==2);
assertTrue("This annotation should contain the string 'fruit=Apples' but it is "+annos[0].toString(),
annos[0].toString().indexOf("fruit=Apples")!=-1);
@@ -124,7 +121,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
JavaClass jc = getClassFrom("testcode.jar","AnnotatedParameters");
ClassGen clg = new ClassGen(jc);
- ConstantPoolGen cpg = clg.getConstantPool();
+ ConstantPool cpg = clg.getConstantPool();
//
// Foo method looks like this:
@@ -171,15 +168,15 @@ public class ParameterAnnotationsTest extends BcelTestCase {
JavaClass jc2 = getClassFrom("temp2","AnnotatedParameters");
m = jc2.getMethods()[2];
- Annotation[] p1annotations = m.getAnnotationsOnParameter(0);
- Annotation[] p2annotations = m.getAnnotationsOnParameter(1);
+ AnnotationGen[] p1annotations = m.getAnnotationsOnParameter(0);
+ AnnotationGen[] p2annotations = m.getAnnotationsOnParameter(1);
assertTrue("Expected two annotations on the first parameter but found "+p1annotations.length,p1annotations.length==2);
assertTrue("Expected two annotations on the second parameter but found "+p2annotations.length,p2annotations.length==2);
String expectedString = "[@SimpleAnnotation(id=2),@SimpleStringAnnotation(fruit=Banana)]";
assertTrue("Expected formatted short string of '"+expectedString+"' but it was '"+dumpAnnotations(p1annotations)+"'",
dumpAnnotations(p1annotations).equals(expectedString));
- expectedString = "[@SimpleAnnotation(id=3),@AnnotationEnumElement(enumval=Red)]";
+ expectedString = "[@SimpleAnnotation(id=3),@AnnotationEnumElement(enumval=LSimpleEnum;Red)]";
assertTrue("Expected formatted short string of '"+expectedString+"' but it was '"+dumpAnnotations(p2annotations)+"'",
dumpAnnotations(p2annotations).equals(expectedString));
@@ -193,7 +190,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
public void testParameterAnnotations_loadedThenModifiedWithInvisibleAnnotationThenSavedAndLoadedOK() throws ClassNotFoundException {
JavaClass jc = getClassFrom("testcode.jar","AnnotatedParameters");
ClassGen clg = new ClassGen(jc);
- ConstantPoolGen cpg = clg.getConstantPool();
+ ConstantPool cpg = clg.getConstantPool();
//
// Foo method looks like this:
@@ -242,15 +239,15 @@ public class ParameterAnnotationsTest extends BcelTestCase {
JavaClass jc2 = getClassFrom("temp3","AnnotatedParameters");
m = jc2.getMethods()[2];
- Annotation[] p1annotations = m.getAnnotationsOnParameter(0);
- Annotation[] p2annotations = m.getAnnotationsOnParameter(1);
+ AnnotationGen[] p1annotations = m.getAnnotationsOnParameter(0);
+ AnnotationGen[] p2annotations = m.getAnnotationsOnParameter(1);
assertTrue("Expected two annotations on the first parameter but found "+p1annotations.length,p1annotations.length==2);
assertTrue("Expected two annotations on the second parameter but found "+p2annotations.length,p2annotations.length==2);
String expectedString = "[@SimpleAnnotation(id=2),@SimpleStringAnnotation(fruit=Banana)]";
assertTrue("Expected formatted short string of '"+expectedString+"' but it was '"+dumpAnnotations(p1annotations)+"'",
dumpAnnotations(p1annotations).equals(expectedString));
- expectedString = "[@SimpleAnnotation(id=3),@AnnotationEnumElement(enumval=Red)]";
+ expectedString = "[@SimpleAnnotation(id=3),@AnnotationEnumElement(enumval=LSimpleEnum;Red)]";
assertTrue("Expected formatted short string of '"+expectedString+"' but it was '"+dumpAnnotations(p2annotations)+"'",
dumpAnnotations(p2annotations).equals(expectedString));
@@ -263,12 +260,12 @@ public class ParameterAnnotationsTest extends BcelTestCase {
// attributes vanish !
clg = new ClassGen(jc2);
mg = new MethodGen(m,clg.getClassName(),clg.getConstantPool());
- Attribute[] as = mg.getAttributes();
- assertTrue("Should be 2 (RIPA and RVPA) but there are "+mg.getAttributes().length,mg.getAttributes().length==2);
+ List as = mg.getAttributes();
+ assertTrue("Should be 2 (RIPA and RVPA) but there are "+mg.getAttributes().size(),mg.getAttributes().size()==2);
List l = mg.getAnnotationsOnParameter(0);
assertTrue("Should be 2 annotations on first parameter but there is only "+l.size()+":"+l.toString(),
l.size()==2);
- assertTrue("Should be 0 but there are "+mg.getAttributes().length,mg.getAttributes().length==0);
+ assertTrue("Should be 0 but there are "+mg.getAttributes().size(),mg.getAttributes().size()==0);
}
@@ -294,7 +291,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
dumpClass(cg,dir+File.separator+fname);
}
- private void buildClassContentsWithAnnotatedMethods(ClassGen cg, ConstantPoolGen cp, InstructionList il,boolean addParameterAnnotations) {
+ private void buildClassContentsWithAnnotatedMethods(ClassGen cg, ConstantPool cp, InstructionList il,boolean addParameterAnnotations) {
// Create method 'public static void main(String[]argv)'
MethodGen mg = createMethodGen("main",il,cp);
InstructionFactory factory = new InstructionFactory(cg);
@@ -323,14 +320,14 @@ public class ParameterAnnotationsTest extends BcelTestCase {
LocalVariableGen lg = mg.addLocalVariable("in", new ObjectType(
"java.io.BufferedReader"), null, null);
int in = lg.getIndex();
- lg.setStart(il.append(new ASTORE(in))); // "in" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(in))); // "in" valid from here
// Create local variable name and initialize it to null
lg = mg.addLocalVariable("name", Type.STRING, null, null);
int name = lg.getIndex();
il.append(InstructionConstants.ACONST_NULL);
- lg.setStart(il.append(new ASTORE(name))); // "name" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(name))); // "name" valid from here
// Create try-catch block: We remember the start of the block, read a
// line from the standard input and store it into the variable name .
@@ -345,13 +342,13 @@ public class ParameterAnnotationsTest extends BcelTestCase {
// il.append(new ALOAD(in));
// il.append(factory.createInvoke("java.io.BufferedReader", "readLine",
// Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
- InstructionHandle try_start = il.append(new PUSH(cp,"Andy"));
- il.append(new ASTORE(name));
+ InstructionHandle try_start = il.append(InstructionFactory.PUSH(cp,"Andy"));
+ il.append(InstructionFactory.createASTORE(name));
// Upon normal execution we jump behind exception handler, the target
// address is not known yet.
- GOTO g = new GOTO(null);
+ InstructionBranch g = new InstructionBranch(Constants.GOTO);
InstructionHandle try_end = il.append(g);
// We add the exception handler which simply returns from the method.
@@ -359,7 +356,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
LocalVariableGen var_ex = mg.addLocalVariable("ex",Type.getType("Ljava.io.IOException;"),null,null);
int var_ex_slot = var_ex.getIndex();
- InstructionHandle handler = il.append(new ASTORE(var_ex_slot));
+ InstructionHandle handler = il.append(InstructionFactory.createASTORE(var_ex_slot));
var_ex.setStart(handler);
var_ex.setEnd(il.append(InstructionConstants.RETURN));
@@ -378,12 +375,12 @@ public class ParameterAnnotationsTest extends BcelTestCase {
il.append(factory.createNew(Type.STRINGBUFFER));
il.append(InstructionConstants.DUP);
- il.append(new PUSH(cp, "Hello, "));
+ il.append(InstructionFactory.PUSH(cp, "Hello, "));
il
.append(factory.createInvoke("java.lang.StringBuffer",
"<init>", Type.VOID, new Type[] { Type.STRING },
Constants.INVOKESPECIAL));
- il.append(new ALOAD(name));
+ il.append(new InstructionLV(Constants.ALOAD,name));
il.append(factory.createInvoke("java.lang.StringBuffer", "append",
Type.STRINGBUFFER, new Type[] { Type.STRING },
Constants.INVOKEVIRTUAL));
@@ -408,7 +405,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
cg.addEmptyConstructor(Constants.ACC_PUBLIC);
}
- private void buildClassContents(ClassGen cg, ConstantPoolGen cp, InstructionList il) {
+ private void buildClassContents(ClassGen cg, ConstantPool cp, InstructionList il) {
// Create method 'public static void main(String[]argv)'
MethodGen mg = createMethodGen("main",il,cp);
InstructionFactory factory = new InstructionFactory(cg);
@@ -436,14 +433,14 @@ public class ParameterAnnotationsTest extends BcelTestCase {
LocalVariableGen lg = mg.addLocalVariable("in", new ObjectType(
"java.io.BufferedReader"), null, null);
int in = lg.getIndex();
- lg.setStart(il.append(new ASTORE(in))); // "in" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(in))); // "in" valid from here
// Create local variable name and initialize it to null
lg = mg.addLocalVariable("name", Type.STRING, null, null);
int name = lg.getIndex();
il.append(InstructionConstants.ACONST_NULL);
- lg.setStart(il.append(new ASTORE(name))); // "name" valid from here
+ lg.setStart(il.append(InstructionFactory.createASTORE(name))); // "name" valid from here
// Create try-catch block: We remember the start of the block, read a
// line from the standard input and store it into the variable name .
@@ -458,13 +455,13 @@ public class ParameterAnnotationsTest extends BcelTestCase {
// il.append(new ALOAD(in));
// il.append(factory.createInvoke("java.io.BufferedReader", "readLine",
// Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
- InstructionHandle try_start = il.append(new PUSH(cp,"Andy"));
- il.append(new ASTORE(name));
+ InstructionHandle try_start = il.append(InstructionFactory.PUSH(cp,"Andy"));
+ il.append(InstructionFactory.createASTORE(name));
// Upon normal execution we jump behind exception handler, the target
// address is not known yet.
- GOTO g = new GOTO(null);
+ InstructionBranch g = new InstructionBranch(Constants.GOTO);
InstructionHandle try_end = il.append(g);
// We add the exception handler which simply returns from the method.
@@ -472,7 +469,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
LocalVariableGen var_ex = mg.addLocalVariable("ex",Type.getType("Ljava.io.IOException;"),null,null);
int var_ex_slot = var_ex.getIndex();
- InstructionHandle handler = il.append(new ASTORE(var_ex_slot));
+ InstructionHandle handler = il.append(InstructionFactory.createASTORE(var_ex_slot));
var_ex.setStart(handler);
var_ex.setEnd(il.append(InstructionConstants.RETURN));
@@ -491,12 +488,12 @@ public class ParameterAnnotationsTest extends BcelTestCase {
il.append(factory.createNew(Type.STRINGBUFFER));
il.append(InstructionConstants.DUP);
- il.append(new PUSH(cp, "Hello, "));
+ il.append(InstructionFactory.PUSH(cp, "Hello, "));
il
.append(factory.createInvoke("java.lang.StringBuffer",
"<init>", Type.VOID, new Type[] { Type.STRING },
Constants.INVOKESPECIAL));
- il.append(new ALOAD(name));
+ il.append(InstructionFactory.createALOAD(name));
il.append(factory.createInvoke("java.lang.StringBuffer", "append",
Type.STRINGBUFFER, new Type[] { Type.STRING },
Constants.INVOKEVIRTUAL));
@@ -535,7 +532,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
"<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null);
}
- private MethodGen createMethodGen(String methodname,InstructionList il,ConstantPoolGen cp) {
+ private MethodGen createMethodGen(String methodname,InstructionList il,ConstantPool cp) {
return new MethodGen(
Constants.ACC_STATIC | Constants.ACC_PUBLIC, // access flags
Type.VOID, // return type
@@ -546,7 +543,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
}
- public AnnotationGen createSimpleVisibleAnnotation(ConstantPoolGen cp) {
+ public AnnotationGen createSimpleVisibleAnnotation(ConstantPool cp) {
SimpleElementValueGen evg = new SimpleElementValueGen(
ElementValueGen.PRIMITIVE_INT, cp, 4);
@@ -561,7 +558,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
return a;
}
- public AnnotationGen createCombinedAnnotation(ConstantPoolGen cp) {
+ public AnnotationGen createCombinedAnnotation(ConstantPool cp) {
// Create an annotation instance
AnnotationGen a = createSimpleVisibleAnnotation(cp);
ArrayElementValueGen array = new ArrayElementValueGen(cp);
@@ -572,7 +569,7 @@ public class ParameterAnnotationsTest extends BcelTestCase {
return new AnnotationGen(new ObjectType("CombinedAnnotation"),elements,true,cp);
}
- public AnnotationGen createSimpleInvisibleAnnotation(ConstantPoolGen cp) {
+ public AnnotationGen createSimpleInvisibleAnnotation(ConstantPool cp) {
SimpleElementValueGen evg = new SimpleElementValueGen(
ElementValueGen.PRIMITIVE_INT, cp, 4);
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java
index 4c8c463cb..ac9023f22 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleAnnotationAttributeTest.java
@@ -14,6 +14,7 @@ package org.aspectj.apache.bcel.classfile.tests;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -21,17 +22,16 @@ import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.ConstantPool;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Utility;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.AnnotationElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ClassElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.EnumElementValue;
-import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ClassElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.EnumElementValueGen;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValueGen;
import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
import org.aspectj.apache.bcel.util.SyntheticRepository;
@@ -60,17 +60,17 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
List anns = rva.getAnnotations();
assertTrue("Should be one annotation but found "+anns.size(),
anns.size()==1);
- Annotation ann = (Annotation) anns.get(0);
+ AnnotationGen ann = (AnnotationGen) anns.get(0);
assertTrue("Should be called 'SimpleAnnotation' but was called "+ann.getTypeName(),
ann.getTypeName().equals("SimpleAnnotation"));
List l = ann.getValues();
assertTrue("Should be one value for annotation 'SimpleAnnotation' but found "+l.size(),
l.size()==1);
- ElementNameValuePair envp = (ElementNameValuePair)l.get(0);
+ ElementNameValuePairGen envp = (ElementNameValuePairGen)l.get(0);
assertTrue("Name of element in SimpleAnnotation should be 'id' but it is "+envp.getNameString(),
envp.getNameString().equals("id"));
- SimpleElementValue evalue = (SimpleElementValue)envp.getValue();
- assertTrue("'id' should be of type int, but it is "+evalue.getElementValueType(),evalue.getElementValueType()==SimpleElementValue.PRIMITIVE_INT);
+ SimpleElementValueGen evalue = (SimpleElementValueGen)envp.getValue();
+ assertTrue("'id' should be of type int, but it is "+evalue.getElementValueType(),evalue.getElementValueType()==SimpleElementValueGen.PRIMITIVE_INT);
assertTrue("'id' should have value 4 but it is "+evalue.getValueInt(),
evalue.getValueInt()==4);
}
@@ -79,7 +79,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
SyntheticRepository repos = createRepos("testcode.jar");
JavaClass clazz = repos.loadClass("SimpleAnnotatedClass");
ConstantPool pool = clazz.getConstantPool();
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("Expected one annotation on SimpleAnnotatedClass class but got "+anns.length,
anns.length==1);
}
@@ -88,7 +88,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
SyntheticRepository repos = createRepos("testcode.jar");
JavaClass clazz = repos.loadClass("SimpleAnnotatedClass");
ConstantPool pool = clazz.getConstantPool();
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("Expected one annotation on SimpleAnnotatedClass class but got "+anns.length,
anns.length==1);
@@ -99,7 +99,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
SyntheticRepository repos2 = createRepos(".");
JavaClass clazz2 = repos.loadClass("SimpleAnnotatedClass");
ConstantPool pool2 = clazz2.getConstantPool();
- Annotation[] anns2 = clazz2.getAnnotations();
+ AnnotationGen[] anns2 = clazz2.getAnnotations();
assertTrue("Expected one annotation on SimpleAnnotatedClass class but got "+anns2.length,
anns2.length==1);
@@ -135,17 +135,17 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
}
private void verifyAnnotationStringElement(JavaClass clazz) {
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("should be one annotation but found "+anns.length,anns.length==1);
- Annotation ann = anns[0];
+ AnnotationGen ann = anns[0];
assertTrue("should be called 'AnnotationStringElement' but was called "+ann.getTypeName(),
ann.getTypeName().equals("AnnotationStringElement"));
List l = ann.getValues();
assertTrue("Should be one value but there were "+l.size(),l.size()==1);
- ElementNameValuePair nvp = (ElementNameValuePair)l.get(0);
+ ElementNameValuePairGen nvp = (ElementNameValuePairGen)l.get(0);
assertTrue("Name of element should be 'stringval' but was "+nvp.getNameString(),
nvp.getNameString().equals("stringval"));
- SimpleElementValue ev = (SimpleElementValue)nvp.getValue();
+ SimpleElementValueGen ev = (SimpleElementValueGen)nvp.getValue();
assertTrue("String value should be 'hello' but was '"+ev.getValueString()+"'",
ev.getValueString().equals("hello"));
}
@@ -178,15 +178,15 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
}
private void verifyComplexAnnotation(JavaClass clazz) {
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("Should be one annotation but found "+anns.length,anns.length==1);
- Annotation ann = anns[0];
+ AnnotationGen ann = anns[0];
assertTrue("Should be called 'ComplexAnnotation' but was called "+ann.getTypeName(),
ann.getTypeName().equals("ComplexAnnotation"));
List l = ann.getValues();
assertTrue("Should be eight values for annotation 'ComplexAnnotation' but found "+l.size(),
l.size()==8);
- List names = Utility.getListOfAnnotationNames(ann);
+ List names = RuntimeVisibleAnnotationAttributeTest.getListOfAnnotationNames(ann);
assertTrue("Cant find expected element ",names.contains("ival"));
assertTrue("Cant find expected element ",names.contains("dval"));
assertTrue("Cant find expected element ",names.contains("zval"));
@@ -207,9 +207,9 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
}
- private void checkValue(Annotation a,String name,String tostring) {
+ private void checkValue(AnnotationGen a,String name,String tostring) {
for (Iterator i = a.getValues().iterator(); i.hasNext();) {
- ElementNameValuePair element = (ElementNameValuePair) i.next();
+ ElementNameValuePairGen element = (ElementNameValuePairGen) i.next();
if (element.getNameString().equals(name)) {
if (!element.getValue().stringifyValue().equals(tostring)) {
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue());
@@ -232,7 +232,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
public void testAnnotationClassElementCopying() throws ClassNotFoundException {
SyntheticRepository repos = createRepos("testcode.jar");
JavaClass clazz = repos.loadClass("AnnotatedWithClassClass");
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
ClassGen cg = new ClassGen(clazz);
// Checks we can copy class values in an annotation
new AnnotationGen(anns[0],cg.getConstantPool(),true);
@@ -256,17 +256,17 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
}
private void verifyClassAnnotation(JavaClass clazz) {
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("should be one annotation but found "+anns.length,anns.length==1);
- Annotation ann = anns[0];
+ AnnotationGen ann = anns[0];
assertTrue("should be called 'AnnotationClassElement' but was called "+ann.getTypeName(),
ann.getTypeName().equals("AnnotationClassElement"));
List l = ann.getValues();
assertTrue("Should be one value but there were "+l.size(),l.size()==1);
- ElementNameValuePair nvp = (ElementNameValuePair)l.get(0);
+ ElementNameValuePairGen nvp = (ElementNameValuePairGen)l.get(0);
assertTrue("Name of element should be 'clz' but was "+nvp.getNameString(),
nvp.getNameString().equals("clz"));
- ClassElementValue ev = (ClassElementValue)nvp.getValue();
+ ClassElementValueGen ev = (ClassElementValueGen)nvp.getValue();
assertTrue("String value should be 'Ljava/lang/Integer;' but was '"+ev.getClassString()+"'",
ev.getClassString().equals("Ljava/lang/Integer;"));
@@ -298,20 +298,20 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
}
public void verifyAnnotationEnumElement(JavaClass clazz) {
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("should be one annotation but found "+anns.length,anns.length==1);
- Annotation ann = anns[0];
+ AnnotationGen ann = anns[0];
assertTrue("should be called 'AnnotationEnumElement' but was called "+ann.getTypeName(),
ann.getTypeName().equals("AnnotationEnumElement"));
List l = ann.getValues();
assertTrue("Should be one value but there were "+l.size(),l.size()==1);
- ElementNameValuePair nvp = (ElementNameValuePair)l.get(0);
+ ElementNameValuePairGen nvp = (ElementNameValuePairGen)l.get(0);
assertTrue("Name of element should be 'enumval' but was "+nvp.getNameString(),
nvp.getNameString().equals("enumval"));
- ElementValue ev = nvp.getValue();
- assertTrue("Should be of type EnumElementValue but is "+ev,ev instanceof EnumElementValue);
- EnumElementValue eev = (EnumElementValue)ev;
- assertTrue("Should be an enum type value but is "+eev.getElementValueType(),eev.getElementValueType()==SimpleElementValue.ENUM_CONSTANT);
+ ElementValueGen ev = nvp.getValue();
+ assertTrue("Should be of type EnumElementValue but is "+ev,ev instanceof EnumElementValueGen);
+ EnumElementValueGen eev = (EnumElementValueGen)ev;
+ assertTrue("Should be an enum type value but is "+eev.getElementValueType(),eev.getElementValueType()==SimpleElementValueGen.ENUM_CONSTANT);
assertTrue("Enum type for annotation should be 'SimpleEnum' but is "+Utility.signatureToString(eev.getEnumTypeString()),Utility.signatureToString(eev.getEnumTypeString()).equals("SimpleEnum"));
assertTrue("String value should be 'Red' but was '"+eev.getEnumValueString()+"'",
eev.getEnumValueString().equals("Red"));
@@ -323,7 +323,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
public void testAnnotationArraysOfAnnotations() throws ClassNotFoundException {
SyntheticRepository repos = createRepos("testcode.jar");
JavaClass clazz = repos.loadClass("AnnotatedWithCombinedAnnotation");
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("should be one annotation but found "+anns.length,anns.length==1);
checkCombinedAnnotation(anns[0]);
}
@@ -331,7 +331,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
public void testAnnotationArraysOfAnnotationsReadWrite() throws ClassNotFoundException, IOException {
SyntheticRepository repos = createRepos("testcode.jar");
JavaClass clazz = repos.loadClass("AnnotatedWithCombinedAnnotation");
- Annotation[] anns = clazz.getAnnotations();
+ AnnotationGen[] anns = clazz.getAnnotations();
assertTrue("should be one annotation but found "+anns.length,anns.length==1);
checkCombinedAnnotation(anns[0]);
@@ -341,7 +341,7 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
SyntheticRepository repos2 = createRepos(".");
JavaClass clazz2 = repos2.loadClass("AnnotatedWithCombinedAnnotation");
- Annotation[] anns2 = clazz2.getAnnotations();
+ AnnotationGen[] anns2 = clazz2.getAnnotations();
assertTrue("should be one annotation but found "+anns2.length,anns2.length==1);
checkCombinedAnnotation(anns2[0]);
@@ -349,29 +349,29 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
}
- private void checkCombinedAnnotation(Annotation ann) {
+ private void checkCombinedAnnotation(AnnotationGen ann) {
assertTrue("should be called 'CombinedAnnotation' but was called "+ann.getTypeName(),
ann.getTypeName().equals("CombinedAnnotation"));
List l = ann.getValues();
assertTrue("Should be one value but there were "+l.size(),l.size()==1);
- ElementNameValuePair nvp = (ElementNameValuePair)l.get(0);
+ ElementNameValuePairGen nvp = (ElementNameValuePairGen)l.get(0);
assertTrue("Name of element should be 'value' but was "+nvp.getNameString(),
nvp.getNameString().equals("value"));
- ElementValue ev = nvp.getValue();
- assertTrue("Should be of type ArrayElementValue but is "+ev,ev instanceof ArrayElementValue);
- ArrayElementValue aev = (ArrayElementValue)ev;
+ ElementValueGen ev = nvp.getValue();
+ assertTrue("Should be of type ArrayElementValue but is "+ev,ev instanceof ArrayElementValueGen);
+ ArrayElementValueGen aev = (ArrayElementValueGen)ev;
assertTrue("Array element value should be of size 1 but is "+aev.getElementValuesArraySize(),
aev.getElementValuesArraySize()==1);
- ElementValue[] evs = aev.getElementValuesArray();
+ ElementValueGen[] evs = aev.getElementValuesArray();
assertTrue("Entry in the array should be AnnotationElementValue but is "+evs[0],
- evs[0] instanceof AnnotationElementValue);
- AnnotationElementValue inner_ev = (AnnotationElementValue)evs[0];
- Annotation a = inner_ev.getAnnotation();
+ evs[0] instanceof AnnotationElementValueGen);
+ AnnotationElementValueGen inner_ev = (AnnotationElementValueGen)evs[0];
+ AnnotationGen a = inner_ev.getAnnotation();
assertTrue("Should be SimpleAnnotation but is "+a.getTypeName(),a.getTypeName().equals("SimpleAnnotation"));
List envps = a.getValues();
assertTrue("Should be one name value pair but found "+envps.size(),envps.size()==1);
- ElementNameValuePair envp = (ElementNameValuePair) envps.get(0);
+ ElementNameValuePairGen envp = (ElementNameValuePairGen) envps.get(0);
assertTrue("Name should be 'id' but it is "+envp.getNameString(),envp.getNameString().equals("id"));
assertTrue("Value of 'id' should be 4 but it is "+envp.getValue().stringifyValue(),
envp.getValue().stringifyValue().equals("4"));
@@ -381,5 +381,15 @@ public class RuntimeVisibleAnnotationAttributeTest extends BcelTestCase {
protected void tearDown() throws Exception {
super.tearDown();
}
+
+ public static List getListOfAnnotationNames(AnnotationGen a) {
+ List l = a.getValues();
+ List names = new ArrayList();
+ for (Iterator i = l.iterator(); i.hasNext();) {
+ ElementNameValuePairGen element = (ElementNameValuePairGen) i.next();
+ names.add(element.getNameString());
+ }
+ return names;
+ }
}
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleParameterAnnotationAttributeTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleParameterAnnotationAttributeTest.java
index fad1dad2c..424d5352f 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleParameterAnnotationAttributeTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/RuntimeVisibleParameterAnnotationAttributeTest.java
@@ -19,8 +19,8 @@ import java.util.Iterator;
import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations;
import org.aspectj.apache.bcel.util.SyntheticRepository;
@@ -46,12 +46,12 @@ public class RuntimeVisibleParameterAnnotationAttributeTest extends BcelTestCase
assertTrue("foo takes two parameters, not "+paramAnns.getParameterAnnotations().size(),
paramAnns.getParameterAnnotations().size()==2);
- Annotation[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0);
+ AnnotationGen[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0);
checkAnnotation(firstParamAnnotations[0],"SimpleAnnotation","id","2");
- Annotation[] secondParamAnnotations = paramAnns.getAnnotationsOnParameter(1);
+ AnnotationGen[] secondParamAnnotations = paramAnns.getAnnotationsOnParameter(1);
checkAnnotation(secondParamAnnotations[0],"SimpleAnnotation","id","3");
- checkAnnotation(secondParamAnnotations[1],"AnnotationEnumElement","enumval","Red");
+ checkAnnotation(secondParamAnnotations[1],"AnnotationEnumElement","enumval","LSimpleEnum;Red");
}
if (m.getName().equals("main")) {
@@ -60,7 +60,7 @@ public class RuntimeVisibleParameterAnnotationAttributeTest extends BcelTestCase
assertTrue("main takes one parameter, not "+paramAnns.getParameterAnnotations().size(),
paramAnns.getParameterAnnotations().size()==1);
- Annotation[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0);
+ AnnotationGen[] firstParamAnnotations = paramAnns.getAnnotationsOnParameter(0);
checkAnnotation(firstParamAnnotations[0],"SimpleAnnotation","id","1");
}
}
@@ -98,22 +98,22 @@ public class RuntimeVisibleParameterAnnotationAttributeTest extends BcelTestCase
Method m = methods[i];
if (m.getName().equals("foo")) {
- Annotation[] firstParamAnnotations = m.getAnnotationsOnParameter(0);
+ AnnotationGen[] firstParamAnnotations = m.getAnnotationsOnParameter(0);
checkAnnotation(firstParamAnnotations[0],"SimpleAnnotation","id","2");
- Annotation[] secondParamAnnotations = m.getAnnotationsOnParameter(1);
+ AnnotationGen[] secondParamAnnotations = m.getAnnotationsOnParameter(1);
checkAnnotation(secondParamAnnotations[0],"SimpleAnnotation","id","3");
- checkAnnotation(secondParamAnnotations[1],"AnnotationEnumElement","enumval","Red");
+ checkAnnotation(secondParamAnnotations[1],"AnnotationEnumElement","enumval","LSimpleEnum;Red");
}
}
}
- private void checkAnnotation(Annotation a,String name,String elementname,String elementvalue) {
+ private void checkAnnotation(AnnotationGen a,String name,String elementname,String elementvalue) {
assertTrue("Expected annotation to have name "+name+" but it had name "+a.getTypeName(),
a.getTypeName().equals(name));
assertTrue("Expected annotation to have one element but it had "+a.getValues().size(),a.getValues().size()==1);
- ElementNameValuePair envp = (ElementNameValuePair)a.getValues().get(0);
+ ElementNameValuePairGen envp = (ElementNameValuePairGen)a.getValues().get(0);
assertTrue("Expected element name "+elementname+" but was "+envp.getNameString(),
elementname.equals(envp.getNameString()));
assertTrue("Expected element value "+elementvalue+" but was "+envp.getValue().stringifyValue(),
@@ -123,9 +123,9 @@ public class RuntimeVisibleParameterAnnotationAttributeTest extends BcelTestCase
// helper methods
- public void checkValue(Annotation a,String name,String tostring) {
+ public void checkValue(AnnotationGen a,String name,String tostring) {
for (Iterator i = a.getValues().iterator(); i.hasNext();) {
- ElementNameValuePair element = (ElementNameValuePair) i.next();
+ ElementNameValuePairGen element = (ElementNameValuePairGen) i.next();
if (element.getNameString().equals(name)) {
if (!element.getValue().stringifyValue().equals(tostring)) {
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue());
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java
index 5b2e17af8..dcb36432f 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java
@@ -13,8 +13,8 @@
package org.aspectj.apache.bcel.classfile.tests;
import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.ClassGen;
-import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
public class TypeAnnotationsTest extends BcelTestCase {
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java
index 1ed7e8381..8c9fb5024 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/UtilTests.java
@@ -12,6 +12,7 @@
package org.aspectj.apache.bcel.classfile.tests;
+import org.aspectj.apache.bcel.classfile.ClassFormatException;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.generic.Type;
@@ -24,7 +25,7 @@ public class UtilTests extends TestCase {
}
public void testUtilityClassSignatureManipulation1() {
- String[] ss = Utility.methodSignatureArgumentTypes("(Ljava/lang/String;I[Ljava/lang/Integer;)");
+ String[] ss = UtilTests.methodSignatureArgumentTypes("(Ljava/lang/String;I[Ljava/lang/Integer;)");
assertTrue("should be 3 not "+ss.length,ss.length==3);
assertTrue("first should be 'String', not "+ss[0],ss[0].equals("String"));
@@ -53,6 +54,15 @@ public class UtilTests extends TestCase {
protected void tearDown() throws Exception {
super.tearDown();
}
+
+ /**
+ * @param signature Method signature
+ * @return Array of argument types
+ * @throws ClassFormatException
+ */
+ public static final String[] methodSignatureArgumentTypes(String signature) throws ClassFormatException {
+ return GenericSignatureParsingTest.methodSignatureArgumentTypes(signature, true);
+ }
}
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/VarargsTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/VarargsTest.java
index 52590bf71..a6f8e8021 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/VarargsTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/VarargsTest.java
@@ -18,8 +18,8 @@ import java.util.Iterator;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.annotation.Annotation;
-import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePairGen;
import org.aspectj.apache.bcel.util.SyntheticRepository;
@@ -77,9 +77,9 @@ public class VarargsTest extends BcelTestCase {
// helper methods
- public void checkValue(Annotation a,String name,String tostring) {
+ public void checkValue(AnnotationGen a,String name,String tostring) {
for (Iterator i = a.getValues().iterator(); i.hasNext();) {
- ElementNameValuePair element = (ElementNameValuePair) i.next();
+ ElementNameValuePairGen element = (ElementNameValuePairGen) i.next();
if (element.getNameString().equals(name)) {
if (!element.getValue().stringifyValue().equals(tostring)) {
fail("Expected element "+name+" to have value "+tostring+" but it had value "+element.getValue().stringifyValue());