]> source.dussan.org Git - aspectj.git/commitdiff
256669: itd parameter annotations copied to target
authoraclement <aclement>
Thu, 27 Nov 2008 21:30:49 +0000 (21:30 +0000)
committeraclement <aclement>
Thu, 27 Nov 2008 21:30:49 +0000 (21:30 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java

index adb91f8d9ea65fcdc298843f9b91b358dbb1477c..06c02fb3739985d207158f89cd3b635ebd325f5f 100644 (file)
@@ -374,6 +374,30 @@ class BcelMethod extends ResolvedMemberImpl {
                // method.addAnnotation(annotation.getBcelAnnotation());
        }
 
+       public static final AnnotationAJ[] NO_PARAMETER_ANNOTATIONS = new AnnotationAJ[] {};
+
+       public void addParameterAnnotation(int param, AnnotationAJ anno) {
+               ensureParameterAnnotationsRetrieved();
+               if (parameterAnnotations == NO_PARAMETER_ANNOTATIONXS) {
+                       // First time we've added any, so lets set up the array
+                       parameterAnnotations = new AnnotationAJ[getArity()][];
+                       for (int i = 0; i < getArity(); i++) {
+                               parameterAnnotations[i] = NO_PARAMETER_ANNOTATIONS;
+                       }
+               }
+               int existingCount = parameterAnnotations[param].length;
+               if (existingCount == 0) {
+                       AnnotationAJ[] annoArray = new AnnotationAJ[1];
+                       annoArray[0] = anno;
+                       parameterAnnotations[param] = annoArray;
+               } else {
+                       AnnotationAJ[] newAnnoArray = new AnnotationAJ[existingCount + 1];
+                       System.arraycopy(parameterAnnotations[param], 0, newAnnoArray, 0, existingCount);
+                       newAnnoArray[existingCount] = anno;
+                       parameterAnnotations[param] = newAnnoArray;
+               }
+       }
+
        private void ensureAnnotationsRetrieved() {
                if (method == null)
                        return; // must be ok, we have evicted it
index 7947d526c02ba2336cbd1ac19028ed526e022175..b3f1e9fb26ec54e37610f46579ac2c6ad12e047c 100644 (file)
@@ -786,8 +786,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
 
                        // pr98901
                        // For copying the annotations across, we have to discover the real
-                       // member in the aspect
-                       // which is holding them.
+                       // member in the aspect which is holding them.
                        if (weaver.getWorld().isInJava5Mode()) {
                                AnnotationAJ annotationsOnRealMember[] = null;
                                ResolvedType toLookOn = aspectType;
@@ -807,6 +806,20 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                                newMethod.addAnnotation(new BcelAnnotation(ag, weaver.getWorld()));
                                        }
                                }
+                               AnnotationAJ[][] pAnnos = realMember.getParameterAnnotations();
+                               int offset = newMethod.isStatic() ? 0 : 1;
+                               if (pAnnos != null && pAnnos.length != 0) {
+                                       int param = 0;
+                                       for (int i = offset; i < pAnnos.length; i++) {
+                                               AnnotationAJ[] annosOnParam = pAnnos[i];
+                                               if (annosOnParam != null && annosOnParam.length > 0) {
+                                                       for (int j = 0; j < annosOnParam.length; j++) {
+                                                               newMethod.addParameterAnnotation(param, annosOnParam[j]);
+                                                       }
+                                               }
+                                               param++;
+                                       }
+                               }
                                // the below loop fixes the very special (and very stupid)
                                // case where an aspect declares an annotation
                                // on an ITD it declared on itself.
@@ -914,6 +927,21 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                                        mg.addAnnotation(new BcelAnnotation(ag, weaver.getWorld()));
                                                }
                                        }
+
+                                       AnnotationAJ[][] pAnnos = realMember.getParameterAnnotations();
+                                       int offset = mg.isStatic() ? 0 : 1;
+                                       if (pAnnos != null && pAnnos.length != 0) {
+                                               int param = 0;
+                                               for (int i = offset; i < pAnnos.length; i++) {
+                                                       AnnotationAJ[] annosOnParam = pAnnos[i];
+                                                       if (annosOnParam != null && annosOnParam.length > 0) {
+                                                               for (int j = 0; j < annosOnParam.length; j++) {
+                                                                       mg.addParameterAnnotation(param, annosOnParam[j]);
+                                                               }
+                                                       }
+                                                       param++;
+                                               }
+                                       }
                                }
 
                                if (mungingInterface) {
index 57e1286e1af4a2dfe9e31ed0f562a415232f39c4..7397ddb0aaf4e9216047f79cbe80643f458324ad 100644 (file)
@@ -89,6 +89,7 @@ public final class LazyMethodGen implements Traceable {
        private InstructionList body; // leaving null for abstracts
        private List attributes;
        private List newAnnotations;
+       private AnnotationAJ[][] newParameterAnnotations;
        private final LazyClassGen enclosingClass;
        private BcelMethod memberView;
        private AjAttribute.EffectiveSignatureAttribute effectiveSignature;
@@ -276,6 +277,35 @@ public final class LazyMethodGen implements Traceable {
                }
        }
 
+       private static final AnnotationAJ[] NO_ANNOTATIONAJ = new AnnotationAJ[] {};
+
+       public void addParameterAnnotation(int parameterNumber, AnnotationAJ anno) {
+               initialize();
+               if (memberView == null) {
+                       if (newParameterAnnotations == null) {
+                               // time to create it
+                               int pcount = getArgumentTypes().length;
+                               newParameterAnnotations = new AnnotationAJ[pcount][];
+                               for (int i = 0; i < pcount; i++) {
+                                       if (i == parameterNumber) {
+                                               newParameterAnnotations[i] = new AnnotationAJ[1];
+                                               newParameterAnnotations[i][0] = anno;
+                                       } else {
+                                               newParameterAnnotations[i] = NO_ANNOTATIONAJ;
+                                       }
+                               }
+                       } else {
+                               AnnotationAJ[] currentAnnoArray = newParameterAnnotations[parameterNumber];
+                               AnnotationAJ[] newAnnoArray = new AnnotationAJ[currentAnnoArray.length + 1];
+                               System.arraycopy(currentAnnoArray, 0, newAnnoArray, 0, currentAnnoArray.length);
+                               newAnnoArray[currentAnnoArray.length] = anno;
+                               newParameterAnnotations[parameterNumber] = newAnnoArray;
+                       }
+               } else {
+                       memberView.addParameterAnnotation(parameterNumber, anno);
+               }
+       }
+
        public boolean hasAnnotation(UnresolvedType annotationTypeX) {
                initialize();
                if (memberView == null) {
@@ -898,6 +928,16 @@ public final class LazyMethodGen implements Traceable {
                        }
                }
 
+               if (newParameterAnnotations != null) {
+                       for (int i = 0; i < newParameterAnnotations.length; i++) {
+                               AnnotationAJ[] annos = newParameterAnnotations[i];
+                               for (int j = 0; j < annos.length; j++) {
+                                       gen.addParameterAnnotation(i, new AnnotationGen(((BcelAnnotation) annos[j]).getBcelAnnotation(), gen
+                                                       .getConstantPool(), true));
+                               }
+                       }
+               }
+
                if (memberView != null && memberView.getAnnotations() != null && memberView.getAnnotations().length != 0) {
                        AnnotationAJ[] ans = memberView.getAnnotations();
                        for (int i = 0, len = ans.length; i < len; i++) {