diff options
author | Andy Clement <aclement@pivotal.io> | 2022-01-17 17:47:37 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2022-01-17 17:47:37 -0800 |
commit | b720626100766ec0c34985404d774eccb51efdc0 (patch) | |
tree | e3310ac13761767f646fa4690a4f9e2e591870d3 /org.aspectj.ajdt.core | |
parent | 08414a740dc00b3b3d08fc01e2d1a5b947395a45 (diff) | |
download | aspectj-b720626100766ec0c34985404d774eccb51efdc0.tar.gz aspectj-b720626100766ec0c34985404d774eccb51efdc0.zip |
Fix annotation style support for if(true) and if(false)
The documentation specifies annotation style pointcuts
can use if(false) or if(true) and not require a boolean
return value and body for the @Pointcut annotated
method but it doesn't work without this change to validation
that recognizes the situation.
Fixes #115
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r-- | org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java index 285f6f5bf..a6cc3c19f 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java @@ -528,6 +528,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { boolean noValueSupplied = true; boolean containsIfPcd = false; + boolean isIfTrueOrFalse = false; int[] pcLocation = new int[2]; String pointcutExpression = getStringLiteralFor("value", ajAnnotations.pointcutAnnotation, pcLocation); try { @@ -538,6 +539,11 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { } else { noValueSupplied = false; pc = new PatternParser(pointcutExpression, context).parsePointcut(); + if (pc instanceof IfPointcut) { + if (((IfPointcut)pc).alwaysFalse() || ((IfPointcut)pc).alwaysTrue()) { + isIfTrueOrFalse = true; + } + } } pcDecl.pointcutDesignator = (pc == null) ? null : new PointcutDesignator(pc); pcDecl.setGenerateSyntheticPointcutMethod(); @@ -592,10 +598,10 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { methodDeclaration.returnType.sourceEnd, "Methods annotated with @Pointcut must return void unless the pointcut contains an if() expression"); } - if (!returnsBoolean && containsIfPcd) { + if (!returnsBoolean && containsIfPcd && !isIfTrueOrFalse) { methodDeclaration.scope.problemReporter().signalError(methodDeclaration.returnType.sourceStart, methodDeclaration.returnType.sourceEnd, - "Methods annotated with @Pointcut must return boolean when the pointcut contains an if() expression"); + "Methods annotated with @Pointcut must return boolean when the pointcut contains an if() expression unless it is if(false) or if(true)"); } if (methodDeclaration.statements != null && methodDeclaration.statements.length > 0 && !containsIfPcd) { |