From: acolyer Date: Tue, 29 Nov 2005 20:44:02 +0000 (+0000) Subject: when generating advice annotations, populate the argNames attribute X-Git-Tag: V1_5_0RC1~85 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7cf0d6499ce9894015f192adb68cac3e5501148f;p=aspectj.git when generating advice annotations, populate the argNames attribute --- diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java index 35ea7c5d3..0824480aa 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java @@ -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; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java index 35fccc856..bd0eb825f 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java @@ -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) {