resources.report.rules.pmd.EmptyMethodInAbstractClassShouldBeAbstract.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
The newest version!
EmptyMethodInAbstractClassShouldBeAbstract
EmptyMethodInAbstractClassShouldBeAbstract
An empty method in an abstract class should be abstract instead, as developer may rely on this empty implementation
rather than code the appropriate one.
This rule is defined by the following XPath expression:
//ClassOrInterfaceDeclaration[@Abstract = 'true']
/ClassOrInterfaceBody
/ClassOrInterfaceBodyDeclaration
/MethodDeclaration[@Abstract = 'false' and @Native = 'false']
[
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal/NullLiteral) = 'true' )
or
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image = '0']) = 'true' )
or
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal[string-length(@Image) = 2]) = 'true' )
or
(
(
(boolean(./Block/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image = '']) = 'true' )
)
and
( count (./Block/*) = 1 )
)
or
( count (./Block/*) = 0 )
]
Example:
public abstract class ShouldBeAbstract
{
public Object couldBeAbstract()
{
// Should be abstract method ?
return null;
}
public void couldBeAbstract()
{
}
}