]> source.dussan.org Git - aspectj.git/commitdiff
support for generics and type variables
authoracolyer <acolyer>
Fri, 8 Jul 2005 10:25:01 +0000 (10:25 +0000)
committeracolyer <acolyer>
Fri, 8 Jul 2005 10:25:01 +0000 (10:25 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java

index 21f3d766a940527151c1de83959d4084751a2016..0ce8c6e32954faa12766b27eb8ac49dd04248609 100644 (file)
@@ -38,9 +38,11 @@ import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedPointcutDefinition;
 import org.aspectj.weaver.ResolvedTypeX;
+import org.aspectj.weaver.TypeVariable;
 import org.aspectj.weaver.TypeX;
 import org.aspectj.weaver.WeaverStateInfo;
 import org.aspectj.weaver.AjcMemberMaker;
+import org.aspectj.weaver.World;
 import org.aspectj.weaver.patterns.PerClause;
 
 
@@ -57,6 +59,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
     private ResolvedMember[] methods = null;
     private ResolvedTypeX[] annotationTypes = null;
     private AnnotationX[] annotations = null;
+    private TypeVariable[] typeVars = null;
 
     // track unpackAttribute. In some case (per clause inheritance) we encounter
     // unpacked state when calling getPerClause
@@ -121,6 +124,32 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        resetState();
     }
     
+    /**
+     * Return true if this is a generic type (has one or more type variables
+     * in its signature).
+     */
+    public boolean isGeneric() {
+       return javaClass.getGenericSignature() != null;
+    }
+    
+    
+    public TypeVariable[] getTypeVariables() {
+       if (!isGeneric()) return new TypeVariable[0];
+       
+       if (typeVars == null) {
+               Signature.ClassSignature classSig = javaClass.getGenericClassTypeSignature();
+               typeVars = new TypeVariable[classSig.formalTypeParameters.length];
+               for (int i = 0; i < typeVars.length; i++) {
+                               Signature.FormalTypeParameter ftp = classSig.formalTypeParameters[i];
+                               typeVars[i] = BcelGenericSignatureToTypeXConverter.formalTypeParameter2TypeVariable(
+                                               ftp, 
+                                               classSig.formalTypeParameters,
+                                               getResolvedTypeX().getWorld());
+                       }
+       }
+       return typeVars;
+    }
+    
     public int getModifiers() {
         return javaClass.getAccessFlags();
     }