summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-07-01 11:29:54 +0000
committeracolyer <acolyer>2005-07-01 11:29:54 +0000
commit14f1ca3554408b363ac88c7fd708f32b7ed86f89 (patch)
tree545591fe6566e97b851656de241ae028906dd797
parent85ca59ed0b8a0bfe4876d016fcbdf9b0e6d78416 (diff)
downloadaspectj-14f1ca3554408b363ac88c7fd708f32b7ed86f89.tar.gz
aspectj-14f1ca3554408b363ac88c7fd708f32b7ed86f89.zip
signature parsing for methods and fields now complete also
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/classfile/GenericSignatureParser.java5
-rw-r--r--bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java6
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParserTest.java91
3 files changed, 98 insertions, 4 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/GenericSignatureParser.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/GenericSignatureParser.java
index 775a8b930..230a055c1 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/GenericSignatureParser.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/GenericSignatureParser.java
@@ -163,7 +163,6 @@ public class GenericSignatureParser {
private ArrayTypeSignature parseArrayTypeSignature() {
// opening [ already eaten
- eat("["); // grammar adds another one!
FieldTypeSignature fieldType = parseFieldTypeSignature(true);
if (fieldType != null) {
return new ArrayTypeSignature(fieldType);
@@ -273,6 +272,7 @@ public class GenericSignatureParser {
}
private boolean maybeEat(String token) {
+ if (tokenStream.length <= tokenIndex) return false;
if (tokenStream[tokenIndex].equals(token)) {
tokenIndex++;
return true;
@@ -329,6 +329,8 @@ public class GenericSignatureParser {
tokens.add(";");
break;
case '^':
+ if (identifier.length() > 0) tokens.add(identifier.toString());
+ identifier = new StringBuffer();
tokens.add("^");
break;
case '+':
@@ -350,6 +352,7 @@ public class GenericSignatureParser {
break;
case ')' :
tokens.add(")");
+ break;
case '[' :
tokens.add("[");
break;
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java
index c1546fac2..672b1171c 100644
--- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java
+++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java
@@ -71,7 +71,7 @@ import org.aspectj.apache.bcel.Constants;
* This class is derived from <em>Attribute</em> and represents a reference
* to a <href="http://wwwipd.ira.uka.de/~pizza/gj/">GJ</a> attribute.
*
- * @version $Id: Signature.java,v 1.4 2005/07/01 09:10:45 acolyer Exp $
+ * @version $Id: Signature.java,v 1.5 2005/07/01 11:29:54 acolyer Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
@@ -457,7 +457,7 @@ public final class Signature extends Attribute {
}
}
- static class TypeVariableSignature extends FieldTypeSignature {
+ public static class TypeVariableSignature extends FieldTypeSignature {
public String typeVariableName;
public TypeVariableSignature(String typeVarToken) {
this.typeVariableName = typeVarToken.substring(1);
@@ -468,7 +468,7 @@ public final class Signature extends Attribute {
}
}
- static class ArrayTypeSignature extends FieldTypeSignature {
+ public static class ArrayTypeSignature extends FieldTypeSignature {
public TypeSignature typeSig;
public ArrayTypeSignature(TypeSignature aTypeSig) {
this.typeSig = aTypeSig;
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParserTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParserTest.java
index e4d97a818..9833a309c 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParserTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericSignatureParserTest.java
@@ -1,13 +1,18 @@
package org.aspectj.apache.bcel.classfile.tests;
+
import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
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.Signature.ClassSignature;
import org.aspectj.apache.bcel.classfile.Signature.ClassTypeSignature;
import org.aspectj.apache.bcel.classfile.Signature.FieldTypeSignature;
import org.aspectj.apache.bcel.classfile.Signature.SimpleClassTypeSignature;
import org.aspectj.apache.bcel.util.SyntheticRepository;
+import sun.reflect.generics.scope.MethodScope;
+
import junit.framework.TestCase;
public class GenericSignatureParserTest extends TestCase {
@@ -117,6 +122,92 @@ public class GenericSignatureParserTest extends TestCase {
assertEquals("Ljava/lang/String;",fsig.toString());
}
+ public void testFieldSignatureParsingArrayType() {
+ FieldTypeSignature fsig = parser.parseAsFieldSignature("[Ljava/lang/String;");
+ assertTrue("ArrayTypeSignature", fsig instanceof Signature.ArrayTypeSignature);
+ assertEquals("[Ljava/lang/String;",fsig.toString());
+ }
+
+ public void testFieldSignatureParsingTypeVariable() {
+ FieldTypeSignature fsig = parser.parseAsFieldSignature("TT;");
+ assertTrue("TypeVariableSignature",fsig instanceof Signature.TypeVariableSignature);
+ assertEquals("TT;",fsig.toString());
+ }
+
+ public void testSimpleMethodSignatureParsing() {
+ Signature.MethodTypeSignature mSig = parser.parseAsMethodSignature("()V");
+ assertEquals("No type parameters",0,mSig.formalTypeParameters.length);
+ assertEquals("No parameters",0,mSig.parameters.length);
+ assertEquals("Void return type","V",mSig.returnType.toString());
+ assertEquals("No throws",0,mSig.throwsSignatures.length);
+ }
+
+ public void testMethodSignatureTypeParams() {
+ Signature.MethodTypeSignature mSig = parser.parseAsMethodSignature("<T:>(TT;)V");
+ assertEquals("One type parameter",1,mSig.formalTypeParameters.length);
+ assertEquals("T",mSig.formalTypeParameters[0].identifier);
+ assertEquals("Ljava/lang/Object;",mSig.formalTypeParameters[0].classBound.toString());
+ assertEquals("One parameter",1,mSig.parameters.length);
+ assertEquals("TT;",mSig.parameters[0].toString());
+ assertEquals("Void return type","V",mSig.returnType.toString());
+ assertEquals("No throws",0,mSig.throwsSignatures.length);
+ }
+
+ public void testMethodSignatureGenericReturn() {
+ Signature.MethodTypeSignature mSig = parser.parseAsMethodSignature("<T:>()TT;");
+ assertEquals("One type parameter",1,mSig.formalTypeParameters.length);
+ assertEquals("T",mSig.formalTypeParameters[0].identifier);
+ assertEquals("Ljava/lang/Object;",mSig.formalTypeParameters[0].classBound.toString());
+ assertEquals("No parameters",0,mSig.parameters.length);
+ assertEquals("'T' return type","TT;",mSig.returnType.toString());
+ assertEquals("No throws",0,mSig.throwsSignatures.length);
+ }
+
+ public void testMethodSignatureThrows() {
+ Signature.MethodTypeSignature mSig = parser.parseAsMethodSignature("<T:>(TT;)V^Ljava/lang/Exception;^Ljava/lang/RuntimeException;");
+ assertEquals("One type parameter",1,mSig.formalTypeParameters.length);
+ assertEquals("T",mSig.formalTypeParameters[0].identifier);
+ assertEquals("Ljava/lang/Object;",mSig.formalTypeParameters[0].classBound.toString());
+ assertEquals("One parameter",1,mSig.parameters.length);
+ assertEquals("TT;",mSig.parameters[0].toString());
+ assertEquals("Void return type","V",mSig.returnType.toString());
+ assertEquals("2 throws",2,mSig.throwsSignatures.length);
+ assertEquals("Ljava/lang/Exception;",mSig.throwsSignatures[0].toString());
+ assertEquals("Ljava/lang/RuntimeException;",mSig.throwsSignatures[1].toString());
+ }
+
+ public void testMethodSignatureParsingInJDK() throws Exception{
+ SyntheticRepository repository = SyntheticRepository.getInstance();
+ String[] testClasses = new String[] {
+ "java.lang.Comparable",
+ "java.lang.Iterable",
+ "java.lang.Class",
+ "java.lang.Enum",
+ "java.lang.InheritableThreadLocal",
+ "java.lang.ThreadLocal",
+ "java.util.Collection",
+ "java.util.Comparator",
+ "java.util.Enumeration",
+ "java.util.Iterator",
+ "java.util.List",
+ "java.util.ListIterator",
+ "java.util.Map",
+ "java.util.Map$Entry",
+ "java.util.Queue",
+ "java.util.Set",
+ "java.util.SortedMap",
+ "java.util.SortedSet"
+ };
+ for (int i = 0; i < testClasses.length; i++) {
+ JavaClass jc = repository.loadClass(testClasses[i]);
+ Method[] methods = jc.getMethods();
+ for (int j = 0; j < methods.length; j++) {
+ String sig = methods[j].getGenericSignature();
+ if (sig != null) parser.parseAsMethodSignature(sig);
+ }
+ }
+ }
+
private void assertEquals(String[] expected, String[] actual) {
if (actual.length != expected.length) {
int shorter = Math.min(expected.length,actual.length);