patterntesting.check.runtime.AbstractDeprecatedAspect.aj Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of patterntesting-check-rt Show documentation
Show all versions of patterntesting-check-rt Show documentation
PatternTesting Check.RT (patterntesting-check-rt) provides different runtime
checks of known anti patterns (like using null values as arguments or
return values) but provides also a test framework for better testing.
/**
* $Id: AbstractDeprecatedAspect.aj,v 1.1 2011/12/22 17:15:11 oboehm Exp $
*
* Copyright (c) 2008 by Oliver Boehm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 17.02.2009 by oliver ([email protected])
*/
package patterntesting.check.runtime;
import org.apache.commons.logging.Log;
import org.aspectj.lang.annotation.SuppressAjWarnings;
import patterntesting.runtime.util.*;
/**
* If you want you can use this abstract aspect to mark your own deprected
* code. But normally you should rely on DeprecatedAspect.
*
* @see DeprecatedAspect
* @author oliver
* @since 17.02.2009
* @version $Revision: 1.1 $
*/
public abstract aspect AbstractDeprecatedAspect {
/**
* To get the aspect specific logger.
* @return the logger
*/
public abstract Log getLog();
/**
* Specify what the deprected code is that should be subject to the
* pattern test.
* Normally these are methods, attributes or classes which are marked
* with the @Deprecated Annotation.
*
* @see DeprecatedAspect
*/
public abstract pointcut deprecatedCode();
/**
* We will print here a warning for a call of a deprecated method or class.
* If assertions are enabled we throw a DeprecatedCodeException.
*/
@SuppressAjWarnings({"adviceDidNotMatch"})
before() : deprecatedCode() {
if (Assertions.enabled) {
getLog().error("deprecated use of "
+ JoinPointHelper.getAsShortString(thisJoinPoint)
+ " will fail!");
throw new DeprecatedCodeException(thisJoinPoint);
} else {
getLog().warn("deprecated: " + thisJoinPoint);
}
}
}