]> source.dussan.org Git - aspectj.git/commitdiff
proper implementation of canBeParameterized
authoracolyer <acolyer>
Fri, 8 Jul 2005 10:24:19 +0000 (10:24 +0000)
committeracolyer <acolyer>
Fri, 8 Jul 2005 10:24:19 +0000 (10:24 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java

index 376ee1e145162b22ab1535796b1c5e17a4887720..d540a1c83aee131780b10642bef5e9fbe892eac2 100644 (file)
@@ -16,11 +16,15 @@ package org.aspectj.weaver.bcel;
 import java.lang.reflect.Modifier;
 import java.util.Iterator;
 import java.util.List;
+import java.util.StringTokenizer;
 
 import org.aspectj.apache.bcel.classfile.ExceptionTable;
+import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
 import org.aspectj.apache.bcel.classfile.LocalVariable;
 import org.aspectj.apache.bcel.classfile.LocalVariableTable;
 import org.aspectj.apache.bcel.classfile.Method;
+import org.aspectj.apache.bcel.classfile.Signature;
+import org.aspectj.apache.bcel.classfile.Signature.TypeVariableSignature;
 import org.aspectj.apache.bcel.classfile.annotation.Annotation;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.SourceLocation;
@@ -231,4 +235,39 @@ final class BcelMethod extends ResolvedMember {
                        }
        }
        }
+        
+
+        private boolean canBeParameterized = false;
+        private boolean calculatedParameterization = false;
+        /**
+         * A method can be parameterized if it has one or more generic
+         * parameters. A generic parameter (type variable parameter) is
+         * identified by the prefix "T"
+         */
+        public boolean canBeParameterized() {
+               if (calculatedParameterization) return canBeParameterized;
+               
+               String fullSignature = method.getGenericSignature();
+               if (fullSignature == null) {
+                       canBeParameterized = false;
+               } else {
+                       Signature.MethodTypeSignature mtSig = new GenericSignatureParser().parseAsMethodSignature(fullSignature);
+                       if (mtSig.formalTypeParameters.length > 0) {
+                               // generic method declaration
+                               canBeParameterized = true;
+                       } else {
+                               // might be method with generic parameters declared in generic type
+                               Signature.TypeSignature[] params = mtSig.parameters;
+                               for (int i = 0; i < params.length; i++) {
+                                       if (params[i] instanceof TypeVariableSignature) {
+                                               canBeParameterized = true;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+               
+               calculatedParameterization = true;
+               return canBeParameterized;
+       }
 }