]> source.dussan.org Git - aspectj.git/commitdiff
#107953 @AfterThrowing/Returning checks when extra formal is not bound
authoravasseur <avasseur>
Wed, 28 Sep 2005 12:50:29 +0000 (12:50 +0000)
committeravasseur <avasseur>
Wed, 28 Sep 2005 12:50:29 +0000 (12:50 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java

index 4f0106fb62bcfc78b471bb39bcd4762c7e64d27f..3bec1549fe78090701e54e20ee19eac69f136ff4 100644 (file)
@@ -13,6 +13,8 @@ package org.aspectj.ajdt.internal.compiler.ast;
 
 import java.lang.reflect.Modifier;
 import java.util.Stack;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseScope;
@@ -305,15 +307,13 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
                        String thrownFormal = getStringLiteralFor("throwing",ajAnnotations.adviceAnnotation,throwingLocation);
                        if (thrownFormal != null) {
                                Argument[] arguments = methodDeclaration.arguments;
-                               if (arguments != null && arguments.length > 0) {
-                                       Argument lastArgument = arguments[arguments.length - 1];
-                                       if (!thrownFormal.equals(new String(lastArgument.name))) {
+                               if (methodDeclaration.arguments != null
+                        && !toArgumentNames(methodDeclaration.arguments).contains(thrownFormal)) {
                                                methodDeclaration.scope.problemReporter()
-                                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"throwing formal '" + thrownFormal + "' must be declared as the last parameter in the advice signature");
-                                       }
+                                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"throwing formal '" + thrownFormal + "' must be declared as a parameter in the advice signature");
                                } else {
                                        methodDeclaration.scope.problemReporter()
-                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"throwing formal '" + thrownFormal + "' must be declared as the last parameter in the advice signature");
+                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"throwing formal '" + thrownFormal + "' must be declared as a parameter in the advice signature");
                                }
                        }
                }
@@ -322,16 +322,13 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
                        int[] throwingLocation = new int[2];
                        String returningFormal = getStringLiteralFor("returning",ajAnnotations.adviceAnnotation,throwingLocation);
                        if (returningFormal != null) {
-                               Argument[] arguments = methodDeclaration.arguments;
-                               if (arguments != null && arguments.length > 0) {
-                                       Argument lastArgument = arguments[arguments.length - 1];
-                                       if (!returningFormal.equals(new String(lastArgument.name))) {
+                               if (methodDeclaration.arguments.length > 0
+                        && !toArgumentNames(methodDeclaration.arguments).contains(returningFormal)) {
                                                methodDeclaration.scope.problemReporter()
-                                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"returning formal '" + returningFormal + "' must be declared as the last parameter in the advice signature");
-                                       }
+                                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"returning formal '" + returningFormal + "' must be declared as a parameter in the advice signature");
                                } else {
                                        methodDeclaration.scope.problemReporter()
-                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"returning formal '" + returningFormal + "' must be declared as the last parameter in the advice signature");
+                                       .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"returning formal '" + returningFormal + "' must be declared as a parameter in the advice signature");
                                }
                        }
                }
@@ -340,7 +337,24 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
                
        }
 
-       private void resolveAndSetPointcut(MethodDeclaration methodDeclaration, Annotation adviceAnn) {
+    /**
+     * Get the argument names as a string list
+     * @param arguments
+     * @return argument names (possibly empty)
+     */
+    private List toArgumentNames(Argument[] arguments) {
+        List names = new ArrayList();
+        if (arguments == null) {
+            return names;
+        } else {
+            for (int i = 0; i < arguments.length; i++) {
+                names.add(new String(arguments[i].name));
+            }
+            return names;
+        }
+    }
+
+    private void resolveAndSetPointcut(MethodDeclaration methodDeclaration, Annotation adviceAnn) {
                int[] pcLocation = new int[2];
                String pointcutExpression = getStringLiteralFor("pointcut",adviceAnn,pcLocation);
                if (pointcutExpression == null) pointcutExpression = getStringLiteralFor("value",adviceAnn,pcLocation);
index 2896d9dc650068697efbd927ebcb64e34e563947..98d9d96329bac9bb715d26d5c3a6aaa65492ac20 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Arrays;
 
 import org.aspectj.apache.bcel.Constants;
 import org.aspectj.apache.bcel.classfile.Attribute;
@@ -717,10 +718,9 @@ public class AtAjAttributes {
                 } else {
                        // check that thrownFormal exists as the last parameter in the advice
                        String[] pNames = owningMethod.getParameterNames();
-                       if (pNames == null || pNames.length == 0 || !pNames[pNames.length -1].equals(returned)) {
-                               throw new ReturningFormalNotDeclaredInAdviceSignatureException(returned);
-                       }
-                       
+                    if (pNames == null || pNames.length == 0 || !Arrays.asList(pNames).contains(returned)) {
+                        throw new ReturningFormalNotDeclaredInAdviceSignatureException(returned);
+                    }
                 }
             }
 
@@ -815,7 +815,7 @@ public class AtAjAttributes {
                 } else {
                        // check that thrownFormal exists as the last parameter in the advice
                        String[] pNames = owningMethod.getParameterNames();
-                       if (pNames == null || pNames.length == 0 || !pNames[pNames.length -1].equals(thrownFormal)) {
+                       if (pNames == null || pNames.length == 0 || !Arrays.asList(pNames).contains(thrownFormal)) {
                                throw new ThrownFormalNotDeclaredInAdviceSignatureException(thrownFormal);
                        }
                 }