]> source.dussan.org Git - aspectj.git/commitdiff
fix for parameterizing reference pointcuts with bindings
authoracolyer <acolyer>
Thu, 24 Nov 2005 11:05:03 +0000 (11:05 +0000)
committeracolyer <acolyer>
Thu, 24 Nov 2005 11:05:03 +0000 (11:05 +0000)
tests/java5/generics/genericaspects/GenericAspectY.aj
weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java
weaver/src/org/aspectj/weaver/ResolvedPointcutDefinition.java
weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java

index b677c3f10ce2db306062fc6a546aff0f1d0988b5..c863fcf411baffcbb83fdbb27800da344fb2a19f 100644 (file)
@@ -98,7 +98,7 @@ import org.aspectj.lang.annotation.*;
 aspect GenericAspectX extends ParentChildRelationship<Top,Bottom> { 
 
     // Advice to trigger weave infos
-       before(Top p): ParentChildRelationship.addingChildSimple(p) {}
+       before(Top p): /*ParentChildRelationship.*/addingChildSimple(p) {}
        
 //    before(Top p,Bottom c): ParentChildRelationship.addingChild(p,c) {}
 //    before(Top p,Bottom c): ParentChildRelationship.removingChild(p,c) {}
index 7bf91ef84a3fea5729a301b54c027df37537a9fc..4a3d6ebc8943c02df687838bcd415ec65e4cb6a4 100644 (file)
@@ -661,9 +661,9 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                return typeVariables;
        }
        
-       private UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType) {
-               if (aType instanceof TypeVariableReferenceType) {
-                       String variableName = ((TypeVariableReferenceType)aType).getTypeVariable().getName();
+       protected UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType) {
+               if (aType instanceof TypeVariableReference) {
+                       String variableName = ((TypeVariableReference)aType).getTypeVariable().getName();
                        if (!typeVariableMap.containsKey(variableName)) {
                                return aType; // if the type variable comes from the method (and not the type) thats OK
                        }
index 8183ceb2400366f726ee21628daae87293d40672..cf3d5967ddbfa748005c9f225340fcd65a3462e8 100644 (file)
@@ -15,6 +15,8 @@ package org.aspectj.weaver;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.aspectj.weaver.patterns.Pointcut;
 
@@ -113,6 +115,39 @@ public class ResolvedPointcutDefinition extends ResolvedMemberImpl {
         * Called when asking a parameterized super-aspect for its pointcuts.
         */
        public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, boolean isParameterized) {
+               TypeVariable[] typeVariables = getDeclaringType().getTypeVariables();
+               if (isParameterized && (typeVariables.length != typeParameters.length)) {
+                       throw new IllegalStateException("Wrong number of type parameters supplied");
+               }
+               Map typeMap = new HashMap();
+               boolean typeParametersSupplied = typeParameters!=null && typeParameters.length>0;
+               if (typeVariables!=null) {
+                       // If no 'replacements' were supplied in the typeParameters array then collapse
+                       // type variables to their first bound.
+                       for (int i = 0; i < typeVariables.length; i++) {
+                               UnresolvedType ut = (!typeParametersSupplied?typeVariables[i].getFirstBound():typeParameters[i]);
+                               typeMap.put(typeVariables[i].getName(),ut);
+                       }
+               }
+               UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(),typeMap,isParameterized);
+               UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length];
+               for (int i = 0; i < parameterizedParameterTypes.length; i++) {
+                       parameterizedParameterTypes[i] = 
+                               parameterize(getGenericParameterTypes()[i], typeMap,isParameterized);
+               }
+               ResolvedPointcutDefinition ret = new ResolvedPointcutDefinition(
+                                       newDeclaringType,
+                                       getModifiers(),
+                                       getName(),
+                                       parameterizedParameterTypes,
+                                       parameterizedReturnType,
+                                       pointcut.parameterizeWith(typeMap)
+                               );
+               ret.setTypeVariables(getTypeVariables());
+               ret.setSourceContext(getSourceContext());
+               ret.setPosition(getStart(),getEnd());
+               ret.setParameterNames(getParameterNames());
+               //return ret;
                return this;
        }
        
index 6d99ae26179d18a89aec8ba3e760cbbc5729a567..2f2c965a4b6e6ca32abb98db441958a8e05417ff 100644 (file)
@@ -164,7 +164,7 @@ public class ReferencePointcut extends Pointcut {
                if (pointcutDef == null) {
                        scope.message(IMessage.ERROR, this, "can't find referenced pointcut " + name);
                        return;
-               }
+               } 
                
                // check visibility
                if (!pointcutDef.isVisible(scope.getEnclosingType())) {
@@ -193,12 +193,30 @@ public class ReferencePointcut extends Pointcut {
                                                parameterTypes.length + " found " + arguments.size());
                        return;
                }
-               
-               
+                               
+               if (onType != null) {
+                       if (onType.isParameterizedType()) {
+                               // build a type map mapping type variable names in the generic type to
+                               // the type parameters presented
+                               typeVariableMap = new HashMap();
+                               ResolvedType underlyingGenericType = ((ResolvedType) onType).getGenericType();
+                               TypeVariable[] tVars = underlyingGenericType.getTypeVariables();
+                               ResolvedType[] typeParams = ((ResolvedType)onType).getResolvedTypeParameters();
+                               for (int i = 0; i < tVars.length; i++) {
+                                       typeVariableMap.put(tVars[i].getName(),typeParams[i]);
+                               }
+                       } else if (onType.isGenericType()) {
+                               scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.CANT_REFERENCE_POINTCUT_IN_RAW_TYPE),
+                                               getSourceLocation()));
+                       }
+               }
                
                for (int i=0,len=arguments.size(); i < len; i++) {
                        TypePattern p = arguments.get(i);
                        //we are allowed to bind to pointcuts which use subtypes as this is type safe
+                       if (typeVariableMap != null) {
+                               p = p.parameterizeWith(typeVariableMap);
+                       }
                        if (p == TypePattern.NO) {
                                scope.message(IMessage.ERROR, this,
                                                                "bad parameter to pointcut reference");
@@ -212,23 +230,7 @@ public class ReferencePointcut extends Pointcut {
                                return;
                        }
                }
-               
-               if (onType != null) {
-                       if (onType.isParameterizedType()) {
-                               // build a type map mapping type variable names in the generic type to
-                               // the type parameters presented
-                               typeVariableMap = new HashMap();
-                               ResolvedType underlyingGenericType = ((ResolvedType) onType).getGenericType();
-                               TypeVariable[] tVars = underlyingGenericType.getTypeVariables();
-                               ResolvedType[] typeParams = ((ResolvedType)onType).getResolvedTypeParameters();
-                               for (int i = 0; i < tVars.length; i++) {
-                                       typeVariableMap.put(tVars[i].getName(),typeParams[i]);
-                               }
-                       } else if (onType.isGenericType()) {
-                               scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.CANT_REFERENCE_POINTCUT_IN_RAW_TYPE),
-                                               getSourceLocation()));
-                       }
-               }
+
        }
        
        public void postRead(ResolvedType enclosingType) {