]> source.dussan.org Git - aspectj.git/commitdiff
when generating advice annotations, populate the argNames attribute
authoracolyer <acolyer>
Tue, 29 Nov 2005 20:44:02 +0000 (20:44 +0000)
committeracolyer <acolyer>
Tue, 29 Nov 2005 20:44:02 +0000 (20:44 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java

index 35ea7c5d3f3956089bc21e3434873508e006672a..0824480aaec2266bd931cc1ec4c30fc47b5b3b1f 100644 (file)
@@ -285,21 +285,38 @@ public class AdviceDeclaration extends AjMethodDeclaration {
                if (extraArgument != null) {
                        extraArgumentName = new String(extraArgument.name);
                }
+               String argNames = buildArgNameRepresentation();
                
                if (kind == AdviceKind.Before) {
-                       adviceAnnotation = AtAspectJAnnotationFactory.createBeforeAnnotation(pointcutExpression,declarationSourceStart);
+                       adviceAnnotation = AtAspectJAnnotationFactory.createBeforeAnnotation(pointcutExpression,argNames,declarationSourceStart);
                } else if (kind == AdviceKind.After) {
-                       adviceAnnotation = AtAspectJAnnotationFactory.createAfterAnnotation(pointcutExpression,declarationSourceStart);                 
+                       adviceAnnotation = AtAspectJAnnotationFactory.createAfterAnnotation(pointcutExpression,argNames,declarationSourceStart);                        
                } else if (kind == AdviceKind.AfterReturning) {
-                       adviceAnnotation = AtAspectJAnnotationFactory.createAfterReturningAnnotation(pointcutExpression,extraArgumentName,declarationSourceStart);
+                       adviceAnnotation = AtAspectJAnnotationFactory.createAfterReturningAnnotation(pointcutExpression,argNames,extraArgumentName,declarationSourceStart);
                } else if (kind == AdviceKind.AfterThrowing) {
-                       adviceAnnotation = AtAspectJAnnotationFactory.createAfterThrowingAnnotation(pointcutExpression,extraArgumentName,declarationSourceStart);
+                       adviceAnnotation = AtAspectJAnnotationFactory.createAfterThrowingAnnotation(pointcutExpression,argNames,extraArgumentName,declarationSourceStart);
                } else if (kind == AdviceKind.Around) {
-                       adviceAnnotation = AtAspectJAnnotationFactory.createAroundAnnotation(pointcutExpression,declarationSourceStart);
+                       adviceAnnotation = AtAspectJAnnotationFactory.createAroundAnnotation(pointcutExpression,argNames,declarationSourceStart);
                }
                AtAspectJAnnotationFactory.addAnnotation(this, adviceAnnotation,this.scope);
        }
        
+       private String buildArgNameRepresentation() {
+               StringBuffer args = new StringBuffer();
+               int numArgsWeCareAbout = getDeclaredParameterCount();
+               if (this.arguments != null) {
+                       for (int i = 0; i < numArgsWeCareAbout; i++) {
+                               if (i != 0) args.append(",");
+                               args.append(new String(this.arguments[i].name));
+                       }
+               }
+               if (extraArgument != null) {
+                       if (numArgsWeCareAbout > 0) { args.append(","); }
+                       args.append(new String(extraArgument.name));
+               }
+               return args.toString();
+       }
+       
        // override, Called by ClassScope.postParse
        public void postParse(TypeDeclaration typeDec) {
                AspectDeclaration aspectDecl = (AspectDeclaration)typeDec;
index 35fccc8569f7b919d13fe71762ed7a87367e32a6..bd0eb825fcf90f7a633097aebdbb012b15e69364 100644 (file)
@@ -79,47 +79,78 @@ public class AtAspectJAnnotationFactory {
                return ann;
        }
 
-       public static Annotation createBeforeAnnotation(String pointcutExpression, int pos) {
+       public static Annotation createBeforeAnnotation(String pointcutExpression, String argNames, int pos) {
                char[][] typeName = new char[][] {org,aspectj,lang,annotation,before};
-               return makeSingleStringMemberAnnotation(typeName, pos, pointcutExpression);
+               long[] positions = new long[] {pos,pos,pos,pos,pos};
+               TypeReference annType = new QualifiedTypeReference(typeName,positions);
+               NormalAnnotation ann = new NormalAnnotation(annType,pos);
+               Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos);
+               MemberValuePair[] mvps = new MemberValuePair[2];
+               mvps[0] = new MemberValuePair("value".toCharArray(),pos,pos,pcExpr);
+               Expression argNamesExpr = new StringLiteral(argNames.toCharArray(),pos,pos);
+               mvps[1] = new MemberValuePair("argNames".toCharArray(),pos,pos,argNamesExpr);
+               ann.memberValuePairs = mvps;
+               return ann;
        }
 
-       public static Annotation createAfterAnnotation(String pointcutExpression, int pos) {
+       public static Annotation createAfterAnnotation(String pointcutExpression, String argNames, int pos) {
                char[][] typeName = new char[][] {org,aspectj,lang,annotation,after};
-               return makeSingleStringMemberAnnotation(typeName, pos, pointcutExpression);
+               long[] positions = new long[] {pos,pos,pos,pos,pos};
+               TypeReference annType = new QualifiedTypeReference(typeName,positions);
+               NormalAnnotation ann = new NormalAnnotation(annType,pos);
+               Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos);
+               MemberValuePair[] mvps = new MemberValuePair[2];
+               mvps[0] = new MemberValuePair("value".toCharArray(),pos,pos,pcExpr);
+               Expression argNamesExpr = new StringLiteral(argNames.toCharArray(),pos,pos);
+               mvps[1] = new MemberValuePair("argNames".toCharArray(),pos,pos,argNamesExpr);
+               ann.memberValuePairs = mvps;
+               return ann;
        }
 
-       public static Annotation createAfterReturningAnnotation(String pointcutExpression, String extraArgumentName, int pos) {
+       public static Annotation createAfterReturningAnnotation(String pointcutExpression,  String argNames, String extraArgumentName, int pos) {
                char[][] typeName = new char[][] {org,aspectj,lang,annotation,afterReturning};
                long[] positions = new long[] {pos,pos,pos,pos,pos};
                TypeReference annType = new QualifiedTypeReference(typeName,positions);
                NormalAnnotation ann = new NormalAnnotation(annType,pos);
                Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos);
-               MemberValuePair[] mvps = new MemberValuePair[2];
+               MemberValuePair[] mvps = new MemberValuePair[3];
                mvps[0] = new MemberValuePair("pointcut".toCharArray(),pos,pos,pcExpr);
                Expression argExpr = new StringLiteral(extraArgumentName.toCharArray(),pos,pos);
                mvps[1] = new MemberValuePair("returning".toCharArray(),pos,pos,argExpr);
+               Expression argNamesExpr = new StringLiteral(argNames.toCharArray(),pos,pos);
+               mvps[2] = new MemberValuePair("argNames".toCharArray(),pos,pos,argNamesExpr);
                ann.memberValuePairs = mvps;
                return ann;
        }
 
-       public static Annotation createAfterThrowingAnnotation(String pointcutExpression, String extraArgumentName, int pos) {
+       public static Annotation createAfterThrowingAnnotation(String pointcutExpression, String argNames, String extraArgumentName, int pos) {
                char[][] typeName = new char[][] {org,aspectj,lang,annotation,afterThrowing};
                long[] positions = new long[] {pos,pos,pos,pos,pos};
                TypeReference annType = new QualifiedTypeReference(typeName,positions);
                NormalAnnotation ann = new NormalAnnotation(annType,pos);
                Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos);
-               MemberValuePair[] mvps = new MemberValuePair[2];
+               MemberValuePair[] mvps = new MemberValuePair[3];
                mvps[0] = new MemberValuePair("pointcut".toCharArray(),pos,pos,pcExpr);
                Expression argExpr = new StringLiteral(extraArgumentName.toCharArray(),pos,pos);
                mvps[1] = new MemberValuePair("throwing".toCharArray(),pos,pos,argExpr);
+               Expression argNamesExpr = new StringLiteral(argNames.toCharArray(),pos,pos);
+               mvps[2] = new MemberValuePair("argNames".toCharArray(),pos,pos,argNamesExpr);
                ann.memberValuePairs = mvps;
                return ann;
        }
 
-       public static Annotation createAroundAnnotation(String pointcutExpression, int pos) {
+       public static Annotation createAroundAnnotation(String pointcutExpression, String argNames, int pos) {
                char[][] typeName = new char[][] {org,aspectj,lang,annotation,around};
-               return makeSingleStringMemberAnnotation(typeName, pos, pointcutExpression);
+               long[] positions = new long[] {pos,pos,pos,pos,pos};
+               TypeReference annType = new QualifiedTypeReference(typeName,positions);
+               NormalAnnotation ann = new NormalAnnotation(annType,pos);
+               Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos);
+               MemberValuePair[] mvps = new MemberValuePair[2];
+               mvps[0] = new MemberValuePair("value".toCharArray(),pos,pos,pcExpr);
+               Expression argNamesExpr = new StringLiteral(argNames.toCharArray(),pos,pos);
+               mvps[1] = new MemberValuePair("argNames".toCharArray(),pos,pos,argNamesExpr);
+               ann.memberValuePairs = mvps;
+               return ann;
        }
 
        public static Annotation createPointcutAnnotation(String pointcutExpression, String argNames, int pos) {