001 /******************************************************************************* 002 * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian 003 * Thomschke. 004 * 005 * All Rights Reserved. This program and the accompanying materials 006 * are made available under the terms of the Eclipse Public License v1.0 007 * which accompanies this distribution, and is available at 008 * http://www.eclipse.org/legal/epl-v10.html 009 * 010 * Contributors: 011 * Sebastian Thomschke - initial implementation. 012 *******************************************************************************/ 013 package net.sf.oval.guard; 014 015 import org.aspectj.lang.annotation.Aspect; 016 import org.aspectj.lang.annotation.DeclareWarning; 017 018 /** 019 * This is an annotations based version of the ApiUsageAuditor aspect 020 * 021 * @author Sebastian Thomschke 022 */ 023 @Aspect 024 public abstract class ApiUsageAuditor2 025 { 026 /* 027 * Rule 1: Warn about return value constraints for void methods 028 */ 029 @DeclareWarning("execution(@(@net.sf.oval.configuration.annotation.Constraint *) void *.*(..))") 030 public static final String RULE1 = "OVal API usage violation 1: Method return value constraints are not allowed for methods without return values"; 031 032 /* 033 * Rule 2: Warn about return value constraints for non-void, parameterized methods in classes that are not guarded 034 */ 035 @DeclareWarning("execution(@(@net.sf.oval.configuration.annotation.Constraint *) !void (!@net.sf.oval.guard.Guarded *).*(*,..))") 036 public static final String RULE2 = "OVal API usage violation 2: Method return value constraints for parameterized methods are only allowed in guarded classes"; 037 038 /* 039 * Rule 3: Warn about return value constraints for non-void, non-parameterized methods missing the @Invariant annotation in classes 040 * that are not guarded 041 */ 042 @DeclareWarning("execution(!@net.sf.oval.configuration.annotation.IsInvariant @(@net.sf.oval.configuration.annotation.Constraint *) !void (!@net.sf.oval.guard.Guarded *).*())") 043 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"; 044 045 /* 046 * Rule 4: Warn about the @PreValidateThis annotation used on methods in classes that are not guarded 047 */ 048 @DeclareWarning("execution (@net.sf.oval.guard.PreValidateThis * (!@net.sf.oval.guard.Guarded *).*(..))") 049 public static final String RULE4 = "OVal API usage violation 4: @PreValidateThis is only allowed in guarded classes"; 050 051 /* 052 * Rule 5: Warn about the @PostValidateObject annotation used on methods and constructors in classes not annotated with @Guarded 053 */ 054 @DeclareWarning("execution (@net.sf.oval.guard.PostValidateThis * (!@net.sf.oval.guard.Guarded *).*(..)) || execution (@net.sf.oval.guard.PostValidateObject (!@net.sf.oval.guard.Guarded *).new(..))") 055 public static final String RULE5 = "OVal API usage violation 5: @PostValidateThis is only allowed in guarded classes"; 056 057 /* 058 * Rule 6: Warn about method parameter constraints in classes that are not guarded 059 */ 060 @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 *) *, ..))") 061 public static final String RULE6 = "OVal API usage violation 6: Method parameter constraints are only allowed in guarded classes"; 062 063 /* 064 * Rule 7: Warn about constructor parameter constraints in classes that are not guarded 065 */ 066 @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 *) *, ..))") 067 public static final String RULE7 = "OVal API usage violation 7: Method parameter constraints are only allowed in guarded classes"; 068 069 }