12 March 2020
The PMD team is pleased to announce PMD 6.22.0.
This is a minor release.
This release of PMD brings support for Java 14. PMD can parse Switch Expressions, which have been promoted to be a standard language feature of Java.
PMD also parses Text Blocks as String literals, which is still a preview language feature in Java 14.
The new Pattern Matching for instanceof can be used as well as Records.
Note: The Text Blocks, Pattern Matching for instanceof and Records are all preview language features of OpenJDK 14
and are not enabled by default. In order to
analyze a project with PMD that uses these language features, you’ll need to enable it via the environment
variable PMD_JAVA_OPTS
and select the new language version 14-preview
:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 14-preview ...
Note: Support for the extended break statement introduced in Java 12 as a preview language feature has been removed from PMD with this version. The version “12-preview” is no longer available.
This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.
In addition to suppressing violation with the @SuppressWarnings
annotation, Apex now also supports
the suppressions with a NOPMD
comment. See Suppressing warnings.
The C# tokenizer is now based on an antlr grammar instead of a manual written tokenizer. This should give more accurate results and especially fixes the problems with the using statement syntax (see #2139).
See the new documentation about Writing XPath Rules.
Note: As of PMD version 6.22.0, XPath versions 1.0 and the 1.0 compatibility mode are deprecated. XPath 2.0 is superior in many ways, for example for its support for type checking, sequence values, or quantified expressions. For a detailed but approachable review of the features of XPath 2.0 and above, see the Saxon documentation.
The Rule CognitiveComplexity
(apex-design
) finds methods and classes
that are highly complex and therefore difficult to read and more costly to maintain. In contrast
to cyclomatic complexity, this rule uses “Cognitive Complexity”, which is a measure of how
difficult it is for humans to read and understand a method.
The Rule TestMethodsMustBeInTestClasses
(apex-errorprone
) finds test methods
that are not residing in a test class. The test methods should be moved to a proper test class.
Support for tests inside functional classes was removed in Spring-13 (API Version 27.0), making classes
that violate this rule fail compile-time. This rule is however useful when dealing with legacy code.
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the @InternalApi
annotation. You’ll also get a deprecation warning.
JavaLanguageHandler
JavaLanguageParser
JavaDataFlowHandler
RuleViolationFactory
in each
language module, eg JavaRuleViolationFactory
.
See javadoc of RuleViolationFactory
.Implementations of RuleViolation
in each language module,
eg JavaRuleViolation
. See javadoc of
RuleViolation
.
RuleFactory
RuleBuilder
RuleSetFactory
, use factory methods from RulesetsFactoryUtils
insteadAbstractApexNode
AbstractApexNodeBase
, and the related visit
methods on ApexParserVisitor
and its implementations.
Use ApexNode
instead, now considers comments too.DFAGraphRule
and its implementationsDFAGraphMethod
Node
interface
and AbstractNode
base class. See their javadoc for details.Node#isFindBoundary
is deprecated for XPath queries.net.sourceforge.pmd.lang.metrics
, though most of them were internal and
probably not used directly outside of PMD. Use MetricsUtil
as
a replacement for the language-specific façades too.QualifiableNode
, QualifiedName
AbstractJavaParser
AbstractJavaHandler
ASTAnyTypeDeclaration.TypeKind
ASTAnyTypeDeclaration#getKind
JavaQualifiedName
ASTCatchStatement#getBlock
ASTCompilationUnit#declarationsAreInDefaultPackage
JavaQualifiableNode
net.sourceforge.pmd.lang.java.qname
and its contentsMethodLikeNode
ASTMethodOrConstructorDeclaration
,
ASTLambdaExpression
.ASTAnyTypeDeclaration#getImage
will be removed. Please use getSimpleName()
instead. This affects ASTAnnotationTypeDeclaration#getImage
,
ASTClassOrInterfaceDeclaration#getImage
, and
ASTEnumDeclaration#getImage
.ASTTryStatement
, replacements with other names
have been added. This includes the XPath attribute @Finally
, replace it with a test for child::FinallyStatement
.getGuardExpressionNode
are replaced with getCondition
. This affects the
following nodes: WhileStatement, DoStatement, ForStatement, IfStatement, AssertStatement, ConditionalExpression.ASTYieldStatement
will not implement TypeNode
anymore come 7.0.0. Test the type of the expression nested within it.JavaMetrics
, JavaMetricsComputer
ASTArguments#getArgumentCount
.
Use size
instead.ASTFormalParameters#getParameterCount
.
Use size
instead.As part of the changes we’d like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the JSP AST (with other languages to come):
InternalApi
. Nodes should only be obtained from the parser,
which for rules, means that they never need to instantiate node themselves.
Those constructors will be made package private with 7.0.0.JspParser
is deprecated and should not be used directly.
Use LanguageVersionHandler#getParser
instead.Please look at net.sourceforge.pmd.lang.jsp.ast
to find out the full list of deprecations.
As part of the changes we’d like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the VM AST (with other languages to come):
InternalApi
. Nodes should only be obtained from the parser,
which for rules, means that they never need to instantiate node themselves.
Those constructors will be made package private with 7.0.0.net.sourceforge.pmd.lang.vm.directive
as well as the classes
DirectiveMapper
and LogUtil
are deprecated
for removal. They were only used internally during parsing.VmParser
is deprecated and should not be used directly.
Use LanguageVersionHandler#getParser
instead.Please look at net.sourceforge.pmd.lang.vm.ast
to find out the full list of deprecations.
The production and node ASTCursorBody
was unnecessary, not used and has been removed. Cursors have been already
parsed as ASTCursorSpecification
.