patterntesting.check.ct.io.AbstractSopAspect.aj Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of patterntesting-check-ct Show documentation
Show all versions of patterntesting-check-ct Show documentation
PatternTesting Check.CT (patterntesting-check-ct) is a quality framework that
allows to automatically verify that Architecture/Design recommendations
are implemented correctly in the code.
It provides different checks of known anti patterns (like using System.out
for logging) but provides also a test framework for better testing.
The checks are done during compile time (this is the "CT" in Check.CT").
/*
*========================================================================
*
* Copyright 2001-2004 Vincent Massol & Matt Smith.
*
* 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.
*
*========================================================================
*/
package patterntesting.check.ct.io;
import java.io.PrintStream;
/**
* Pattern Test that ensures that System.out
and
* System.err
are not used in the code. This is
* to prevent the usage of System.out.println("")
* calls (and variations).
*
* If you write your own aspect you must tell this aspect where you want to
* see the warnings. This is done by overwriting the abstract pointcut
* applicationCode
.
*
* Note: With AspectJ it is not possible to write a compile time
* check that only ensures that println()
calls are
* not allowed. It is possible for runtime checks but we have
* preferred to make a compile-time test for simplicity. Thus,
* code that manipulate System.out
and
* System.err
for other purpose that using the
* println()
methods will need to be added to the
* list of items to exclude from the tests, hence the abstract
* allowedCode
pointcut.
*
* @author Jerome Bernard
* @author Vincent Massol
*
* @version $Id: AbstractSopAspect.aj,v 1.1 2012/08/09 18:38:37 oboehm Exp $
*/
public abstract aspect AbstractSopAspect
{
/**
* Specify what is application code that should be subject to the
* pattern test.
*
* Ex: pointcut applicationCode(): within(patterntesting.*)
*/
public abstract pointcut applicationCode();
/**
* Specify which code is allowed to manipulate System.out
* and System.err
.
*/
public abstract pointcut allowedCode();
/**
* Invalid system logging.
*/
pointcut invalidSystemLogging() :
(get(PrintStream System.out) || get(PrintStream System.err))
&& applicationCode()
&& !allowedCode();
/**
* Declare logging to stdout and stderr being warnings
* (and no longer compiling errors as till PatternTesting 0.5)
*/
declare warning: invalidSystemLogging() :
"No logging should be done using the default output and error streams.";
}