View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    * 
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    * 
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.guard;
14  
15  import org.aspectj.lang.annotation.Aspect;
16  import org.aspectj.lang.annotation.DeclareWarning;
17  
18  /**
19   * This is an annotations based version of the ApiUsageAuditor aspect
20   *
21   * @author Sebastian Thomschke
22   */
23  @Aspect
24  public abstract class ApiUsageAuditor2
25  {
26  	/*
27  	 * Rule 1: Warn about return value constraints for void methods 
28  	 */
29  	@DeclareWarning("execution(@(@net.sf.oval.configuration.annotation.Constraint *) void *.*(..))")
30  	public static final String RULE1 = "OVal API usage violation 1: Method return value constraints are not allowed for methods without return values";
31  
32  	/*
33  	 * Rule 2: Warn about return value constraints for non-void, parameterized methods in classes that are not guarded 
34  	 */
35  	@DeclareWarning("execution(@(@net.sf.oval.configuration.annotation.Constraint *) !void (!@net.sf.oval.guard.Guarded *).*(*,..))")
36  	public static final String RULE2 = "OVal API usage violation 2: Method return value constraints for parameterized methods are only allowed in guarded classes";
37  
38  	/*
39  	 * Rule 3: Warn about return value constraints for non-void, non-parameterized methods missing the @Invariant annotation in classes 
40  	 * that are not guarded
41  	 */
42  	@DeclareWarning("execution(!@net.sf.oval.configuration.annotation.IsInvariant @(@net.sf.oval.configuration.annotation.Constraint *) !void (!@net.sf.oval.guard.Guarded *).*())")
43  	public static final String RULE3 = "OVal API usage violation 3: Method return value constraints are only allowed if the method is annotated with @IsInvariant or the declaring class is guarded";
44  
45  	/*
46  	 * Rule 4: Warn about the @PreValidateThis annotation used on methods in classes that are not guarded
47  	 */
48  	@DeclareWarning("execution (@net.sf.oval.guard.PreValidateThis * (!@net.sf.oval.guard.Guarded *).*(..))")
49  	public static final String RULE4 = "OVal API usage violation 4: @PreValidateThis is only allowed in guarded classes";
50  
51  	/*
52  	 * Rule 5: Warn about the @PostValidateObject annotation used on methods and constructors in classes not annotated with @Guarded
53  	 */
54  	@DeclareWarning("execution (@net.sf.oval.guard.PostValidateThis * (!@net.sf.oval.guard.Guarded *).*(..)) || execution (@net.sf.oval.guard.PostValidateObject (!@net.sf.oval.guard.Guarded *).new(..))")
55  	public static final String RULE5 = "OVal API usage violation 5: @PostValidateThis is only allowed in guarded classes";
56  
57  	/*
58  	 * Rule 6: Warn about method parameter constraints in classes that are not guarded
59  	 */
60  	@DeclareWarning("execution(* (!@net.sf.oval.guard.Guarded *).*(@(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution(* (!@net.sf.oval.guard.Guarded *).*(*, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution(* (!@net.sf.oval.guard.Guarded *).*(*, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution(* (!@net.sf.oval.guard.Guarded *).*(*, *, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution(* (!@net.sf.oval.guard.Guarded *).*(*, *, *, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution(* (!@net.sf.oval.guard.Guarded *).*(*, *, *, *, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..))")
61  	public static final String RULE6 = "OVal API usage violation 6: Method parameter constraints are only allowed in guarded classes";
62  
63  	/*
64  	 * Rule 7: Warn about constructor parameter constraints in classes that are not guarded
65  	 */
66  	@DeclareWarning("execution((!@net.sf.oval.guard.Guarded *).new(@(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution((!@net.sf.oval.guard.Guarded *).new(*, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution((!@net.sf.oval.guard.Guarded *).new(*, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution((!@net.sf.oval.guard.Guarded *).new(*, *, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution((!@net.sf.oval.guard.Guarded *).new(*, *, *, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..)) || execution((!@net.sf.oval.guard.Guarded *).new(*, *, *, *, *, @(@net.sf.oval.configuration.annotation.Constraint *) *, ..))")
67  	public static final String RULE7 = "OVal API usage violation 7: Method parameter constraints are only allowed in guarded classes";
68  
69  }