forked from phoedos/pmd
Merge branch 'master' into experimental-apex-parser
This commit is contained in:
commit
59537fb15c
@ -106,6 +106,9 @@ entries:
|
||||
- title: Testing your rules
|
||||
url: /pmd_userdocs_extending_testing.html
|
||||
output: web, pdf
|
||||
- title: Creating (XML) dump of the AST
|
||||
url: /pmd_userdocs_extending_ast_dump.html
|
||||
output: web, pdf
|
||||
- title: null
|
||||
output: web, pdf
|
||||
subfolders:
|
||||
@ -552,9 +555,6 @@ entries:
|
||||
- title: Experimental features
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Creating (XML) dump of the AST
|
||||
url: /pmd_devdocs_experimental_ast_dump.html
|
||||
output: web, pdf
|
||||
- title: List of experimental Features
|
||||
url: /tag_experimental.html
|
||||
output: web, pdf
|
||||
|
@ -73,19 +73,19 @@ require_relative 'jdoc_namespace_tag'
|
||||
# * a (args) -> adds the simple name of the argument types for method references, noop for other references
|
||||
# * {% jdoc !a!core::Rule#setName(java.lang.String) %} -> [`setName(String)`](...)
|
||||
# * q (qualify) -> prefix with the fqcn of the class, noop for package references
|
||||
# * {% jdoc !q!core::Rule %} -> [`net.sourceforge.pmd.Rule`](...)
|
||||
# * {% jdoc !q!core::Rule#setName(java.lang.String) %} -> [`net.sourceforge.pmd.Rule#setName`](...)
|
||||
# * {% jdoc !q!core::rule.Rule %} -> [`net.sourceforge.pmd.lang.rule.Rule`](...)
|
||||
# * {% jdoc !q!core::rule.Rule#setName(java.lang.String) %} -> [`net.sourceforge.pmd.lang.rule.Rule#setName`](...)
|
||||
# * c (class) -> prefix the class name for member references, noop for type and package references, or if "qualify" is specified
|
||||
# * {% jdoc !c!core::Rule#setName(java.lang.String) %} -> [`Rule#setName`](...)
|
||||
# * Empty options ("!!") - > shorthand to a commonly relevant option
|
||||
# * For field or method references, "!!" is the "c" option
|
||||
# * {% jdoc !!core::Rule#setName(java.lang.String) %} -> [`Rule#setName`](...)
|
||||
# * For type references, "!!" is the "q" option
|
||||
# * {% jdoc !!core::Rule %} -> [`net.sourceforge.pmd.Rule`](...)
|
||||
# * {% jdoc !!core::rule.Rule %} -> [`net.sourceforge.pmd.lang.rule.Rule`](...)
|
||||
# * For package references, "!!" is a noop, they're always fully qualified
|
||||
# * Several options may be used at once, though this is only useful for method references:
|
||||
# * {% jdoc !ac!core::Rule#setName(java.lang.String) %} -> [`Rule#setName(String)`](...)
|
||||
# * {% jdoc !aq!core::Rule#setName(java.lang.String) %} -> [`net.sourceforge.pmd.Rule#setName(String)`](...)
|
||||
# * {% jdoc !aq!core::rule.Rule#setName(java.lang.String) %} -> [`net.sourceforge.pmd.lang.rule.Rule#setName(String)`](...)
|
||||
#
|
||||
# * DO NOT:
|
||||
# - Include spaces in any part of the reference
|
||||
|
@ -1,117 +0,0 @@
|
||||
---
|
||||
title: Creating XML dump of the AST
|
||||
tags: [devdocs, experimental]
|
||||
summary: Creating a XML representation of the AST allows to analyze the AST with other tools.
|
||||
last_updated: January 17, 2020 (6.21.0)
|
||||
permalink: pmd_devdocs_experimental_ast_dump.html
|
||||
---
|
||||
|
||||
## Command line usage
|
||||
|
||||
```shell
|
||||
$ pmd ast-dump --help
|
||||
Usage: pmd ast-dump [-Dhi] [-e=<encoding>] [-f=<format>] [--file=<file>]
|
||||
[-l=<language>] [-P=<String=String>]...
|
||||
Experimental: dumps the AST of parsing source code
|
||||
-D, -v, --debug, --verbose
|
||||
Debug mode.
|
||||
-e, --encoding=<encoding>
|
||||
Specifies the character set encoding of the source
|
||||
code files
|
||||
-f, --format=<format> The output format.
|
||||
Valid values: xml, text
|
||||
--file=<file> The file to parse and dump.
|
||||
-h, --help Show this help message and exit.
|
||||
-i, --read-stdin Read source from standard input.
|
||||
-l, --language=<language>
|
||||
The source code language.
|
||||
Valid values: apex, ecmascript, html, java, jsp,
|
||||
kotlin, modelica, plsql, pom, scala, swift, vf, vm,
|
||||
wsdl, xml, xsl
|
||||
-P=<String=String> Key-value pair defining a property for the report
|
||||
format.
|
||||
Supported values for each report format:
|
||||
xml:
|
||||
singleQuoteAttributes - Use single quotes to
|
||||
delimit attribute values
|
||||
Default: true
|
||||
lineSeparator - Line separator to use. The default
|
||||
is platform-specific. The values 'CR', 'CRLF',
|
||||
'LF', '\r', '\r\n' and '\n' can be used to
|
||||
represent a carriage return, line feed and their
|
||||
combination more easily.
|
||||
Default: \n
|
||||
renderProlog - True to output a prolog
|
||||
Default: true
|
||||
renderCommonAttributes - True to render attributes
|
||||
like BeginLine, EndLine, etc.
|
||||
Default: false
|
||||
text:
|
||||
onlyAsciiChars - Use only ASCII characters in the
|
||||
structure
|
||||
Default: false
|
||||
maxLevel - Max level on which to recurse. Negative
|
||||
means unbounded
|
||||
Default: -1
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```shell
|
||||
$ cat Foo.java
|
||||
public class Foo {
|
||||
int a;
|
||||
}
|
||||
|
||||
$ pmd ast-dump --format xml --language java --file Foo.java > Foo.xml
|
||||
$ cat Foo.xml
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<CompilationUnit Image='' PackageName='' declarationsAreInDefaultPackage='true'>
|
||||
<TypeDeclaration Image=''>
|
||||
<ClassDeclaration Abstract='false' BinaryName='Foo' Default='false' Final='false' Image='Foo' Interface='false' Local='false' Modifiers='1' Native='false' Nested='false' PackagePrivate='false' Private='false' Protected='false' Public='true' SimpleName='Foo' Static='false' Strictfp='false' Synchronized='false' Transient='false' TypeKind='CLASS' Volatile='false'>
|
||||
<ClassBody AnonymousInnerClass='false' EnumChild='false' Image=''>
|
||||
<FieldDeclaration Abstract='false' AnnotationMember='false' Array='false' ArrayDepth='0' Default='false' Final='false' Image='' InterfaceMember='false' Modifiers='0' Native='false' PackagePrivate='true' Private='false' Protected='false' Public='false' Static='false' Strictfp='false' Synchronized='false' SyntacticallyFinal='false' SyntacticallyPublic='false' SyntacticallyStatic='false' Transient='false' VariableName='a' Volatile='false'>
|
||||
<Type Array='false' ArrayDepth='0' ArrayType='false' Image='' TypeImage='int'>
|
||||
<PrimitiveType Array='false' ArrayDepth='0' Boolean='false' Image='int' />
|
||||
</Type>
|
||||
<VariableDeclarator Image='' Initializer='false' Name='a'>
|
||||
<VariableId Array='false' ArrayDepth='0' ArrayType='false' ExceptionBlockParameter='false' ExplicitReceiverParameter='false' Field='true' Final='false' FormalParameter='false' Image='a' LambdaParameter='false' LocalVariable='false' ResourceDeclaration='false' TypeInferred='false' VariableName='a' />
|
||||
</VariableDeclarator>
|
||||
</FieldDeclaration>
|
||||
</ClassBody>
|
||||
</ClassDeclaration>
|
||||
</TypeDeclaration>
|
||||
</CompilationUnit>
|
||||
|
||||
$ xmlstarlet select -t -c "//VariableId[@VariableName='a']" Foo.xml
|
||||
<VariableId Array="false" ArrayDepth="0" ArrayType="false" ExceptionBlockParameter="false" ExplicitReceiverParameter="false" Field="true" Final="false" FormalParameter="false" Image="a" LambdaParameter="false" LocalVariable="false" ResourceDeclaration="false" TypeInferred="false" VariableName="a"/>
|
||||
```
|
||||
|
||||
This example uses [xmlstarlet](http://xmlstar.sourceforge.net/) to query the xml document for any variables/fields
|
||||
with the name "a".
|
||||
|
||||
|
||||
## Programmatic usage
|
||||
|
||||
Just parse your source code to get the AST and pass it on to the `XmlTreeRenderer`:
|
||||
|
||||
```java
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.util.treeexport.XmlTreeRenderer;
|
||||
|
||||
public class TreeExport {
|
||||
public static void main(String[] args) throws IOException {
|
||||
LanguageVersionHandler java = LanguageRegistry.getLanguage("Java").getDefaultVersion().getLanguageVersionHandler();
|
||||
Parser parser = java.getParser(java.getDefaultParserOptions());
|
||||
Node root = parser.parse("foo", new StringReader("class Foo {}"));
|
||||
|
||||
new XmlTreeRenderer().renderSubtree(root, System.out);
|
||||
}
|
||||
}
|
||||
```
|
@ -66,20 +66,20 @@ We have some additional custom liquid tags that help in writing the documentatio
|
||||
|
||||
Here's a short overview:
|
||||
|
||||
| Liquid | Rendered as |
|
||||
|:-------|:------------|
|
||||
| `{% raw %}{% rule "java/codestyle/LinguisticNaming" %}{% endraw %}` | {% rule "java/codestyle/LinguisticNaming" %} |
|
||||
| `{% raw %}{% jdoc core::Rule %}{% endraw %}` | {% jdoc core::Rule %} |
|
||||
| `{% raw %}{% jdoc !q!core::Rule %}{% endraw %}` | {% jdoc !q!core::Rule %} |
|
||||
| `{% raw %}{% jdoc core::Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc core::Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc !c!core::Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc !c!core::Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc !a!core::Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc !a!core::Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc !ac!core::Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc !ac!core::Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc core::properties.PropertyDescriptor %}{% endraw %}` | {% jdoc core::properties.PropertyDescriptor %} |
|
||||
| `{% raw %}{% jdoc_nspace :jast java::lang.java.ast %}{% jdoc jast::ASTTypeDeclaration %}{% endraw %}` | {% jdoc_nspace :jast java::lang.java.ast %}{% jdoc jast::ASTTypeDeclaration %} |
|
||||
| `{% raw %}{% jdoc_nspace :jast java::lang.java.ast %}{% jdoc_package :jast %}{% endraw %}` | {% jdoc_nspace :jast java::lang.java.ast %}{% jdoc_package :jast %} |
|
||||
| Liquid | Rendered as |
|
||||
|:---------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|
|
||||
| `{% raw %}{% rule "java/codestyle/LinguisticNaming" %}{% endraw %}` | {% rule "java/codestyle/LinguisticNaming" %} |
|
||||
| `{% raw %}{% jdoc core::lang.rule.Rule %}{% endraw %}` | {% jdoc core::lang.rule.Rule %} |
|
||||
| `{% raw %}{% jdoc !q!core::lang.rule.Rule %}{% endraw %}` | {% jdoc !q!core::lang.rule.Rule %} |
|
||||
| `{% raw %}{% jdoc core::lang.rule.Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc core::lang.rule.Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc !c!core::lang.rule.Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc !c!core::lang.rule.Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc !a!core::lang.rule.Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc !a!core::lang.rule.Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc !ac!core::lang.rule.Rule#setName(java.lang.String) %}{% endraw %}` | {% jdoc !ac!core::lang.rule.Rule#setName(java.lang.String) %} |
|
||||
| `{% raw %}{% jdoc core::properties.PropertyDescriptor %}{% endraw %}` | {% jdoc core::properties.PropertyDescriptor %} |
|
||||
| `{% raw %}{% jdoc_nspace :jast java::lang.java.ast %}{% jdoc jast::ASTTypeDeclaration %}{% endraw %}` | {% jdoc_nspace :jast java::lang.java.ast %}{% jdoc jast::ASTTypeDeclaration %} |
|
||||
| `{% raw %}{% jdoc_nspace :jast java::lang.java.ast %}{% jdoc_package :jast %}{% endraw %}` | {% jdoc_nspace :jast java::lang.java.ast %}{% jdoc_package :jast %} |
|
||||
| `{% raw %}{% jdoc_nspace :PrD core::properties.PropertyDescriptor %}{% jdoc !ac!:PrD#uiOrder() %}{% endraw %}` | {% jdoc_nspace :PrD core::properties.PropertyDescriptor %}{% jdoc !ac!:PrD#uiOrder() %} |
|
||||
| `{% raw %}{% jdoc_old core::Rule %}{% endraw %}` | {% jdoc_old core::Rule %}
|
||||
| `{% raw %}{% jdoc_old core::Rule %}{% endraw %}` | {% jdoc_old core::Rule %} |
|
||||
|
||||
For the javadoc tags, the standard PMD maven modules are already defined as namespaces, e.g. `core`, `java`, `apex`, ....
|
||||
|
||||
|
@ -167,12 +167,12 @@ The Javadocs are the reference documentation.
|
||||
Violations reported are the same for all languages, but languages can opt in to provide more details.
|
||||
Java does this by adding the following additional information for each reported violation:
|
||||
|
||||
* {% jdoc core::RuleViolation#VARIABLE_NAME %}
|
||||
* {% jdoc core::RuleViolation#METHOD_NAME %}
|
||||
* {% jdoc core::RuleViolation#CLASS_NAME %}
|
||||
* {% jdoc core::RuleViolation#PACKAGE_NAME %}
|
||||
* {% jdoc core::reporting.RuleViolation#VARIABLE_NAME %}
|
||||
* {% jdoc core::reporting.RuleViolation#METHOD_NAME %}
|
||||
* {% jdoc core::reporting.RuleViolation#CLASS_NAME %}
|
||||
* {% jdoc core::reporting.RuleViolation#PACKAGE_NAME %}
|
||||
|
||||
You can access these via {% jdoc core::RuleViolation#getAdditionalInfo() %}
|
||||
You can access these via {% jdoc core::reporting.RuleViolation#getAdditionalInfo() %}
|
||||
|
||||
## Dataflow
|
||||
|
||||
|
125
docs/pages/pmd/userdocs/extending/ast_dump.md
Normal file
125
docs/pages/pmd/userdocs/extending/ast_dump.md
Normal file
@ -0,0 +1,125 @@
|
||||
---
|
||||
title: Creating XML dump of the AST
|
||||
tags: [userdocs]
|
||||
summary: Creating a XML representation of the AST allows to analyze the AST with other tools.
|
||||
last_updated: January 2024 (7.0.0)
|
||||
permalink: pmd_userdocs_extending_ast_dump.html
|
||||
---
|
||||
|
||||
## Command line usage
|
||||
|
||||
```shell
|
||||
$ pmd ast-dump --help
|
||||
Usage: pmd ast-dump [-Dhi] [-e=<encoding>] [-f=<format>] [--file=<file>]
|
||||
[-l=<language>] [-P=<String=String>]...
|
||||
Dumps the AST of parsing source code
|
||||
-D, -v, --debug, --verbose
|
||||
Debug mode.
|
||||
-e, --encoding=<encoding>
|
||||
Specifies the character set encoding of the source
|
||||
code files
|
||||
-f, --format=<format> The output format.
|
||||
Valid values: xml, text
|
||||
--file=<file> The file to parse and dump.
|
||||
-h, --help Show this help message and exit.
|
||||
-i, --read-stdin Read source from standard input.
|
||||
-l, --language=<language>
|
||||
The source code language.
|
||||
Valid values: apex, ecmascript, html, java, jsp,
|
||||
kotlin, modelica, plsql, pom, scala, swift, vf, vm,
|
||||
wsdl, xml, xsl
|
||||
-P=<String=String> Key-value pair defining a property for the report
|
||||
format.
|
||||
Supported values for each report format:
|
||||
xml:
|
||||
singleQuoteAttributes - Use single quotes to
|
||||
delimit attribute values
|
||||
Default: true
|
||||
lineSeparator - Line separator to use. The default
|
||||
is platform-specific. The values 'CR', 'CRLF',
|
||||
'LF', '\r', '\r\n' and '\n' can be used to
|
||||
represent a carriage return, line feed and their
|
||||
combination more easily.
|
||||
Default: \n
|
||||
renderProlog - True to output a prolog
|
||||
Default: true
|
||||
renderCommonAttributes - True to render attributes
|
||||
like BeginLine, EndLine, etc.
|
||||
Default: false
|
||||
text:
|
||||
onlyAsciiChars - Use only ASCII characters in the
|
||||
structure
|
||||
Default: false
|
||||
maxLevel - Max level on which to recurse. Negative
|
||||
means unbounded
|
||||
Default: -1
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```shell
|
||||
$ cat Foo.java
|
||||
public class Foo {
|
||||
int a;
|
||||
}
|
||||
|
||||
$ pmd ast-dump --format xml --language java --file Foo.java > Foo.xml
|
||||
$ cat Foo.xml
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<CompilationUnit Image='' PackageName=''>
|
||||
<ClassDeclaration Abstract='false' Annotation='false' Anonymous='false' BinaryName='Foo' CanonicalName='Foo' EffectiveVisibility='public' Enum='false' Final='false' Image='Foo' Interface='false' Local='false' Native='false' Nested='false' PackageName='' PackagePrivate='false' Private='false' Protected='false' Public='true' Record='false' RegularClass='true' RegularInterface='false' SimpleName='Foo' Static='false' Strictfp='false' Synchronized='false' SyntacticallyAbstract='false' SyntacticallyFinal='false' SyntacticallyPublic='true' SyntacticallyStatic='false' TopLevel='true' Transient='false' Visibility='public' Volatile='false'>
|
||||
<ModifierList Image='' />
|
||||
<ClassBody Empty='false' Image='' Size='1'>
|
||||
<FieldDeclaration Abstract='false' EffectiveVisibility='package' Final='false' Image='' Native='false' PackagePrivate='true' Private='false' Protected='false' Public='false' Static='false' Strictfp='false' Synchronized='false' SyntacticallyAbstract='false' SyntacticallyFinal='false' SyntacticallyPublic='false' SyntacticallyStatic='false' Transient='false' VariableName='a' Visibility='package' Volatile='false'>
|
||||
<ModifierList Image='' />
|
||||
<PrimitiveType ArrayDepth='0' ArrayType='false' ClassOrInterfaceType='false' Image='' Kind='int' PrimitiveType='true' TypeImage='int' />
|
||||
<VariableDeclarator Image='' Initializer='false' Name='a'>
|
||||
<VariableId Abstract='false' ArrayType='false' EffectiveVisibility='package' EnumConstant='false' ExceptionBlockParameter='false' Field='true' Final='false' ForLoopVariable='false' ForeachVariable='false' FormalParameter='false' Image='a' LambdaParameter='false' LocalVariable='false' Name='a' Native='false' PackagePrivate='true' PatternBinding='false' Private='false' Protected='false' Public='false' RecordComponent='false' ResourceDeclaration='false' Static='false' Strictfp='false' Synchronized='false' SyntacticallyAbstract='false' SyntacticallyFinal='false' SyntacticallyPublic='false' SyntacticallyStatic='false' Transient='false' TypeInferred='false' VariableName='a' Visibility='package' Volatile='false' />
|
||||
</VariableDeclarator>
|
||||
</FieldDeclaration>
|
||||
</ClassBody>
|
||||
</ClassDeclaration>
|
||||
</CompilationUnit>
|
||||
|
||||
$ xmlstarlet select -t -c "//VariableId[@VariableName='a']" Foo.xml
|
||||
<VariableId Abstract="false" ArrayType="false" EffectiveVisibility="package" EnumConstant="false" ExceptionBlockParameter="false" Field="true" Final="false" ForLoopVariable="false" ForeachVariable="false" FormalParameter="false" Image="a" LambdaParameter="false" LocalVariable="false" Name="a" Native="false" PackagePrivate="true" PatternBinding="false" Private="false" Protected="false" Public="false" RecordComponent="false" ResourceDeclaration="false" Static="false" Strictfp="false" Synchronized="false" SyntacticallyAbstract="false" SyntacticallyFinal="false" SyntacticallyPublic="false" SyntacticallyStatic="false" Transient="false" TypeInferred="false" VariableName="a" Visibility="package" Volatile="false"/>
|
||||
```
|
||||
|
||||
This example uses [xmlstarlet](http://xmlstar.sourceforge.net/) to query the xml document for any variables/fields
|
||||
with the name "a".
|
||||
|
||||
|
||||
## Programmatic usage
|
||||
|
||||
Just parse your source code to get the AST and pass it on to the `XmlTreeRenderer`:
|
||||
|
||||
```java
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageProcessor;
|
||||
import net.sourceforge.pmd.lang.LanguageProcessorRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.PmdCapableLanguage;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
import net.sourceforge.pmd.util.treeexport.XmlTreeRenderer;
|
||||
|
||||
public class TreeExportTest {
|
||||
public static void main(String[] args) throws IOException {
|
||||
PmdCapableLanguage java = (PmdCapableLanguage) LanguageRegistry.PMD.getLanguageById("java");
|
||||
LanguageProcessor processor = java.createProcessor(java.newPropertyBundle());
|
||||
Parser parser = processor.services().getParser();
|
||||
|
||||
try (TextDocument textDocument = TextDocument.readOnlyString("class Foo { int a; }", java.getDefaultVersion());
|
||||
LanguageProcessorRegistry lpr = LanguageProcessorRegistry.singleton(processor)) {
|
||||
|
||||
Parser.ParserTask task = new Parser.ParserTask(textDocument, SemanticErrorReporter.noop(), lpr);
|
||||
RootNode root = parser.parse(task);
|
||||
|
||||
new XmlTreeRenderer().renderSubtree(root, System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
@ -165,7 +165,6 @@ with a backslash when needed.
|
||||
```xml
|
||||
<rule name="MyXpathRule" ...>
|
||||
<properties>
|
||||
<property name="version" value="2.0" />
|
||||
<property name="intProp" type="List[Integer]" value="1,2,5" description="An IntegerMultiProperty." />
|
||||
<property name="reportedIdentifiers" type="List[String]" value="foo,bar"
|
||||
description="A StringMultiProperty." />
|
||||
|
@ -32,7 +32,7 @@ very similar for other languages.
|
||||
|
||||
To write a rule in Java you'll have to:
|
||||
|
||||
1. Write a Java class that implements the interface {% jdoc core::Rule %}. Each
|
||||
1. Write a Java class that implements the interface {% jdoc core::lang.rule.Rule %}. Each
|
||||
language implementation provides a base rule class to ease your pain,
|
||||
e.g. {% jdoc jrule::AbstractJavaRule %}.
|
||||
2. Compile this class, linking it to PMD APIs (e.g. using PMD as a Maven dependency)
|
||||
@ -172,18 +172,18 @@ to get the condition of an If-statement.
|
||||
|
||||
### Reporting violations
|
||||
|
||||
In your visit method, you have access to the {% jdoc core::RuleContext %} which is the entry point into
|
||||
In your visit method, you have access to the {% jdoc core::reporting.RuleContext %} which is the entry point into
|
||||
reporting back during the analysis.
|
||||
|
||||
* {% jdoc core::RuleContext#addViolation(core::lang.ast.Node) %} reports a rule violation at
|
||||
* {% jdoc core::reporting.RuleContext#addViolation(core::lang.ast.Node) %} reports a rule violation at
|
||||
the position of the given node with the message defined in the rule declaration XML element.
|
||||
* The message defined in the rule declaration XML element might contain **placeholder**, such as `{0}`.
|
||||
In that case, you need to call {% jdoc core::RuleContext#addViolation(core::lang.ast.Node,java.lang.Object...) %}
|
||||
In that case, you need to call {% jdoc core::reporting.RuleContext#addViolation(core::lang.ast.Node,java.lang.Object...) %}
|
||||
and provide the values for the placeholders. The message is actually processed as a `java.text.MessageFormat`.
|
||||
* Sometimes a rule might want to differentiate between different cases of a violation and use different
|
||||
messages. This is possible by calling the methods
|
||||
{% jdoc core::RuleContext#addViolationWithMessage(core::lang.ast.Node,java.lang.String) %} or
|
||||
{% jdoc core::RuleContext#addViolationWithMessage(core::lang.ast.Node,java.lang.String,java.lang.Object...) %}.
|
||||
{% jdoc core::reporting.RuleContext#addViolationWithMessage(core::lang.ast.Node,java.lang.String) %} or
|
||||
{% jdoc core::reporting.RuleContext#addViolationWithMessage(core::lang.ast.Node,java.lang.String,java.lang.Object...) %}.
|
||||
Using these methods, the message defined in the rule declaration XML element is _not used_.
|
||||
* Rules can be customized using properties and sometimes you want to include the actual value of a property
|
||||
in the message, e.g. if the rule enforces a specific limit.
|
||||
@ -247,11 +247,11 @@ For each thread, a deep copy of the rule is created. Each thread is given
|
||||
a different set of files to analyse. Then, for each such file and for each
|
||||
rule copy:
|
||||
|
||||
1. {% jdoc core::Rule#start(core::RuleContext) %} is called once, before parsing
|
||||
2. {% jdoc core::Rule#apply(core::lang.ast.Node,core::RuleContext) %} is called with the root
|
||||
1. {% jdoc core::lang.rule.Rule#start(core::reporting.RuleContext) %} is called once, before parsing
|
||||
2. {% jdoc core::lang.rule.Rule#apply(core::lang.ast.Node,core::reporting.RuleContext) %} is called with the root
|
||||
of the AST. That method performs the AST traversal that ultimately calls visit methods.
|
||||
It's not called for RuleChain rules.
|
||||
3. {% jdoc core::Rule#end(core::RuleContext) %} is called when the rule is done processing
|
||||
3. {% jdoc core::lang.rule.Rule#end(core::reporting.RuleContext) %} is called when the rule is done processing
|
||||
the file
|
||||
|
||||
## Example projects
|
||||
|
@ -73,7 +73,7 @@ example, all Java AST nodes extend {% jdoc java::lang.java.ast.JavaNode %}.
|
||||
|
||||
The structure of the AST can be discovered through
|
||||
* the [Rule Designer](pmd_userdocs_extending_designer_reference.html#ast-inspection)
|
||||
* the [AST dump feature](pmd_devdocs_experimental_ast_dump.html)
|
||||
* the [AST dump feature](pmd_userdocs_extending_ast_dump.html)
|
||||
|
||||
|
||||
|
||||
@ -104,7 +104,7 @@ instead of mentioning the `ref` attribute, it mentions the `class` attribute,
|
||||
with the implementation class of your rule.
|
||||
|
||||
* **For Java rules:** this is the concrete class extending AbstractRule (transitively)
|
||||
* **For XPath rules:** this is `net.sourceforge.pmd.lang.rule.XPathRule`.
|
||||
* **For XPath rules:** this is `net.sourceforge.pmd.lang.rule.xpath.XPathRule`.
|
||||
* **For XPath rules analyzing XML-based languages:** this is `net.sourceforge.pmd.lang.xml.rule.DomXPathRule`.
|
||||
See [XPath rules in XML](pmd_languages_xml.html#xpath-rules-in-xml) for more info.
|
||||
|
||||
@ -128,7 +128,7 @@ Example for XPath rule:
|
||||
<rule name="MyXPathRule"
|
||||
language="java"
|
||||
message="Violation!"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule">
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
|
||||
<description>
|
||||
Description
|
||||
</description>
|
||||
|
@ -27,7 +27,8 @@ with opt-in support for XPath 2.0.
|
||||
See [the Saxonica documentation](https://www.saxonica.com/html/documentation/expressions/xpath31new.html)
|
||||
for an introduction to new features in XPath 3.1.
|
||||
|
||||
The property `version` of {% jdoc core::lang.rule.XPathRule %} is deprecated and will be removed.
|
||||
The property `version` of {% jdoc core::lang.rule.XPathRule %} is deprecated and
|
||||
has been removed with PMD 7.
|
||||
|
||||
|
||||
## DOM representation of ASTs
|
||||
|
@ -127,7 +127,7 @@ copy-paste into your ruleset XML. The resulting element looks like so:
|
||||
<rule name="DontCallBossShort"
|
||||
language="java"
|
||||
message="Boss wants to talk to you."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule">
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
|
||||
<description>
|
||||
TODO
|
||||
</description>
|
||||
|
@ -27,7 +27,7 @@ There are a couple of deprecated things in PMD 6, you might encounter:
|
||||
See also [Defining rule properties](pmd_userdocs_extending_defining_properties.html)
|
||||
|
||||
* When reporting a violation, you might see a deprecation of the `addViolation` methods. These methods have been moved
|
||||
to {% jdoc core::RuleContext %}. E.g. instead of `addViolation(data, node, ...)` use `asCtx(data).addViolation(node, ...)`.
|
||||
to {% jdoc core::reporting.RuleContext %}. E.g. instead of `addViolation(data, node, ...)` use `asCtx(data).addViolation(node, ...)`.
|
||||
|
||||
* When you are calling PMD from CLI, you need to stop using deprecated CLI params, e.g.
|
||||
* `-no-cache` ➡️ `--no-cache`
|
||||
@ -109,9 +109,11 @@ XPath 2.0 is available in PMD 6 already and can be used right away. PMD 7 will u
|
||||
won't support XPath 1.0 anymore. The difference between XPath 2.0 and XPath 3.1 is not big, so your XPath 2.0
|
||||
can be expected to work in PMD 7 without any further changes. So the migration path is to simply migrate to XPath 2.0.
|
||||
|
||||
After you have migrated your XPath rules to XPath 2.0, remove the "version" property, since that will be removed
|
||||
with PMD 7. PMD 7 by default uses XPath 3.1.
|
||||
See below [XPath](#xpath-migrating-from-10-to-20) for details.
|
||||
After you have migrated your XPath rules to XPath 2.0, remove the "version" property, since that has been removed
|
||||
with PMD 7. PMD 7 by default uses XPath 3.1. See below [XPath](#xpath-migrating-from-10-to-20) for details.
|
||||
|
||||
Then change the `class` attribute of your rule to `net.sourceforge.pmd.lang.rule.xpath.XPathRule` - because the
|
||||
class {%jdoc core::lang.rule.xpath.XPathRule %} has been moved into subpackage {% jdoc_package core::lang.rule.xpath %}.
|
||||
|
||||
There are some general changes for AST nodes regarding the `@Image` attribute.
|
||||
See below [General AST Changes to avoid @Image](#general-ast-changes-to-avoid-image).
|
||||
@ -161,7 +163,7 @@ Most notable changes are:
|
||||
* A rule violation factory is not needed anymore. For language specific information on rule violations, there is
|
||||
now a {% jdoc core::reporting.ViolationDecorator %} that a language can implement. These ViolationDecorators
|
||||
are called when a violation is reported and they can provide the additional information. This information can be
|
||||
used by renderers via {% jdoc !!core::RuleViolation#getAdditionalInfo() %}.
|
||||
used by renderers via {% jdoc !!core::reporting.RuleViolation#getAdditionalInfo() %}.
|
||||
* A parser visitor adapter is not needed anymore. The visitor interface now provides a default implementation.
|
||||
Instead, a base visitor for the language should be created, which extends {% jdoc core::lang.ast.AstVisitorBase %}.
|
||||
* A rule chain visitor is not needed anymore. PMD provides a common implementation that fits all languages.
|
||||
|
@ -199,7 +199,11 @@ The rules have been moved into categories with PMD 6.
|
||||
* [#4723](https://github.com/pmd/pmd/issues/4723): \[cli] Launch fails for "bash pmd"
|
||||
* core
|
||||
* [#1027](https://github.com/pmd/pmd/issues/1027): \[core] Apply the new PropertyDescriptor<Pattern> type where applicable
|
||||
* [#3903](https://github.com/pmd/pmd/issues/3903): \[core] Consolidate `n.s.pmd.reporting` package
|
||||
* [#3905](https://github.com/pmd/pmd/issues/3905): \[core] Stabilize tree export API
|
||||
* [#3917](https://github.com/pmd/pmd/issues/3917): \[core] Consolidate `n.s.pmd.lang.rule` package
|
||||
* [#4065](https://github.com/pmd/pmd/issues/4065): \[core] Rename TokenMgrError to LexException, Tokenizer to CpdLexer
|
||||
* [#4309](https://github.com/pmd/pmd/issues/4309): \[core] Cleanups in XPath area
|
||||
* [#4312](https://github.com/pmd/pmd/issues/4312): \[core] Remove unnecessary property `color` and system property `pmd.color` in `TextColorRenderer`
|
||||
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for <lang>-<ruleset> hyphen notation for ruleset references
|
||||
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
|
||||
@ -257,11 +261,53 @@ The rules have been moved into categories with PMD 6.
|
||||
|
||||
#### API Changes
|
||||
|
||||
**New API**
|
||||
|
||||
The API around {%jdoc core::util.treeexport.TreeRenderer %} has been declared as stable. It was previously
|
||||
experimental. It can be used via the CLI subcommand `ast-dump` or programmatically, as described
|
||||
on [Creating XML dump of the AST]({{ baseurl }}pmd_userdocs_extending_ast_dump.html).
|
||||
|
||||
**General AST Changes to avoid `@Image`**
|
||||
|
||||
See [General AST Changes to avoid @Image]({{ baseurl }}pmd_userdocs_migrating_to_pmd7.html#general-ast-changes-to-avoid-image)
|
||||
in the migration guide for details.
|
||||
|
||||
**XPath Rules**
|
||||
* The property `version` was already deprecated and has finally been removed. Please don't define the version
|
||||
property anymore in your custom XPath rules. By default, the latest XPath version will be used, which
|
||||
is XPath 3.1.
|
||||
|
||||
**Moved classes/consolidated packages**
|
||||
|
||||
* pmd-core
|
||||
* Many types have been moved from the base package `net.sourceforge.pmd` into subpackage {% jdoc_package core::lang.rule %}
|
||||
* {%jdoc core::lang.rule.Rule %}
|
||||
* {%jdoc core::lang.rule.RulePriority %}
|
||||
* {%jdoc core::lang.rule.RuleSet %}
|
||||
* {%jdoc core::lang.rule.RuleSetFactory %}
|
||||
* {%jdoc core::lang.rule.RuleSetLoader %}
|
||||
* {%jdoc core::lang.rule.RuleSetLoadException %}
|
||||
* {%jdoc core::lang.rule.RuleSetWriter %}
|
||||
* Many types have been moved from the base package `net.sourceforge.pmd` into subpackage {% jdoc_package core::reporting %}
|
||||
* {%jdoc core::reporting.Report %}
|
||||
* {%jdoc core::reporting.RuleContext %}
|
||||
* {%jdoc core::reporting.RuleViolation %}
|
||||
* {%jdoc core::reporting.ViolationSuppressor %}
|
||||
* {%jdoc core::reporting.ParametricRuleViolation %} (moved from `net.sourcceforge.pmd.lang.rule`)
|
||||
* {%jdoc core::lang.rule.xpath.XPathRule %} has been moved into subpackage {% jdoc_package core::lang.rule.xpath %}.
|
||||
|
||||
**Internalized classes**
|
||||
|
||||
These were marked as `@InternalApi` previously.
|
||||
|
||||
* pmd-core
|
||||
* `RuleFactory`: moved from `net.sourceforge.pmd.rules` into subpackage `lang.rule`.
|
||||
It has now been hidden completely from public API.
|
||||
* Many types have been moved from the base package `net.sourceforge.pmd` into subpackage `lang.rule.internal`.
|
||||
* `RuleSetReference`
|
||||
* `RuleSetReferenceId`
|
||||
* `RuleSets`
|
||||
|
||||
**Removed classes and methods (previously deprecated)**
|
||||
|
||||
The following previously deprecated classes have been removed:
|
||||
@ -779,6 +825,9 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
|
||||
* [#3815](https://github.com/pmd/pmd/issues/3815): \[core] Update Saxon HE to 10.7
|
||||
* [#3893](https://github.com/pmd/pmd/pull/3893): \[core] Text documents
|
||||
* [#3902](https://github.com/pmd/pmd/issues/3902): \[core] Violation decorators
|
||||
* [#3903](https://github.com/pmd/pmd/issues/3903): \[core] Consolidate `n.s.pmd.reporting` package
|
||||
* [#3905](https://github.com/pmd/pmd/issues/3905): \[core] Stabilize tree export API
|
||||
* [#3917](https://github.com/pmd/pmd/issues/3917): \[core] Consolidate `n.s.pmd.lang.rule` package
|
||||
* [#3918](https://github.com/pmd/pmd/issues/3918): \[core] Make LanguageRegistry non static
|
||||
* [#3919](https://github.com/pmd/pmd/issues/3919): \[core] Merge CPD and PMD language
|
||||
* [#3922](https://github.com/pmd/pmd/pull/3922): \[core] Better error reporting for the ruleset parser
|
||||
@ -788,6 +837,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
|
||||
* [#4204](https://github.com/pmd/pmd/issues/4204): \[core] Provide a CpdAnalysis class as a programmatic entry point into CPD
|
||||
* [#4301](https://github.com/pmd/pmd/issues/4301): \[core] Remove deprecated property concrete classes
|
||||
* [#4302](https://github.com/pmd/pmd/issues/4302): \[core] Migrate Property Framework API to Java 8
|
||||
* [#4309](https://github.com/pmd/pmd/issues/4309): \[core] Cleanups in XPath area
|
||||
* [#4312](https://github.com/pmd/pmd/issues/4312): \[core] Remove unnecessary property `color` and system property `pmd.color` in `TextColorRenderer`
|
||||
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for <lang>-<ruleset> hyphen notation for ruleset references
|
||||
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
|
||||
|
@ -6792,7 +6792,7 @@ is of course PMD specific and language dependent. That XML file can be used to e
|
||||
if you don't want to use the [Designer](https://github.com/pmd/pmd-designer).
|
||||
|
||||
This feature is experimental and might change or even be removed in the future, if it is not
|
||||
useful. A short description how to use it is available under [Creating XML dump of the AST](pmd_devdocs_experimental_ast_dump.html).
|
||||
useful. A short description how to use it is available under [Creating XML dump of the AST](pmd_userdocs_extending_ast_dump.html).
|
||||
|
||||
Any feedback about it, especially about your use cases, is highly appreciated.
|
||||
|
||||
|
@ -1201,7 +1201,7 @@ You can identify them with the `@InternalApi` annotation. You'll also get a depr
|
||||
should be used.
|
||||
- Several members of {% jdoc test::cli.BaseCPDCLITest %} have been deprecated with replacements.
|
||||
- The methods {% jdoc !!core::ant.Formatter#start(java.lang.String) %},
|
||||
{% jdoc !!core::ant.Formatter#end(net.sourceforge.pmd.Report) %}, {% jdoc !!core::ant.Formatter#getRenderer() %},
|
||||
{% jdoc !!core::ant.Formatter#end(net.sourceforge.pmd.reporting.Report) %}, {% jdoc !!core::ant.Formatter#getRenderer() %},
|
||||
and {% jdoc !!core::ant.Formatter#isNoOutputSupplied() %} have been internalized.
|
||||
|
||||
#### 6.45.0
|
||||
@ -1211,7 +1211,7 @@ You can identify them with the `@InternalApi` annotation. You'll also get a depr
|
||||
* Report has two new methods which allow limited mutations of a given report:
|
||||
* {% jdoc !!core::Report#filterViolations(net.sourceforge.pmd.util.Predicate) %} creates a new report with
|
||||
some violations removed with a given predicate based filter.
|
||||
* {% jdoc !!core::Report#union(net.sourceforge.pmd.Report) %} can combine two reports into a single new Report.
|
||||
* {% jdoc !!core::Report#union(net.sourceforge.pmd.reporting.Report) %} can combine two reports into a single new Report.
|
||||
* {% jdoc !!core::util.Predicate %} will be replaced in PMD7 with the standard Predicate interface from java8.
|
||||
* The module `pmd-html` is entirely experimental right now. Anything in the package
|
||||
`net.sourceforge.pmd.lang.html` should be used cautiously.
|
||||
|
@ -26,7 +26,6 @@ import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.types.Parameter;
|
||||
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.internal.util.IOUtil;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
@ -36,6 +35,7 @@ import net.sourceforge.pmd.reporting.FileAnalysisListener;
|
||||
import net.sourceforge.pmd.reporting.FileNameRenderer;
|
||||
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
|
||||
import net.sourceforge.pmd.reporting.ListenerInitializer;
|
||||
import net.sourceforge.pmd.reporting.Report;
|
||||
|
||||
@InternalApi
|
||||
public class Formatter {
|
||||
|
@ -17,9 +17,9 @@ import org.apache.tools.ant.types.Path;
|
||||
import org.apache.tools.ant.types.Reference;
|
||||
import org.apache.tools.ant.types.Resource;
|
||||
|
||||
import net.sourceforge.pmd.RulePriority;
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.ant.internal.PMDTaskImpl;
|
||||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||
|
||||
/**
|
||||
* PMD Ant task. Setters of this class are interpreted by Ant as properties
|
||||
|
@ -23,8 +23,6 @@ import org.slf4j.event.Level;
|
||||
|
||||
import net.sourceforge.pmd.PMDConfiguration;
|
||||
import net.sourceforge.pmd.PmdAnalysis;
|
||||
import net.sourceforge.pmd.RulePriority;
|
||||
import net.sourceforge.pmd.RuleSetLoader;
|
||||
import net.sourceforge.pmd.ant.Formatter;
|
||||
import net.sourceforge.pmd.ant.PMDTask;
|
||||
import net.sourceforge.pmd.ant.SourceLanguage;
|
||||
@ -35,6 +33,8 @@ import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.document.TextFile;
|
||||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||
import net.sourceforge.pmd.lang.rule.RuleSetLoader;
|
||||
import net.sourceforge.pmd.reporting.FileAnalysisListener;
|
||||
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
|
||||
import net.sourceforge.pmd.reporting.ReportStats;
|
||||
|
@ -9,7 +9,6 @@ import static net.sourceforge.pmd.util.CollectionUtil.setOf;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.ViolationSuppressor;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParser;
|
||||
import net.sourceforge.pmd.lang.apex.internal.ApexDesignerBindings;
|
||||
@ -17,6 +16,7 @@ import net.sourceforge.pmd.lang.apex.metrics.ApexMetrics;
|
||||
import net.sourceforge.pmd.lang.ast.Parser;
|
||||
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.metrics.Metric;
|
||||
import net.sourceforge.pmd.reporting.ViolationSuppressor;
|
||||
import net.sourceforge.pmd.util.designerbindings.DesignerBindings;
|
||||
|
||||
class ApexLanguageHandler implements LanguageVersionHandler {
|
||||
|
@ -13,11 +13,6 @@ import java.util.TreeSet;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.Report.SuppressedViolation;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.ViolationSuppressor;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTAnnotation;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTAnnotationParameter;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTField;
|
||||
@ -30,6 +25,11 @@ import net.sourceforge.pmd.lang.apex.ast.ASTUserEnum;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclarationStatements;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.rule.Rule;
|
||||
import net.sourceforge.pmd.reporting.Report;
|
||||
import net.sourceforge.pmd.reporting.Report.SuppressedViolation;
|
||||
import net.sourceforge.pmd.reporting.RuleViolation;
|
||||
import net.sourceforge.pmd.reporting.ViolationSuppressor;
|
||||
|
||||
final class ApexViolationSuppressors {
|
||||
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.rule;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitor;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
import net.sourceforge.pmd.reporting.RuleContext;
|
||||
|
||||
public abstract class AbstractApexRule extends AbstractRule
|
||||
implements ApexParserVisitor {
|
||||
|
@ -10,7 +10,6 @@ import static net.sourceforge.pmd.properties.PropertyFactory.booleanProperty;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTForEachStatement;
|
||||
@ -27,6 +26,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
import net.sourceforge.pmd.reporting.RuleContext;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTAssignmentExpression;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDmlDeleteStatement;
|
||||
@ -57,6 +56,7 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.reporting.RuleContext;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
@ -10,7 +10,6 @@ import java.util.WeakHashMap;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDmlDeleteStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDmlInsertStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDmlMergeStatement;
|
||||
@ -26,6 +25,7 @@ import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
|
||||
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
|
||||
import net.sourceforge.pmd.reporting.RuleContext;
|
||||
|
||||
/**
|
||||
* Finds Apex class that do not define sharing
|
||||
|
@ -106,7 +106,7 @@ private class TestRunAs {
|
||||
since="6.13.0"
|
||||
language="apex"
|
||||
message="Apex test methods should have @isTest annotation."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation">
|
||||
<description>
|
||||
Apex test methods should have `@isTest` annotation instead of the `testMethod` keyword,
|
||||
@ -116,7 +116,6 @@ annotation for test classes and methods.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="version" value="2.0"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
@ -231,7 +230,7 @@ trigger Accounts on Account (before insert, before update, before delete, after
|
||||
since="6.18.0"
|
||||
language="apex"
|
||||
message="Calls to System.debug should specify a logging level."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel">
|
||||
<description>
|
||||
The first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum.
|
||||
|
@ -37,7 +37,7 @@ public class fooClass { } // This will be reported unless you change the regex
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using 'if...else' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#ifelsestmtsmustusebraces">
|
||||
<description>
|
||||
Avoid using if..else statements without using surrounding braces. If the code formatting
|
||||
@ -74,7 +74,7 @@ else
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using if statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#ifstmtsmustusebraces">
|
||||
<description>
|
||||
Avoid using if statements without using braces to surround the code block. If the code
|
||||
@ -156,7 +156,7 @@ public class Foo {
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using 'for' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#forloopsmustusebraces">
|
||||
<description>
|
||||
Avoid using 'for' statements without using surrounding braces. If the code formatting or
|
||||
@ -270,7 +270,7 @@ public class Foo {
|
||||
language="apex"
|
||||
since="6.7.0"
|
||||
message="Use one statement for each line, it enhances code readability."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#onedeclarationperline">
|
||||
<description>
|
||||
Apex allows the use of several variables declaration of the same type on one line. However, it
|
||||
@ -338,7 +338,7 @@ public class Foo {
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using 'while' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#whileloopsmustusebraces">
|
||||
<description>
|
||||
Avoid using 'while' statements without using braces to surround the code block. If the code
|
||||
|
@ -54,7 +54,7 @@ public class Foo {
|
||||
language="apex"
|
||||
since="6.0.0"
|
||||
message="Avoid directly accessing Trigger.old and Trigger.new"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermap">
|
||||
<description>
|
||||
Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be bulkified and iterate through the map to handle the actions for each item separately.
|
||||
@ -138,7 +138,7 @@ public without sharing class Foo {
|
||||
language="apex"
|
||||
since="6.0.0"
|
||||
message="Avoid empty catch blocks"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptycatchblock">
|
||||
<description>
|
||||
Empty Catch Block finds instances where an exception is caught, but nothing is done.
|
||||
@ -177,7 +177,7 @@ public void doSomething() {
|
||||
language="apex"
|
||||
since="6.0.0"
|
||||
message="Avoid empty 'if' statements"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptyifstmt">
|
||||
<description>
|
||||
Empty If Statement finds instances where a condition is checked but nothing is done about it.
|
||||
@ -210,7 +210,7 @@ public class Foo {
|
||||
language="apex"
|
||||
since="6.0.0"
|
||||
message="Avoid empty block statements."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptystatementblock">
|
||||
<description>
|
||||
Empty block statements serve no purpose and should be removed.
|
||||
@ -256,7 +256,7 @@ public class Foo {
|
||||
language="apex"
|
||||
since="6.0.0"
|
||||
message="Avoid empty try or finally blocks"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptytryorfinallyblock">
|
||||
<description>
|
||||
Avoid empty try or finally blocks - what's the point?
|
||||
@ -300,7 +300,7 @@ public class Foo {
|
||||
language="apex"
|
||||
since="6.0.0"
|
||||
message="Avoid empty 'while' statements"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptywhilestmt">
|
||||
<description>
|
||||
Empty While Statement finds all instances where a while statement does nothing.
|
||||
@ -454,7 +454,7 @@ public class Foo { // perfect, both methods provided
|
||||
language="apex"
|
||||
since="6.22.0"
|
||||
message="Test methods must be in test classes"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#testmethodsmustbeintestclasses">
|
||||
<description>
|
||||
Test methods marked as a testMethod or annotated with @IsTest,
|
||||
|
@ -13,7 +13,7 @@ Rules that flag suboptimal code.
|
||||
language="apex"
|
||||
since="6.36.0"
|
||||
message="Avoid debug statements since they impact on performance"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#avoiddebugstatements">
|
||||
<description>
|
||||
Debug statements contribute to longer transactions and consume Apex CPU time even when debug logs are not being captured.
|
||||
@ -24,7 +24,6 @@ For other valid use cases that the statement is in fact valid make use of the `@
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="version" value="2.0"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
@ -141,7 +140,7 @@ public class Something {
|
||||
language="apex"
|
||||
since="6.40.0"
|
||||
message="DescribeSObjectResult could be being loaded eagerly with all child relationships."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#eagerlyloadeddescribesobjectresult">
|
||||
<description>
|
||||
This rule finds `DescribeSObjectResult`s which could have been loaded eagerly via `SObjectType.getDescribe()`.
|
||||
@ -172,7 +171,6 @@ Properties:
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="noDefault" type="Boolean" value="false" description="Do not allow SObjectDescribeOptions.DEFAULT option to ensure consistent results no matter where getDescribe is called"/>
|
||||
<property name="version" value="2.0"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
|
@ -9,9 +9,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.AbstractRuleSetFactoryTest;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetLoader;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRuleSetFactoryTest;
|
||||
import net.sourceforge.pmd.lang.rule.RuleSet;
|
||||
import net.sourceforge.pmd.lang.rule.RuleSetLoader;
|
||||
|
||||
import com.github.stefanbirkner.systemlambda.SystemLambda;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex;
|
||||
|
||||
import net.sourceforge.pmd.AbstractRuleSetFactoryTest;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRuleSetFactoryTest;
|
||||
|
||||
class RuleSetFactoryTest extends AbstractRuleSetFactoryTest {
|
||||
// no additional tests yet
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user