patterntesting.check.runtime.NullPointerTrap.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: NullPointerTrap.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 12.09.2008 by oliver ([email protected])
*/
package patterntesting.check.runtime;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
import patterntesting.annotation.check.runtime.*;
/**
* Together with the AbstractNullPointerTrap forbids this aspect "null" as
* valid argument or return value. If you want to flag a null value as
* valid arguemnt or return value you can use the annotations
* @NullArgsAllowed
and @MayReturnNull
.
*
* @see AbstractNullPointerTrap
* @see patterntesting.annotation.check.runtime.NullArgsAllowed
* @see patterntesting.annotation.check.runtime.MayReturnNull
* @author oliver
* @since 12.09.2008
* @version $Revision: 1.1 $
*/
public aspect NullPointerTrap extends AbstractNullPointerTrap {
private static final Log log = LogFactoryImpl.getLog(NullPointerTrap.class);
static {
if (assertEnabled) {
log.debug("NullPointerTrap is active");
} else {
log.debug("NullPointer checks are skipped - call 'java -ea' (SunVM) to activate it");
}
}
/**
* To return the aspect specific logger to the super aspect.
* @return the aspect specific logger
*/
public final Log getLog() {
return log;
}
/**
* Application code is the whole application.
*/
public pointcut applicationCode() :
within(*..*);
/**
* Null arguments are only allowed at methods and constructors which have
* the NullArgsAllowed
annotation either before the
* method name / constructor or before the whole class.
* Also inner classes are considered.
*/
public pointcut nullArgsAllowed() :
execution(@NullArgsAllowed * *..*(*, ..))
|| execution(@NullArgsAllowed *..new(*, ..))
|| execution(*..*$*.new(..))
|| within(@NullArgsAllowed *);
/**
* Return values are only allowed for methods which have
* the NullArgsAllowed
annotation either before the
* method name or before the whole class.
*/
public pointcut mayReturnNull() :
execution(@MayReturnNull Object+ *..*(..))
|| within(@MayReturnNull *);
}