diff --git a/.ci/build.sh b/.ci/build.sh
index eb7283cd6b..762cdc018d 100755
--- a/.ci/build.sh
+++ b/.ci/build.sh
@@ -323,7 +323,7 @@ ${rendered_release_notes}"
#
function pmd_ci_dogfood() {
local mpmdVersion=()
- ./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false
+ ./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION%-SNAPSHOT}-dogfood-SNAPSHOT" -DgenerateBackupPoms=false
sed -i 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *\)/'"${PMD_CI_MAVEN_PROJECT_VERSION}"'<\/version>\1/' pom.xml
./mvnw verify --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}" \
"${mpmdVersion[@]}" \
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 33c5ebb236..89690e8f81 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- - uses: actions/cache@v3
+ - uses: actions/cache@v4
with:
path: |
~/.m2/repository
diff --git a/.github/workflows/troubleshooting.yml b/.github/workflows/troubleshooting.yml
index 70006cb241..0b6b92788b 100644
--- a/.github/workflows/troubleshooting.yml
+++ b/.github/workflows/troubleshooting.yml
@@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- - uses: actions/cache@v3
+ - uses: actions/cache@v4
with:
path: |
~/.m2/repository
diff --git a/do-release.sh b/do-release.sh
index 89b02a1412..0e021f5b32 100755
--- a/do-release.sh
+++ b/do-release.sh
@@ -84,17 +84,12 @@ if [ "${BUILD_TOOLS_VERSION}" != "${BUILD_TOOLS_VERSION_RELEASE}" ]; then
exit 1
fi
-RELEASE_RULESET="pmd-core/src/main/resources/rulesets/releases/${RELEASE_VERSION//\./}.xml"
-
echo "* Update date info in **docs/_config.yml**."
echo " date: $(date -u +%d-%B-%Y)"
echo
echo "* Update version info in **docs/_config.yml**."
echo " remove the SNAPSHOT from site.pmd.version"
echo
-echo "* Ensure all the new rules are listed in the proper file:"
-echo " ${RELEASE_RULESET}"
-echo
echo "* Update **pmd-apex/src/main/resources/rulesets/apex/quickstart.xml** and"
echo " **pmd-java/src/main/resources/rulesets/java/quickstart.xml** with the new rules."
echo
@@ -151,11 +146,6 @@ EOF
echo "Committing current changes (pmd)"
-if [[ -e "${RELEASE_RULESET}" ]]
-then
- git add "${RELEASE_RULESET}"
-fi
-
git commit -a -m "Prepare pmd release ${RELEASE_VERSION}"
(
cd ../pmd.github.io
diff --git a/docs/_data/sidebars/pmd_sidebar.yml b/docs/_data/sidebars/pmd_sidebar.yml
index eaccf838e4..22741aaf1b 100644
--- a/docs/_data/sidebars/pmd_sidebar.yml
+++ b/docs/_data/sidebars/pmd_sidebar.yml
@@ -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
diff --git a/docs/_plugins/javadoc_tag.rb b/docs/_plugins/javadoc_tag.rb
index c31b9a655f..e4dd63e0de 100644
--- a/docs/_plugins/javadoc_tag.rb
+++ b/docs/_plugins/javadoc_tag.rb
@@ -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
diff --git a/docs/pages/pmd/devdocs/experimental/ast_dump.md b/docs/pages/pmd/devdocs/experimental/ast_dump.md
deleted file mode 100644
index 13c52f5f1d..0000000000
--- a/docs/pages/pmd/devdocs/experimental/ast_dump.md
+++ /dev/null
@@ -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=] [-f=] [--file=]
- [-l=] [-P=]...
-Experimental: dumps the AST of parsing source code
- -D, -v, --debug, --verbose
- Debug mode.
- -e, --encoding=
- Specifies the character set encoding of the source
- code files
- -f, --format= The output format.
- Valid values: xml, text
- --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=
- The source code language.
- Valid values: apex, ecmascript, html, java, jsp,
- kotlin, modelica, plsql, pom, scala, swift, vf, vm,
- wsdl, xml, xsl
- -P= 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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-$ xmlstarlet select -t -c "//VariableId[@VariableName='a']" Foo.xml
-
-```
-
-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);
- }
-}
-```
diff --git a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md
index 8f05cf0ac2..249da18808 100644
--- a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md
+++ b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md
@@ -119,15 +119,15 @@ definitely don't come for free. It is much effort and requires perseverance to i
### 5. Create a TokenManager
* This is needed to support CPD (copy paste detection)
-* We provide a default implementation using [`AntlrTokenManager`](https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java).
-* You must create your own "AntlrTokenizer" such as we do with
- [`SwiftTokenizer`](https://github.com/pmd/pmd/blob/master/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/cpd/SwiftTokenizer.java).
+* We provide a default implementation using [`AntlrTokenManager`](https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java).
+* You must create your own "AntlrCpdLexer" such as we do with
+ [`SwiftCpdLexer`](https://github.com/pmd/pmd/blob/master/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/cpd/SwiftCpdLexer.java).
* If you wish to filter specific tokens (e.g. comments to support CPD suppression via "CPD-OFF" and "CPD-ON")
you can create your own implementation of
[`AntlrTokenFilter`](https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenFilter.java).
You'll need to override then the protected method `getTokenFilter(AntlrTokenManager)`
- and return your custom filter. See the tokenizer for C# as an exmaple:
- [`CsTokenizer`](https://github.com/pmd/pmd/blob/master/pmd-cs/src/main/java/net/sourceforge/pmd/lang/cs/cpd/CsTokenizer.java).
+ and return your custom filter. See the CpdLexer for C# as an exmaple:
+ [`CsCpdLexer`](https://github.com/pmd/pmd/blob/master/pmd-cs/src/main/java/net/sourceforge/pmd/lang/cs/cpd/CsCpdLexer.java).
If you don't need a custom token filter, you don't need to override the method. It returns the default
`AntlrTokenFilter` which doesn't filter anything.
diff --git a/docs/pages/pmd/devdocs/major_contributions/adding_new_cpd_language.md b/docs/pages/pmd/devdocs/major_contributions/adding_new_cpd_language.md
index 665aa7ce18..9261c50e18 100644
--- a/docs/pages/pmd/devdocs/major_contributions/adding_new_cpd_language.md
+++ b/docs/pages/pmd/devdocs/major_contributions/adding_new_cpd_language.md
@@ -11,7 +11,7 @@ author: Matías Fraga, Clément Fournier
## Adding support for a CPD language
CPD works generically on the tokens produced by a {% jdoc core::cpd.Tokenizer %}.
-To add support for a new language, the crucial piece is writing a tokenizer that
+To add support for a new language, the crucial piece is writing a CpdLexer that
splits the source file into the tokens specific to your language. Thankfully you
can use a stock [Antlr grammar](https://github.com/antlr/grammars-v4) or JavaCC
grammar to generate a lexer for you. If you cannot use a lexer generator, for
@@ -31,12 +31,12 @@ Use the following guide to set up a new language module that supports CPD.
the lexer from the grammar. To do so, edit `pom.xml` (eg like [the Golang module](https://github.com/pmd/pmd/tree/master/pmd-go/pom.xml)).
Once that is done, `mvn generate-sources` should generate the lexer sources for you.
- You can now implement a tokenizer, for instance by extending {% jdoc core::cpd.impl.AntlrTokenizer %}. The following reproduces the Go implementation:
+ You can now implement a CpdLexer, for instance by extending {% jdoc core::cpd.impl.AntlrCpdLexer %}. The following reproduces the Go implementation:
```java
// mind the package convention if you are going to make a PR
package net.sourceforge.pmd.lang.go.cpd;
- public class GoTokenizer extends AntlrTokenizer {
+ public class GoCpdLexer extends AntlrCpdLexer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
@@ -64,9 +64,9 @@ If your language only supports CPD, then you can subclass {% jdoc core::lang.imp
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- // This method should return an instance of the tokenizer you created.
- return new GoTokenizer();
+ public Tokenizer createCpdLexer(LanguagePropertyBundle bundle) {
+ // This method should return an instance of the CpdLexer you created.
+ return new GoCpdLexer();
}
}
```
@@ -77,7 +77,7 @@ If your language only supports CPD, then you can subclass {% jdoc core::lang.imp
4. Update the test that asserts the list of supported languages by updating the `SUPPORTED_LANGUAGES` constant in [BinaryDistributionIT](https://github.com/pmd/pmd/blob/master/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java).
-5. Add some tests for your tokenizer by following the [section below](#testing-your-implementation).
+5. Add some tests for your CpdLexer by following the [section below](#testing-your-implementation).
6. Finishing up your new language module by adding a page in the documentation. Create a new markdown file
`.md` in `docs/pages/pmd/languages/`. This file should have the following frontmatter:
@@ -100,10 +100,10 @@ If your language only supports CPD, then you can subclass {% jdoc core::lang.imp
{% endraw %}
```
-### Declaring tokenizer options
+### Declaring CpdLexer options
-To make the tokenizer configurable, first define some property descriptors using
-{% jdoc core::properties.PropertyFactory %}. Look at {% jdoc core::cpd.Tokenizer %}
+To make the CpdLexer configurable, first define some property descriptors using
+{% jdoc core::properties.PropertyFactory %}. Look at {% jdoc core::cpd.CpdLexer %}
for some predefined ones which you can reuse (prefer reusing property descriptors if you can).
You need to override {% jdoc core::Language#newPropertyBundle() %}
and call `definePropertyDescriptor` to register the descriptors.
@@ -112,13 +112,13 @@ of {% jdoc core::cpd.CpdCapableLanguage#createCpdTokenizer(core::lang.LanguagePr
To implement simple token filtering, you can use {% jdoc core::cpd.impl.BaseTokenFilter %}
as a base class, or another base class in {% jdoc_package core::cpd.impl %}.
-Take a look at the [Kotlin token filter implementation](https://github.com/pmd/pmd/blob/master/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/cpd/KotlinTokenizer.java), or the [Java one](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizer.java).
+Take a look at the [Kotlin token filter implementation](https://github.com/pmd/pmd/blob/master/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/cpd/KotlinCpdLexer.java), or the [Java one](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/cpd/JavaCpdLexer.java).
### Testing your implementation
Add a Maven dependency on `pmd-lang-test` (scope `test`) in your `pom.xml`.
-This contains utilities to test your tokenizer.
+This contains utilities to test your CpdLexer.
Create a test class extending from {% jdoc lang-test::cpd.test.CpdTextComparisonTest %}.
To add tests, you need to write regular JUnit `@Test`-annotated methods, and
diff --git a/docs/pages/pmd/devdocs/writing_documentation.md b/docs/pages/pmd/devdocs/writing_documentation.md
index 196823239e..53c7be347f 100644
--- a/docs/pages/pmd/devdocs/writing_documentation.md
+++ b/docs/pages/pmd/devdocs/writing_documentation.md
@@ -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`, ....
diff --git a/docs/pages/pmd/languages/java.md b/docs/pages/pmd/languages/java.md
index c59a841c50..6354280cae 100644
--- a/docs/pages/pmd/languages/java.md
+++ b/docs/pages/pmd/languages/java.md
@@ -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
diff --git a/docs/pages/pmd/languages/language_properties.md b/docs/pages/pmd/languages/language_properties.md
index 91f396489f..9520ae1fd0 100644
--- a/docs/pages/pmd/languages/language_properties.md
+++ b/docs/pages/pmd/languages/language_properties.md
@@ -24,7 +24,7 @@ PropertyName is the name of the property converted to SCREAMING_SNAKE_CASE, that
As a convention, properties whose name start with an *x* are internal and may be removed or changed without notice.
-Properties whose name start with **CPD** are used to configure CPD tokenizer options.
+Properties whose name start with **CPD** are used to configure CPD CpdLexer options.
Programmatically, the language properties can be set on `PMDConfiguration` (or `CPDConfiguration`) before using the
{%jdoc core::PmdAnalyzer %} (or {%jdoc core::cpd.CpdAnalyzer %}) instance
diff --git a/docs/pages/pmd/projectdocs/committers/releasing.md b/docs/pages/pmd/projectdocs/committers/releasing.md
index 28b4049b03..caa058dfec 100644
--- a/docs/pages/pmd/projectdocs/committers/releasing.md
+++ b/docs/pages/pmd/projectdocs/committers/releasing.md
@@ -81,8 +81,6 @@ pmd:
The release type could be one of "bugfix" (e.g. 6.34.x), "minor" (6.x.0), or "major" (x.0.0).
The release notes usually mention any new rules that have been added since the last release.
-Please double-check the file `pmd-core/src/main/resources/rulesets/releases/.xml`, so
-that all new rules are listed.
Add the new rules as comments to the quickstart rulesets:
* `pmd-apex/src/main/resources/rulesets/apex/quickstart.xml`
diff --git a/docs/pages/pmd/userdocs/extending/ast_dump.md b/docs/pages/pmd/userdocs/extending/ast_dump.md
new file mode 100644
index 0000000000..f8801d0bb8
--- /dev/null
+++ b/docs/pages/pmd/userdocs/extending/ast_dump.md
@@ -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=] [-f=] [--file=]
+ [-l=] [-P=]...
+Dumps the AST of parsing source code
+ -D, -v, --debug, --verbose
+ Debug mode.
+ -e, --encoding=
+ Specifies the character set encoding of the source
+ code files
+ -f, --format= The output format.
+ Valid values: xml, text
+ --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=
+ The source code language.
+ Valid values: apex, ecmascript, html, java, jsp,
+ kotlin, modelica, plsql, pom, scala, swift, vf, vm,
+ wsdl, xml, xsl
+ -P= 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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+$ xmlstarlet select -t -c "//VariableId[@VariableName='a']" Foo.xml
+
+```
+
+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);
+ }
+ }
+}
+```
diff --git a/docs/pages/pmd/userdocs/extending/defining_properties.md b/docs/pages/pmd/userdocs/extending/defining_properties.md
index 3551accd42..dfda872abc 100644
--- a/docs/pages/pmd/userdocs/extending/defining_properties.md
+++ b/docs/pages/pmd/userdocs/extending/defining_properties.md
@@ -165,7 +165,6 @@ with a backslash when needed.
```xml
-
diff --git a/docs/pages/pmd/userdocs/extending/writing_java_rules.md b/docs/pages/pmd/userdocs/extending/writing_java_rules.md
index 6024542609..ee71109161 100644
--- a/docs/pages/pmd/userdocs/extending/writing_java_rules.md
+++ b/docs/pages/pmd/userdocs/extending/writing_java_rules.md
@@ -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
diff --git a/docs/pages/pmd/userdocs/extending/writing_rules_intro.md b/docs/pages/pmd/userdocs/extending/writing_rules_intro.md
index 74c3978b70..43fece776c 100644
--- a/docs/pages/pmd/userdocs/extending/writing_rules_intro.md
+++ b/docs/pages/pmd/userdocs/extending/writing_rules_intro.md
@@ -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:
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
Description
diff --git a/docs/pages/pmd/userdocs/extending/writing_xpath_rules.md b/docs/pages/pmd/userdocs/extending/writing_xpath_rules.md
index a0bc692c6c..a374d5abd6 100644
--- a/docs/pages/pmd/userdocs/extending/writing_xpath_rules.md
+++ b/docs/pages/pmd/userdocs/extending/writing_xpath_rules.md
@@ -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
diff --git a/docs/pages/pmd/userdocs/extending/your_first_rule.md b/docs/pages/pmd/userdocs/extending/your_first_rule.md
index 873324db0c..30c2f98e13 100644
--- a/docs/pages/pmd/userdocs/extending/your_first_rule.md
+++ b/docs/pages/pmd/userdocs/extending/your_first_rule.md
@@ -127,7 +127,7 @@ copy-paste into your ruleset XML. The resulting element looks like so:
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
TODO
diff --git a/docs/pages/pmd/userdocs/migrating_to_pmd7.md b/docs/pages/pmd/userdocs/migrating_to_pmd7.md
index 675a46ad74..501f40c49e 100644
--- a/docs/pages/pmd/userdocs/migrating_to_pmd7.md
+++ b/docs/pages/pmd/userdocs/migrating_to_pmd7.md
@@ -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`
@@ -42,6 +42,22 @@ There are a couple of deprecated things in PMD 6, you might encounter:
```
and often already suggest an alternative.
+* If you still reference rulesets or rules the old way which has been deprecated since 6.46.0:
+ - `-`, eg `java-basic`, which resolves to `rulesets/java/basic.xml`
+ - the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml`
+
+ Such usages produce deprecation warnings that should be easy to spot, e.g.
+ ```
+ Ruleset reference 'java-basic' uses a deprecated form, use 'rulesets/java/basic.xml' instead
+ ```
+
+ Use the explicit forms of these references to be compatible with PMD 7.
+
+ Note: Since PMD 6, all rules are sorted into categories (such as "Best Practices", "Design", "Error Prone")
+ and the old rulesets like `basic.xml` have been deprecated and have been removed with PMD 7.
+ It is about time to create a [custom ruleset](pmd_userdocs_making_rulesets.html).
+
+
## Use cases
### I'm using only built-in rules
@@ -93,9 +109,14 @@ 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).
Additional infos:
* The custom XPath function `typeOf` has been removed (deprecated since 6.4.0).
@@ -142,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.
@@ -184,6 +205,7 @@ Most notable changes:
an error message such as `[main] ERROR net.sourceforge.pmd.cli.commands.internal.PmdCommand - No such file false`.
* PMD tries to display a progress bar. If you don't want this (e.g. on a CI build server), you can disable this
with `--no-progress`.
+ * `--no-ruleset-compatibility` has been removed
### Custom distribution packages
@@ -387,6 +409,144 @@ XPath 1.0 and 2.0 queries. Here's a list of known incompatibilities:
since there is a built-in function available since XPath 2.0 which can be used instead. If you use "pmd:matches"
simply remove the "pmd:" prefix.
+### General AST Changes to avoid @Image
+
+An abstract syntax tree should be abstract, but in the same time, should not be too abstract. One of the
+base interfaces for PMD's AST for all languages is {% jdoc core::lang.ast.Node %}, which provides
+the methods {% jdoc core::lang.ast.Node#getImage() %} and {% jdoc core::lang.ast.Node#hasImageEqualTo(java.lang.String) %}.
+However, these methods don't necessarily make sense for all nodes in all contexts. That's why `getImage()`
+often returns just `null`. Also, the name is not very describing. AST nodes should try to use more specific
+names, such as `getValue()` or `getName()`.
+
+For PMD 7, most languages have been adapted. And when writing XPath rules, you need to replace `@Image` with
+whatever is appropriate now (e.g. `@Name`). See below for details.
+
+#### Apex and Visualforce
+
+There are many usages of `@Image`. These will be refactored after PMD 7 is released
+by deprecating the attribute and providing alternatives.
+
+See also issue [Deprecate getImage/@Image #4787](https://github.com/pmd/pmd/issues/4787).
+
+#### Html
+
+* {% jdoc html::lang.html.ast.ASTHtmlTextNode %}: `@Image` ➡️ `@Text`, `@NormalizedText` ➡️ `@Text`, `@Text` ➡️ `@WholeText`.
+
+#### Java
+
+There are still many usages of `@Image` which are not refactored yet. This will be done after PMD 7 is released
+by deprecating the attribute and providing alternatives.
+
+See also issue [Deprecate getImage/@Image #4787](https://github.com/pmd/pmd/issues/4787).
+
+Some nodes have already the image attribute (and others) deprecated. These deprecated attributes are removed now:
+
+* {% jdoc java::lang.java.ast.ASTAnnotationTypeDeclaration %}: `@Image` ➡️ `@SimpleName`
+* {% jdoc java::lang.java.ast.ASTAnonymousClassDeclaration %}: `@Image` ➡️ `@SimpleName`
+* {% jdoc java::lang.java.ast.ASTClassOrInterfaceDeclaration %}: `@Image` ➡️ `@SimpleName`
+* {% jdoc java::lang.java.ast.ASTEnumDeclaration %}: `@Image` ➡️ `@SimpleName`
+* {% jdoc java::lang.java.ast.ASTFieldDeclaration %}: `@VariableName` ➡️ `VariableDeclaratorId/@Name`
+* {% jdoc java::lang.java.ast.ASTMethodDeclaration %}: `@MethodName` ➡️ `@Name`
+* {% jdoc java::lang.java.ast.ASTRecordDeclaration %}: `@Image` ➡️ `@SimpleName`
+* {% jdoc java::lang.java.ast.ASTVariableDeclaratorId %}: `@Image` ➡️ `@Name`
+* {% jdoc java::lang.java.ast.ASTVariableDeclaratorId %}: `@VariableName` ➡️ `@Name`
+* {% jdoc java::lang.java.ast.ASTVariableDeclaratorId %}: `@Array` ➡️ `@ArrayType`
+
+#### JavaScript
+
+* {% jdoc javascript::lang.ecmascript.ast.ASTAssignment %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTBigIntLiteral %}: `@Image` ➡️ `@Value`
+* {% jdoc javascript::lang.ecmascript.ast.ASTBreakStatement %}: `@Image` ➡️ `Name/@Identifier`
+* {% jdoc javascript::lang.ecmascript.ast.ASTContinueStatement %}: `@Image` ➡️ `Name/@Identifier`
+* {% jdoc javascript::lang.ecmascript.ast.ASTErrorNode %}: `@Image` ➡️ `@Message`
+* {% jdoc javascript::lang.ecmascript.ast.ASTFunctionNode %}: `@Image` ➡️ `Name/@Identifier`
+* {% jdoc javascript::lang.ecmascript.ast.ASTInfixExpression %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTKeywordLiteral %}: `@Image` ➡️ `@Literal`
+* {% jdoc javascript::lang.ecmascript.ast.ASTLabel %}: `@Image` ➡️ `@Name`
+* {% jdoc javascript::lang.ecmascript.ast.ASTName %}: `@Image` ➡️ `@Identifier`
+* {% jdoc javascript::lang.ecmascript.ast.ASTNumberLiteral %}: `@Image` ➡️ `@Value`
+* {% jdoc javascript::lang.ecmascript.ast.ASTObjectProperty %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTPropertyGet %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTRegExpLiteral %}: `@Image` ➡️ `@Value`
+* {% jdoc javascript::lang.ecmascript.ast.ASTStringLiteral %}: `@Image` ➡️ `@Value`
+* {% jdoc javascript::lang.ecmascript.ast.ASTUnaryExpression %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTUpdateExpression %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTXmlDotQuery %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTXmlMemberGet %}: `@Image` ➡️ `@Operator`
+* {% jdoc javascript::lang.ecmascript.ast.ASTXmlPropRef %}: `@Image` ➡️ `Name[last()]/@Identifier`
+* {% jdoc javascript::lang.ecmascript.ast.ASTXmlString %}: `@Image` ➡️ `@Xml`
+
+#### JSP
+
+* {% jdoc jsp::lang.jsp.ast.ASTAttributeValue %}: `@Image` ➡️ `@Value`
+* {% jdoc jsp::lang.jsp.ast.ASTCData %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTCommentTag %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTElExpression %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTHtmlScript %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTJspComment %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTJspDeclaration %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTJspExpression %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTJspExpressionInAttribute %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTJspScriptlet %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTText %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTUnparsedText %}: `@Image` ➡️ `@Content`
+* {% jdoc jsp::lang.jsp.ast.ASTValueBinding %}: `@Image` ➡️ `@Content`
+
+#### Modelica
+
+* {% jdoc modelica::lang.modelica.ast.ASTAddOp %}: `@Image` ➡️ `@Operator`
+* {% jdoc modelica::lang.modelica.ast.ASTDerClassSpecifier %}: `@Image` ➡️ `@SimpleClassName`
+* {% jdoc modelica::lang.modelica.ast.ASTEnumerationShortClassSpecifier %}: `@Image` ➡️ `@SimpleClassName`
+* {% jdoc modelica::lang.modelica.ast.ASTExtendingLongClassSpecifier %}: `@Image` ➡️ `@SimpleClassName`
+* {% jdoc modelica::lang.modelica.ast.ASTFactor %}: `@Image` ➡️ `@Operator`
+* {% jdoc modelica::lang.modelica.ast.ASTLanguageSpecification %}: `@Image` ➡️ `@ExternalLanguage`
+* {% jdoc modelica::lang.modelica.ast.ASTMulOp %}: `@Image` ➡️ `@Operator`
+* {% jdoc modelica::lang.modelica.ast.ASTName %}: `@Image` ➡️ `@Name`
+* {% jdoc modelica::lang.modelica.ast.ASTNumberLiteral %}: `@Image` ➡️ `@Value`
+* {% jdoc modelica::lang.modelica.ast.ASTRelOp %}: `@Image` ➡️ `@Operator`
+* {% jdoc modelica::lang.modelica.ast.ASTSimpleLongClassSpecifier %}: `@Image` ➡️ `@SimpleClassName`
+* {% jdoc modelica::lang.modelica.ast.ASTSimpleName %}: `@Image` ➡️ `@Name`
+* {% jdoc modelica::lang.modelica.ast.ASTSimpleShortClassSpecifier %}: `@Image` ➡️ `@SimpleClassName`
+* {% jdoc modelica::lang.modelica.ast.ASTStoredDefinition %}: `@Image` ➡️ `@Name`
+* {% jdoc modelica::lang.modelica.ast.ASTStringComment %}: `@Image` ➡️ `@Comment`
+* {% jdoc modelica::lang.modelica.ast.ASTStringLiteral %}: `@Image` ➡️ `@Value`
+* {% jdoc modelica::lang.modelica.ast.ASTWithinClause %}: `@Image` ➡️ `@Name`
+
+#### PLSQL
+
+There are many usages of `@Image`. These will be refactored after PMD 7 is released
+by deprecating the attribute and providing alternatives.
+
+See also issue [Deprecate getImage/@Image #4787](https://github.com/pmd/pmd/issues/4787).
+
+#### Scala
+
+* {% jdoc scala::lang.scala.ast.ASTLitBoolean %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitByte %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitChar %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitDouble %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitFloat %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitInt %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitLong %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitNull %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitShort %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitString %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitSymbol %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTLitUnit %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTNameAnonymous %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTNameIndeterminate %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTTermName %}: `@Image` ➡️ `@Value`
+* {% jdoc scala::lang.scala.ast.ASTTypeName %}: `@Image` ➡️ `@Value`
+
+#### XML (and POM)
+
+When using {% jdoc core::lang.rule.XPathRule %}, text of text nodes was exposed as `@Image` of
+normal element type nodes. Now the attribute is called `@Text`.
+
+Note: In general, it is recommended to use {% jdoc xml::lang.xml.rule.DomXPathRule %} instead,
+which exposes text nodes as real XPath/XML text nodes which conforms to the XPath spec.
+There is no difference, text of text nodes can be selected using `text()`.
+
### Java AST
The Java grammar has been refactored substantially in order to make it easier to maintain and more correct
diff --git a/docs/pages/pmd/userdocs/pmd_report_formats.md b/docs/pages/pmd/userdocs/pmd_report_formats.md
index 05dafb2253..33961afabc 100644
--- a/docs/pages/pmd/userdocs/pmd_report_formats.md
+++ b/docs/pages/pmd/userdocs/pmd_report_formats.md
@@ -254,10 +254,6 @@ Was expecting one of:
* warnings: 2
-**Properties:**
-
-* color: Enables colors with anything other than `false` or `0`. Default: yes.
-
## textpad
TextPad integration.
diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index 807c351f3b..ce54c5e3a5 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -83,6 +83,12 @@ in the Migration Guide.
* We now support [suppression](pmd_userdocs_cpd.html#suppression) through `CPD-ON`/`CPD-OFF` comment pairs.
* See [PR #4726](https://github.com/pmd/pmd/pull/4726) for details.
+##### Updated PMD Designer
+
+This PMD release ships a new version of the pmd-designer.
+For the changes, see
+* [PMD Designer Changelog (7.0.0)](https://github.com/pmd/pmd-designer/releases/tag/7.0.0).
+
#### Rule Changes
**New Rules**
@@ -97,6 +103,67 @@ in the Migration Guide.
* {% rule java/codestyle/EmptyControlStatement %}: The rule has a new property to allow empty blocks when
they contain a comment (`allowCommentedBlocks`).
+**Removed deprecated rulesets**
+
+The following previously deprecated rulesets have been removed. These were the left-over rulesets from PMD 5.
+The rules have been moved into categories with PMD 6.
+
+* rulesets/apex/apexunit.xml
+* rulesets/apex/braces.xml
+* rulesets/apex/complexity.xml
+* rulesets/apex/empty.xml
+* rulesets/apex/metrics.xml
+* rulesets/apex/performance.xml
+* rulesets/apex/ruleset.xml
+* rulesets/apex/securty.xml
+* rulesets/apex/style.xml
+* rulesets/java/android.xml
+* rulesets/java/basic.xml
+* rulesets/java/clone.xml
+* rulesets/java/codesize.xml
+* rulesets/java/comments.xml
+* rulesets/java/controversial.xml
+* rulesets/java/coupling.xml
+* rulesets/java/design.xml
+* rulesets/java/empty.xml
+* rulesets/java/finalizers.xml
+* rulesets/java/imports.xml
+* rulesets/java/j2ee.xml
+* rulesets/java/javabeans.xml
+* rulesets/java/junit.xml
+* rulesets/java/logging-jakarta-commons.xml
+* rulesets/java/logging-java.xml
+* rulesets/java/metrics.xml
+* rulesets/java/migrating.xml
+* rulesets/java/migrating_to_13.xml
+* rulesets/java/migrating_to_14.xml
+* rulesets/java/migrating_to_15.xml
+* rulesets/java/migrating_to_junit4.xml
+* rulesets/java/naming.xml
+* rulesets/java/optimizations.xml
+* rulesets/java/strictexception.xml
+* rulesets/java/strings.xml
+* rulesets/java/sunsecure.xml
+* rulesets/java/typeresolution.xml
+* rulesets/java/unnecessary.xml
+* rulesets/java/unusedcode.xml
+* rulesets/ecmascript/basic.xml
+* rulesets/ecmascript/braces.xml
+* rulesets/ecmascript/controversial.xml
+* rulesets/ecmascript/unnecessary.xml
+* rulesets/jsp/basic.xml
+* rulesets/jsp/basic-jsf.xml
+* rulesets/plsql/codesize.xml
+* rulesets/plsql/dates.xml
+* rulesets/plsql/strictsyntax.xml
+* rulesets/plsql/TomKytesDespair.xml
+* rulesets/vf/security.xml
+* rulesets/vm/basic.xml
+* rulesets/pom/basic.xml
+* rulesets/xml/basic.xml
+* rulesets/xsl/xpath.xml
+* rulesets/releases/*
+
#### Fixed issues
* cli
@@ -105,11 +172,21 @@ in the Migration Guide.
* [#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`
* [#4348](https://github.com/pmd/pmd/issues/4348): \[core] Consolidate @InternalApi classes
+ * [#4378](https://github.com/pmd/pmd/issues/4378): \[core] Ruleset loading processes commented rules
* [#4674](https://github.com/pmd/pmd/issues/4674): \[core] WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass
* [#4694](https://github.com/pmd/pmd/pull/4694): \[core] Fix line/col numbers in TokenMgrError
* [#4717](https://github.com/pmd/pmd/issues/4717): \[core] XSLTRenderer doesn't close report file
* [#4750](https://github.com/pmd/pmd/pull/4750): \[core] Fix flaky SummaryHTMLRenderer
+ * [#4782](https://github.com/pmd/pmd/pull/4782): \[core] Avoid using getImage/@Image
* doc
* [#995](https://github.com/pmd/pmd/issues/995): \[doc] Document API evolution principles as ADR
* [#2511](https://github.com/pmd/pmd/issues/2511): \[doc] Review guides for writing java/xpath rules for correctness with PMD 7
@@ -126,6 +203,7 @@ in the Migration Guide.
* [#4736](https://github.com/pmd/pmd/issues/4736): \[ci] Improve build procedure
* [#4741](https://github.com/pmd/pmd/pull/4741): Add pmd-compat6 module for maven-pmd-plugin
* [#4749](https://github.com/pmd/pmd/pull/4749): Fixes NoSuchMethodError on processing errors in pmd-compat6
+ * [#4796](https://github.com/pmd/pmd/pull/4796): Remove deprecated and release rulesets
* apex-performance
* [#4675](https://github.com/pmd/pmd/issues/4675): \[apex] New Rule: OperationWithHighCostInLoop
* groovy
@@ -155,6 +233,41 @@ in the Migration Guide.
#### 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 and interfaces and methods**
The following classes/methods have been marked as @InternalApi before and are now moved into a `internal`
@@ -186,6 +299,12 @@ package or made (package) private and are _not accessible_ anymore.
* {%jdoc !!core::RuleContext %}
* Method `getRule()` is now package private.
* Method `create(FileAnalysisListener listener, Rule rule)` has been removed.
+ * `net.sourceforge.pmd.rules.RuleFactory`: moved into subpackage `lang.rule` and made package private.
+ It has now been hidden completely from public API.
+ * Many types have been moved from into subpackage `lang.rule.internal`.
+ * `net.sourceforge.pmd.RuleSetReference`
+ * `net.sourceforge.pmd.RuleSetReferenceId`
+ * `net.sourceforge.pmd.RuleSets`
* pmd-ant
* {%jdoc !!ant::ant.Formatter %}
* Method `getRenderer()` has been removed.
@@ -277,6 +396,27 @@ The following previously deprecated classes have been removed:
* The node `ASTClassOrInterfaceBody` has been renamed to {% jdoc java::lang.ast.ASTClassBody %}. XPath rules
need to be adjusted.
+**Renamed classes and methods**
+
+* pmd-core
+ * {%jdoc_old core::lang.ast.TokenMgrError %} has been renamed to {% jdoc core::lang.ast.LexException %}
+ * {%jdoc_old core::cpd.Tokenizer %} has been renamed to {% jdoc core::cpd.CpdLexer %}. Along with this rename,
+ all the implementations have been renamed as well (`Tokenizer` -> `CpdLexer`), e.g. "CppCpdLexer", "JavaCpdLexer".
+ This affects all language modules.
+ * {%jdoc_old core::cpd.AnyTokenizer %} has been renamed to {% jdoc core::cpd.AnyCpdLexer %}.
+
+**Removed functionality**
+
+* The CLI parameter `--no-ruleset-compatibility` has been removed. It was only used to allow loading
+ some rulesets originally written for PMD 5 also in PMD 6 without fixing the rulesets.
+* The class {% jdoc_old core::RuleSetFactoryCompatibility %} has been removed without replacement.
+ The different ways to enable/disable this filter in {% jdoc core::PMDConfiguration %}
+ (Property "RuleSetFactoryCompatibilityEnabled") and
+ {% jdoc ant::ant.PMDTask %} (Property "noRuleSetCompatibility") have been removed as well.
+* `textcolor` renderer ({%jdoc core::renderers.TextColorRenderer %}) now renders always in color.
+ The property `color` has been removed. The possibility to override this with the system property `pmd.color`
+ has been removed as well. If you don't want colors, use `text` renderer ({%jdoc core::renderers.TextRenderer %}).
+
#### External Contributions
* [#4640](https://github.com/pmd/pmd/pull/4640): \[cli] Launch script fails if run via "bash pmd" - [Shai Bennathan](https://github.com/shai-bennathan) (@shai-bennathan)
* [#4673](https://github.com/pmd/pmd/pull/4673): \[javascript] CPD: Added support for decorator notation - [Wener](https://github.com/wener-tiobe) (@wener-tiobe)
@@ -342,7 +482,10 @@ Contributors: [Lucas Soncini](https://github.com/lsoncini) (@lsoncini),
#### Updated PMD Designer
This PMD release ships a new version of the pmd-designer.
-For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designer/releases/tag/7.0.0-rc1).
+For the changes, see
+* [PMD Designer Changelog (7.0.0-rc1)](https://github.com/pmd/pmd-designer/releases/tag/7.0.0-rc1).
+* [PMD Designer Changelog (7.0.0-rc4)](https://github.com/pmd/pmd-designer/releases/tag/7.0.0-rc4).
+* [PMD Designer Changelog (7.0.0)](https://github.com/pmd/pmd-designer/releases/tag/7.0.0).
#### New CPD report format cpdhtml-v2.xslt
@@ -648,6 +791,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
* [#4736](https://github.com/pmd/pmd/issues/4736): \[ci] Improve build procedure
* [#4741](https://github.com/pmd/pmd/pull/4741): Add pmd-compat6 module for maven-pmd-plugin
* [#4749](https://github.com/pmd/pmd/pull/4749): Fixes NoSuchMethodError on processing errors in pmd-compat6
+ * [#4796](https://github.com/pmd/pmd/pull/4796): Remove deprecated and release rulesets
* ant
* [#4080](https://github.com/pmd/pmd/issues/4080): \[ant] Split off Ant integration into a new submodule
* core
@@ -676,19 +820,28 @@ 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
* [#4035](https://github.com/pmd/pmd/issues/4035): \[core] ConcurrentModificationException in DefaultRuleViolationFactory
+ * [#4065](https://github.com/pmd/pmd/issues/4065): \[core] Rename TokenMgrError to LexException, Tokenizer to CpdLexer
* [#4120](https://github.com/pmd/pmd/issues/4120): \[core] Explicitly name all language versions
* [#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`
* [#4323](https://github.com/pmd/pmd/issues/4323): \[core] Refactor CPD integration
* [#4348](https://github.com/pmd/pmd/issues/4348): \[core] Consolidate @InternalApi classes
* [#4353](https://github.com/pmd/pmd/pull/4353): \[core] Micro optimizations for Node API
* [#4365](https://github.com/pmd/pmd/pull/4365): \[core] Improve benchmarking
* [#4397](https://github.com/pmd/pmd/pull/4397): \[core] Refactor CPD
+ * [#4378](https://github.com/pmd/pmd/issues/4378): \[core] Ruleset loading processes commented rules
* [#4420](https://github.com/pmd/pmd/pull/4420): \[core] Remove PMD.EOL
* [#4425](https://github.com/pmd/pmd/pull/4425): \[core] Replace TextFile::pathId
* [#4454](https://github.com/pmd/pmd/issues/4454): \[core] "Unknown option: '-min'" but is referenced in documentation
@@ -698,6 +851,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
* [#4694](https://github.com/pmd/pmd/pull/4694): \[core] Fix line/col numbers in TokenMgrError
* [#4717](https://github.com/pmd/pmd/issues/4717): \[core] XSLTRenderer doesn't close report file
* [#4750](https://github.com/pmd/pmd/pull/4750): \[core] Fix flaky SummaryHTMLRenderer
+ * [#4782](https://github.com/pmd/pmd/pull/4782): \[core] Avoid using getImage/@Image
* cli
* [#2234](https://github.com/pmd/pmd/issues/2234): \[core] Consolidate PMD CLI into a single command
* [#3828](https://github.com/pmd/pmd/issues/3828): \[core] Progress reporting
diff --git a/docs/pages/release_notes_old.md b/docs/pages/release_notes_old.md
index 7cd6e5d5c3..478e5781c5 100644
--- a/docs/pages/release_notes_old.md
+++ b/docs/pages/release_notes_old.md
@@ -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.
diff --git a/docs/pages/release_notes_pmd7.md b/docs/pages/release_notes_pmd7.md
index f02b8a1ff8..cf71d941ff 100644
--- a/docs/pages/release_notes_pmd7.md
+++ b/docs/pages/release_notes_pmd7.md
@@ -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.
diff --git a/javacc-wrapper.xml b/javacc-wrapper.xml
index 601b91bb66..ece4307099 100644
--- a/javacc-wrapper.xml
+++ b/javacc-wrapper.xml
@@ -280,6 +280,13 @@
+
+
+
+
+
+
+
diff --git a/pmd-ant/pom.xml b/pmd-ant/pom.xml
index 26e41e525d..f8c867276c 100644
--- a/pmd-ant/pom.xml
+++ b/pmd-ant/pom.xml
@@ -45,11 +45,6 @@
slf4j-simpletest
-
- com.github.tomakehurst
- wiremock-jre8
- test
- org.hamcresthamcrest
diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java
index 4a562c3289..a59a4c8835 100644
--- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java
+++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java
@@ -15,8 +15,8 @@ import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
-import net.sourceforge.pmd.RulePriority;
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
@@ -58,7 +58,6 @@ public class PMDTask extends Task {
private final List relativizePathsWith = new ArrayList<>();
private String suppressMarker;
private String rulesetFiles;
- private boolean noRuleSetCompatibility;
private String encoding;
private int threads = 1; // same default as in PMDParameters (CLI)
private int minimumPriority = RulePriority.LOW.getPriority(); // inclusive
@@ -264,14 +263,6 @@ public class PMDTask extends Task {
return nestedRules;
}
- public boolean isNoRuleSetCompatibility() {
- return noRuleSetCompatibility;
- }
-
- public void setNoRuleSetCompatibility(boolean noRuleSetCompatibility) {
- this.noRuleSetCompatibility = noRuleSetCompatibility;
- }
-
public String getCacheLocation() {
return cacheLocation;
}
diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java
index e800a34454..e35a8ff962 100644
--- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java
+++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java
@@ -25,8 +25,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.InternalApiBridge;
import net.sourceforge.pmd.ant.PMDTask;
@@ -38,6 +36,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;
@@ -71,7 +71,6 @@ public class PMDTaskImpl {
configuration.setRuleSets(Arrays.asList(task.getRulesetFiles().split(",")));
}
- configuration.setRuleSetFactoryCompatibilityEnabled(!task.isNoRuleSetCompatibility());
if (task.getEncoding() != null) {
configuration.setSourceEncoding(Charset.forName(task.getEncoding()));
}
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageHandler.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageHandler.java
index e1e10d6f00..92348f5f43 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageHandler.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageHandler.java
@@ -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 {
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java
index acb0bb19c0..f3e8f4c64c 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageModule.java
@@ -5,12 +5,12 @@
package net.sourceforge.pmd.lang.apex;
import net.sourceforge.pmd.cpd.CpdCapableLanguage;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguageModuleBase;
import net.sourceforge.pmd.lang.LanguageProcessor;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.PmdCapableLanguage;
-import net.sourceforge.pmd.lang.apex.cpd.ApexTokenizer;
+import net.sourceforge.pmd.lang.apex.cpd.ApexCpdLexer;
public class ApexLanguageModule extends LanguageModuleBase implements PmdCapableLanguage, CpdCapableLanguage {
private static final String ID = "apex";
@@ -47,7 +47,7 @@ public class ApexLanguageModule extends LanguageModuleBase implements PmdCapable
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new ApexTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new ApexCpdLexer();
}
}
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexViolationSuppressors.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexViolationSuppressors.java
index 2212fa9bb1..caa7f1530e 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexViolationSuppressors.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexViolationSuppressors.java
@@ -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 {
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java
index 51dfcb5129..402010bd48 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java
@@ -23,7 +23,6 @@ public final class ASTAnnotation extends AbstractApexNode {
}
@Override
- @Deprecated
public String getImage() {
return getName();
}
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java
index 9c9a17e1ef..d06310df33 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java
@@ -38,7 +38,6 @@ public final class ASTAnnotationParameter extends AbstractApexNode extends AbstractApexNode implements ASTUserClassOrInterface {
@@ -21,12 +19,7 @@ abstract class BaseApexClass extends AbstractApexNode
return true;
}
- /**
- * @deprecated Use {@link #getSimpleName()}
- */
@Override
- @Deprecated
- @DeprecatedUntil700
public String getImage() {
return getSimpleName();
}
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/cpd/ApexTokenizer.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/cpd/ApexCpdLexer.java
similarity index 93%
rename from pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/cpd/ApexTokenizer.java
rename to pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/cpd/ApexCpdLexer.java
index 22319de686..688dce3d4e 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/cpd/ApexTokenizer.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/cpd/ApexCpdLexer.java
@@ -12,16 +12,16 @@ import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.Lexer;
import org.antlr.runtime.Token;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.cpd.TokenFactory;
-import net.sourceforge.pmd.cpd.Tokenizer;
import net.sourceforge.pmd.lang.apex.ApexJorjeLogging;
import net.sourceforge.pmd.lang.document.TextDocument;
import apex.jorje.parser.impl.ApexLexer;
-public class ApexTokenizer implements Tokenizer {
+public class ApexCpdLexer implements CpdLexer {
- public ApexTokenizer() {
+ public ApexCpdLexer() {
ApexJorjeLogging.disableLogging();
}
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java
index c00f59cff9..bdaa957d8e 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRule.java
@@ -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 {
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/StdCyclomaticComplexityRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/StdCyclomaticComplexityRule.java
index 07e8b42fbe..3c10198c70 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/StdCyclomaticComplexityRule.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/StdCyclomaticComplexityRule.java
@@ -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;
/**
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java
index 2acea93e73..0f4c196295 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java
@@ -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;
diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java
index ae0c2cadf5..a4bb420ef4 100644
--- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java
+++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsRule.java
@@ -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
diff --git a/pmd-apex/src/main/resources/category/apex/bestpractices.xml b/pmd-apex/src/main/resources/category/apex/bestpractices.xml
index 178f94e82e..f2d723cb8c 100644
--- a/pmd-apex/src/main/resources/category/apex/bestpractices.xml
+++ b/pmd-apex/src/main/resources/category/apex/bestpractices.xml
@@ -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">
Apex test methods should have `@isTest` annotation instead of the `testMethod` keyword,
@@ -116,7 +116,6 @@ annotation for test classes and methods.
3
-
The first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum.
diff --git a/pmd-apex/src/main/resources/category/apex/codestyle.xml b/pmd-apex/src/main/resources/category/apex/codestyle.xml
index c2028bfd3c..448d8e9a00 100644
--- a/pmd-apex/src/main/resources/category/apex/codestyle.xml
+++ b/pmd-apex/src/main/resources/category/apex/codestyle.xml
@@ -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">
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">
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">
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">
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">
Avoid using 'while' statements without using braces to surround the code block. If the code
diff --git a/pmd-apex/src/main/resources/category/apex/errorprone.xml b/pmd-apex/src/main/resources/category/apex/errorprone.xml
index 2a4f16618b..4bfe137c50 100644
--- a/pmd-apex/src/main/resources/category/apex/errorprone.xml
+++ b/pmd-apex/src/main/resources/category/apex/errorprone.xml
@@ -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">
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">
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">
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">
Empty block statements serve no purpose and should be removed.
@@ -247,7 +247,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">
Avoid empty try or finally blocks - what's the point?
@@ -291,7 +291,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">
Empty While Statement finds all instances where a while statement does nothing.
@@ -445,7 +445,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">
Test methods marked as a testMethod or annotated with @IsTest,
diff --git a/pmd-apex/src/main/resources/category/apex/performance.xml b/pmd-apex/src/main/resources/category/apex/performance.xml
index 8f4e17523b..874e0b7268 100644
--- a/pmd-apex/src/main/resources/category/apex/performance.xml
+++ b/pmd-apex/src/main/resources/category/apex/performance.xml
@@ -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">
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 `@
3
-
This rule finds `DescribeSObjectResult`s which could have been loaded eagerly via `SObjectType.getDescribe()`.
@@ -172,7 +171,6 @@ Properties:
3
-
-
-
-
- These rules deal with different problems that can occur with Apex unit tests.
-
-
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/braces.xml b/pmd-apex/src/main/resources/rulesets/apex/braces.xml
deleted file mode 100644
index 10a8a93bc6..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/braces.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-The Braces ruleset contains rules regarding the use and placement of braces.
-
-
-
-
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/complexity.xml b/pmd-apex/src/main/resources/rulesets/apex/complexity.xml
deleted file mode 100644
index 594a7bd626..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/complexity.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-The Complexity ruleset contains rules that find problems related to code size or complexity.
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml
deleted file mode 100644
index 73dad3a46e..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-The Empty Code ruleset contains rules that find empty statements of any kind (empty method,
-empty block statement, empty try or catch block,...).
-
-
-
-
-
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/metrics.xml b/pmd-apex/src/main/resources/rulesets/apex/metrics.xml
deleted file mode 100644
index f8ee4a7254..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/metrics.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
- These are rules which use the Metrics Framework to calculate metrics.
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/performance.xml b/pmd-apex/src/main/resources/rulesets/apex/performance.xml
deleted file mode 100644
index 347ca6bcbc..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/performance.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-The Performance ruleset contains a collection of good practices which should be followed.
-
-
-
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml
deleted file mode 100644
index 78c1864f93..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-Default ruleset used by the Code Climate Engine for Salesforce.com Apex
-
-Note: This ruleset is deprecated. Use "rulesets/apex/quickstart.xml" instead.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/rulesets.properties b/pmd-apex/src/main/resources/rulesets/apex/rulesets.properties
deleted file mode 100644
index 7688989c44..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/rulesets.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-#
-# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
-#
-rulesets.filenames=\
- category/apex/bestpractices.xml,\
- category/apex/codestyle.xml,\
- category/apex/design.xml,\
- category/apex/documentation.xml,\
- category/apex/errorprone.xml,\
- category/apex/performance.xml,\
- category/apex/security.xml
diff --git a/pmd-apex/src/main/resources/rulesets/apex/security.xml b/pmd-apex/src/main/resources/rulesets/apex/security.xml
deleted file mode 100644
index 1bb9d9a157..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/security.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-These rules deal with different security problems that can occur within Apex.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-apex/src/main/resources/rulesets/apex/style.xml b/pmd-apex/src/main/resources/rulesets/apex/style.xml
deleted file mode 100644
index 7064578fca..0000000000
--- a/pmd-apex/src/main/resources/rulesets/apex/style.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-The Style Ruleset contains rules regarding preferred usage of names and identifiers.
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/DefaultRulesetTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/QuickstartRulesetTest.java
similarity index 70%
rename from pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/DefaultRulesetTest.java
rename to pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/QuickstartRulesetTest.java
index 3ca9685389..d56fdaecf8 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/DefaultRulesetTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/QuickstartRulesetTest.java
@@ -9,21 +9,15 @@ 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;
-class DefaultRulesetTest {
+class QuickstartRulesetTest {
private static final String QUICKSTART_RULESET = "rulesets/apex/quickstart.xml";
- @Test
- void loadDefaultRuleset() {
- RuleSet ruleset = rulesetLoader().loadFromResource("rulesets/apex/ruleset.xml");
- assertNotNull(ruleset);
- }
-
@Test
void loadQuickstartRuleset() throws Exception {
String log = SystemLambda.tapSystemErr(() -> {
@@ -39,6 +33,6 @@ class DefaultRulesetTest {
}
private RuleSetLoader rulesetLoader() {
- return new RuleSetLoader().enableCompatibility(false);
+ return new RuleSetLoader();
}
}
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/RuleSetFactoryTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/RuleSetFactoryTest.java
index fb955369af..c3dd9beaa2 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/RuleSetFactoryTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/RuleSetFactoryTest.java
@@ -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
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/SuppressWarningsTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/SuppressWarningsTest.java
index 9cb2f3500c..c43609aa03 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/SuppressWarningsTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/SuppressWarningsTest.java
@@ -12,11 +12,11 @@ import java.util.List;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.ViolationSuppressor;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.ViolationSuppressor;
class SuppressWarningsTest extends ApexParserTestBase {
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/cpd/ApexTokenizerTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/cpd/ApexCpdLexerTest.java
similarity index 88%
rename from pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/cpd/ApexTokenizerTest.java
rename to pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/cpd/ApexCpdLexerTest.java
index eee012f27f..d1f6a32143 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/cpd/ApexTokenizerTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/cpd/ApexCpdLexerTest.java
@@ -9,9 +9,9 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
-class ApexTokenizerTest extends CpdTextComparisonTest {
+class ApexCpdLexerTest extends CpdTextComparisonTest {
- ApexTokenizerTest() {
+ ApexCpdLexerTest() {
super(ApexLanguageModule.getInstance(), ".cls");
}
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRuleTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRuleTest.java
index 8a247fcbdb..d16f2c69ea 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRuleTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexRuleTest.java
@@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.apex.rule;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.lang.apex.ast.ASTAnonymousClass;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.ast.ASTUserEnum;
@@ -14,6 +13,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface;
import net.sourceforge.pmd.lang.apex.ast.ASTUserTrigger;
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
import net.sourceforge.pmd.lang.ast.test.TestUtilsKt;
+import net.sourceforge.pmd.reporting.Report;
class AbstractApexRuleTest extends ApexParserTestBase {
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/ApexXPathRuleTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/ApexXPathRuleTest.java
index 09346eb0f7..db9f60bf64 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/ApexXPathRuleTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/ApexXPathRuleTest.java
@@ -8,10 +8,10 @@ import static net.sourceforge.pmd.lang.ast.test.TestUtilsKt.assertSize;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
import net.sourceforge.pmd.lang.document.FileId;
-import net.sourceforge.pmd.lang.rule.XPathRule;
+import net.sourceforge.pmd.lang.rule.xpath.XPathRule;
+import net.sourceforge.pmd.reporting.Report;
/**
* @author daniels
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/design/UnusedMethodTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/design/UnusedMethodTest.java
index cda9afc56b..937199a36f 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/design/UnusedMethodTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/design/UnusedMethodTest.java
@@ -15,16 +15,16 @@ import org.junit.jupiter.api.io.TempDir;
import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.PmdAnalysis;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetLoader;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
import net.sourceforge.pmd.lang.apex.ApexLanguageProperties;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
import com.nawforce.pkgforce.path.PathFactory;
import com.nawforce.pkgforce.path.PathLike;
diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsNestedClassTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsNestedClassTest.java
index dd2ae6531b..05c95696c6 100644
--- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsNestedClassTest.java
+++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/security/ApexSharingViolationsNestedClassTest.java
@@ -14,9 +14,9 @@ import java.util.stream.Collectors;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
*
Sharing settings are not inherited by inner classes. Sharing settings need to be declared on the class that
diff --git a/pmd-cli/pom.xml b/pmd-cli/pom.xml
index a217e76abd..fa137647d6 100644
--- a/pmd-cli/pom.xml
+++ b/pmd-cli/pom.xml
@@ -68,11 +68,6 @@
org.checkerframeworkchecker-qual
-
- com.github.tomakehurst
- wiremock-jre8
- test
- org.hamcresthamcrest
diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java
index feceb9e886..02a5804c98 100644
--- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java
+++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java
@@ -20,7 +20,6 @@ import org.slf4j.LoggerFactory;
import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.PmdAnalysis;
-import net.sourceforge.pmd.RulePriority;
import net.sourceforge.pmd.benchmark.TextTimingReportRenderer;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimingReport;
@@ -33,6 +32,7 @@ import net.sourceforge.pmd.cli.internal.ProgressBarListener;
import net.sourceforge.pmd.internal.LogMessages;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageVersion;
+import net.sourceforge.pmd.lang.rule.RulePriority;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.renderers.RendererFactory;
@@ -102,8 +102,6 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand
private String auxClasspath;
- private boolean noRuleSetCompatibility;
-
private Path cacheLocation;
private boolean noCache;
@@ -213,12 +211,6 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand
this.auxClasspath = auxClasspath;
}
- @Option(names = "--no-ruleset-compatibility",
- description = "Disable the ruleset compatibility filter. The filter is active by default and tries automatically 'fix' old ruleset files with old rule names")
- public void setNoRuleSetCompatibility(final boolean noRuleSetCompatibility) {
- this.noRuleSetCompatibility = noRuleSetCompatibility;
- }
-
@Option(names = "--cache",
description = "Specify the location of the cache file for incremental analysis. "
+ "This should be the full path to the file, including the desired file name (not just the parent directory). "
@@ -274,7 +266,6 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand
configuration.addRelativizeRoots(relativizeRootPaths);
}
configuration.setRuleSets(rulesets);
- configuration.setRuleSetFactoryCompatibilityEnabled(!this.noRuleSetCompatibility);
configuration.setShowSuppressedViolations(showSuppressed);
configuration.setSuppressMarker(suppressMarker);
configuration.setThreads(threads);
diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/TreeExportCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/TreeExportCommand.java
index c4ddefebf2..0655739e5d 100644
--- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/TreeExportCommand.java
+++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/TreeExportCommand.java
@@ -32,7 +32,7 @@ import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParameterException;
-@Command(name = "ast-dump", description = "Experimental: dumps the AST of parsing source code")
+@Command(name = "ast-dump", description = "Dumps the AST of parsing source code")
public class TreeExportCommand extends AbstractPmdSubcommand {
static {
diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/RulePriorityTypeSupport.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/RulePriorityTypeSupport.java
index 48ee080be9..67c3e41337 100644
--- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/RulePriorityTypeSupport.java
+++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/typesupport/internal/RulePriorityTypeSupport.java
@@ -8,7 +8,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import net.sourceforge.pmd.RulePriority;
+import net.sourceforge.pmd.lang.rule.RulePriority;
import picocli.CommandLine.ITypeConverter;
import picocli.CommandLine.TypeConversionException;
diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ProgressBarListener.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ProgressBarListener.java
index 84c43acfca..39debca2d5 100644
--- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ProgressBarListener.java
+++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/ProgressBarListener.java
@@ -6,12 +6,12 @@ package net.sourceforge.pmd.cli.internal;
import java.util.concurrent.atomic.AtomicInteger;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.reporting.ListenerInitializer;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
import me.tongfei.progressbar.PmdProgressBarFriend;
import me.tongfei.progressbar.ProgressBar;
diff --git a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java
index be585879ee..b03fe815f9 100644
--- a/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java
+++ b/pmd-cli/src/test/java/net/sourceforge/pmd/cli/PmdCliTest.java
@@ -40,11 +40,11 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.MockRule;
+import net.sourceforge.pmd.reporting.RuleContext;
import com.github.stefanbirkner.systemlambda.SystemLambda;
@@ -209,12 +209,6 @@ class PmdCliTest extends BaseCliTest {
result.checkStdErr(not(containsPattern("Adding file .*"))); // not in debug mode
}
- @Test
- void testDeprecatedRulesetSyntaxOnCommandLine() throws Exception {
- CliExecutionResult result = runCli(VIOLATIONS_FOUND, "--dir", srcDir.toString(), "--rulesets", "dummy-basic");
- result.checkStdErr(containsString("Ruleset reference 'dummy-basic' uses a deprecated form, use 'rulesets/dummy/basic.xml' instead"));
- }
-
@Test
void testReportToStdoutNotClosing() throws Exception {
PrintStream originalOut = System.out;
diff --git a/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml b/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml
index de1fa0063e..8049a8b63b 100644
--- a/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml
+++ b/pmd-cli/src/test/resources/net/sourceforge/pmd/cli/RuleSetWithViolations.xml
@@ -7,7 +7,7 @@
Just for test3
diff --git a/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/CocoLanguageModule.java b/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/CocoLanguageModule.java
index 6f293579f3..711a4a730b 100644
--- a/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/CocoLanguageModule.java
+++ b/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/CocoLanguageModule.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.coco;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
-import net.sourceforge.pmd.lang.coco.cpd.CocoTokenizer;
+import net.sourceforge.pmd.lang.coco.cpd.CocoCpdLexer;
import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase;
/**
@@ -25,7 +25,7 @@ public class CocoLanguageModule extends CpdOnlyLanguageModuleBase {
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new CocoTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new CocoCpdLexer();
}
}
diff --git a/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/cpd/CocoTokenizer.java b/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/cpd/CocoCpdLexer.java
similarity index 80%
rename from pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/cpd/CocoTokenizer.java
rename to pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/cpd/CocoCpdLexer.java
index 2467db44a0..cda9ab4b7f 100644
--- a/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/cpd/CocoTokenizer.java
+++ b/pmd-coco/src/main/java/net/sourceforge/pmd/lang/coco/cpd/CocoCpdLexer.java
@@ -7,13 +7,13 @@ package net.sourceforge.pmd.lang.coco.cpd;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
-import net.sourceforge.pmd.cpd.impl.AntlrTokenizer;
+import net.sourceforge.pmd.cpd.impl.AntlrCpdLexer;
import net.sourceforge.pmd.lang.coco.ast.CocoLexer;
/**
* The Coco Tokenizer.
*/
-public class CocoTokenizer extends AntlrTokenizer {
+public class CocoCpdLexer extends AntlrCpdLexer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
diff --git a/pmd-coco/src/test/java/net/sourceforge/pmd/lang/coco/cpd/CocoTokenizerTest.java b/pmd-coco/src/test/java/net/sourceforge/pmd/lang/coco/cpd/CocoCpdLexerTest.java
similarity index 85%
rename from pmd-coco/src/test/java/net/sourceforge/pmd/lang/coco/cpd/CocoTokenizerTest.java
rename to pmd-coco/src/test/java/net/sourceforge/pmd/lang/coco/cpd/CocoCpdLexerTest.java
index bdb3735151..3ef139cc41 100644
--- a/pmd-coco/src/test/java/net/sourceforge/pmd/lang/coco/cpd/CocoTokenizerTest.java
+++ b/pmd-coco/src/test/java/net/sourceforge/pmd/lang/coco/cpd/CocoCpdLexerTest.java
@@ -9,8 +9,8 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
import net.sourceforge.pmd.lang.coco.CocoLanguageModule;
-class CocoTokenizerTest extends CpdTextComparisonTest {
- CocoTokenizerTest() {
+class CocoCpdLexerTest extends CpdTextComparisonTest {
+ CocoCpdLexerTest() {
super(CocoLanguageModule.getInstance(), ".coco");
}
diff --git a/pmd-compat6/pom.xml b/pmd-compat6/pom.xml
index 9f682a8768..10d2fc34c3 100644
--- a/pmd-compat6/pom.xml
+++ b/pmd-compat6/pom.xml
@@ -43,6 +43,20 @@
+
+ org.jboss.bridger
+ bridger
+ 1.6.Final
+
+
+ weave
+ process-classes
+
+ transform
+
+
+
+ org.apache.maven.pluginsmaven-invoker-plugin
diff --git a/pmd-compat6/src/it/pmd-for-java/exception_ruleset.xml b/pmd-compat6/src/it/pmd-for-java/exception_ruleset.xml
index 7f9604ffa3..bd7427e5a8 100644
--- a/pmd-compat6/src/it/pmd-for-java/exception_ruleset.xml
+++ b/pmd-compat6/src/it/pmd-for-java/exception_ruleset.xml
@@ -2,7 +2,7 @@
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
Use this rule to produce a processing error.3
diff --git a/pmd-compat6/src/it/pmd-for-java/invoker.properties b/pmd-compat6/src/it/pmd-for-java/invoker.properties
index bfaaa1661c..d03166a079 100644
--- a/pmd-compat6/src/it/pmd-for-java/invoker.properties
+++ b/pmd-compat6/src/it/pmd-for-java/invoker.properties
@@ -1,4 +1,4 @@
-invoker.goals.1 = verify
+invoker.goals.1 = verify -e
invoker.goals.2 = pmd:check -Dformat=csv
invoker.goals.3 = pmd:check -Dformat=txt
invoker.buildResult = failure
diff --git a/pmd-compat6/src/it/pmd-for-java/src/main/java/org/example/Main.java b/pmd-compat6/src/it/pmd-for-java/src/main/java/org/example/Main.java
index a1609790b5..8b4ddb6e37 100644
--- a/pmd-compat6/src/it/pmd-for-java/src/main/java/org/example/Main.java
+++ b/pmd-compat6/src/it/pmd-for-java/src/main/java/org/example/Main.java
@@ -4,5 +4,7 @@ public class Main {
public static void main(String[] args) {
String thisIsAUnusedLocalVar = "a";
System.out.println("Hello world!");
+
+ String thisIsASuppressedUnusedLocalVar = "b"; // NOPMD suppressed
}
}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java
index b09a5b9e68..50ef308f17 100644
--- a/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java
@@ -3,7 +3,10 @@
*/
// This class has been taken from 7.0.0-SNAPSHOT
-// Changes: setSourceEncoding
+// Changes:
+// - setSourceEncoding
+// - setBenchmark (non-functional)
+// - getMinimumPriority
package net.sourceforge.pmd;
@@ -30,6 +33,7 @@ import net.sourceforge.pmd.cache.internal.NoopAnalysisCache;
import net.sourceforge.pmd.internal.util.ClasspathClassLoader;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.renderers.RendererFactory;
import net.sourceforge.pmd.util.AssertionUtil;
@@ -585,4 +589,14 @@ public class PMDConfiguration extends AbstractConfiguration {
public void setSourceEncoding(String sourceEncoding) {
setSourceEncoding(Charset.forName(Objects.requireNonNull(sourceEncoding)));
}
+
+ @Deprecated
+ public void setBenchmark(boolean benchmark) {
+ // ignored
+ }
+
+ // new method to be compatible with PMD 7 - RulePriority has changed package
+ public net.sourceforge.pmd.lang.rule.RulePriority getMinimumPriority$$bridge() { // SUPPRESS CHECKSTYLE ignore
+ return minimumPriority.asPMD7RulePriority();
+ }
}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java
new file mode 100644
index 0000000000..de0b41595e
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java
@@ -0,0 +1,625 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// This class has been taken from 7.0.0-SNAPSHOT
+// Changes: performAnalysisAndCollectReport, changes due to Report moved package
+
+package net.sourceforge.pmd;
+
+import static net.sourceforge.pmd.util.CollectionUtil.listOf;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
+
+import net.sourceforge.pmd.benchmark.TimeTracker;
+import net.sourceforge.pmd.benchmark.TimedOperation;
+import net.sourceforge.pmd.benchmark.TimedOperationCategory;
+import net.sourceforge.pmd.cache.internal.AnalysisCacheListener;
+import net.sourceforge.pmd.cache.internal.NoopAnalysisCache;
+import net.sourceforge.pmd.internal.LogMessages;
+import net.sourceforge.pmd.internal.util.ClasspathClassLoader;
+import net.sourceforge.pmd.internal.util.FileCollectionUtil;
+import net.sourceforge.pmd.internal.util.IOUtil;
+import net.sourceforge.pmd.lang.InternalApiBridge;
+import net.sourceforge.pmd.lang.JvmLanguagePropertyBundle;
+import net.sourceforge.pmd.lang.Language;
+import net.sourceforge.pmd.lang.LanguageProcessor.AnalysisTask;
+import net.sourceforge.pmd.lang.LanguageProcessorRegistry;
+import net.sourceforge.pmd.lang.LanguageProcessorRegistry.LanguageTerminationException;
+import net.sourceforge.pmd.lang.LanguagePropertyBundle;
+import net.sourceforge.pmd.lang.LanguageRegistry;
+import net.sourceforge.pmd.lang.LanguageVersion;
+import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
+import net.sourceforge.pmd.lang.document.FileCollector;
+import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
+import net.sourceforge.pmd.renderers.Renderer;
+import net.sourceforge.pmd.reporting.ConfigurableFileNameRenderer;
+import net.sourceforge.pmd.reporting.FileAnalysisListener;
+import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
+import net.sourceforge.pmd.reporting.ListenerInitializer;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.ReportStats;
+import net.sourceforge.pmd.reporting.ReportStatsListener;
+import net.sourceforge.pmd.util.AssertionUtil;
+import net.sourceforge.pmd.util.StringUtil;
+import net.sourceforge.pmd.util.log.PmdReporter;
+
+/**
+ * Main programmatic API of PMD. This is not a CLI entry point, see module
+ * {@code pmd-cli} for that.
+ *
+ *
Usage overview
+ *
+ *
Create and configure a {@link PMDConfiguration},
+ * then use {@link #create(PMDConfiguration)} to obtain an instance.
+ * You can perform additional configuration on the instance, e.g. adding
+ * files to process, or additional rulesets and renderers. Then, call
+ * {@link #performAnalysis()} or one of the related terminal methods.
+ *
+ *
If you just want to render a report to a file like with the CLI, you
+ * should use a {@link Renderer}. You can add a custom one with {@link PmdAnalysis#addRenderer(Renderer)}.
+ * You can add one of the builtin renderers from its ID using {@link PMDConfiguration#setReportFormat(String)}.
+ *
+ *
Reports and events
+ *
+ *
If you want strongly typed access to violations and other analysis events,
+ * you can implement and register a {@link GlobalAnalysisListener} with {@link #addListener(GlobalAnalysisListener)}.
+ * The listener needs to provide a new {@link FileAnalysisListener} for each file,
+ * which will receive events from the analysis. The listener's lifecycle
+ * happens only once the analysis is started ({@link #performAnalysis()}).
+ *
+ *
If you want access to all events once the analysis ends instead of processing
+ * events as they go, you can obtain a {@link Report} instance from {@link #performAnalysisAndCollectReport()},
+ * or use {@link Report.GlobalReportBuilderListener} manually. Keep in
+ * mind collecting a report is less memory-efficient than using a listener.
+ *
+ *
If you want to process events in batches, one per file, you can
+ * use {@link Report.ReportBuilderListener}. to implement {@link GlobalAnalysisListener#startFileAnalysis(TextFile)}.
+ *
+ *
Listeners can be used alongside renderers.
+ *
+ *
Specifying the Java classpath
+ *
+ *
Java rules work better if you specify the path to the compiled classes
+ * of the analysed sources. See {@link PMDConfiguration#prependAuxClasspath(String)}.
+ *
+ *
Customizing message output
+ *
+ *
The analysis reports messages like meta warnings and errors through a
+ * {@link PmdReporter} instance. To override how those messages are output,
+ * you can set it in {@link PMDConfiguration#setReporter(PmdReporter)}.
+ * By default, it forwards messages to SLF4J.
+ *
+ */
+public final class PmdAnalysis implements AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PmdAnalysis.class);
+
+ private final FileCollector collector;
+ private final List renderers = new ArrayList<>();
+ private final List listeners = new ArrayList<>();
+ private final List ruleSets = new ArrayList<>();
+ private final PMDConfiguration configuration;
+ private final PmdReporter reporter;
+
+ private final Map langProperties = new HashMap<>();
+ private boolean closed;
+ private final ConfigurableFileNameRenderer fileNameRenderer = new ConfigurableFileNameRenderer();
+
+ /**
+ * Constructs a new instance. The files paths (input files, filelist,
+ * exclude list, etc) given in the configuration are collected into
+ * the file collector ({@link #files()}), but more can be added
+ * programmatically using the file collector.
+ */
+ private PmdAnalysis(PMDConfiguration config) {
+ this.configuration = config;
+ this.reporter = config.getReporter();
+ this.collector = FileCollector.newCollector(
+ config.getLanguageVersionDiscoverer(),
+ reporter
+ );
+
+ }
+
+ /**
+ * Constructs a new instance from a configuration.
+ *
+ *
+ *
The files paths (input files, filelist,
+ * exclude list, etc) are explored and the files to analyse are
+ * collected into the file collector ({@link #files()}).
+ * More can be added programmatically using the file collector.
+ *
The rulesets given in the configuration are loaded ({@link PMDConfiguration#getRuleSets()})
+ *
A renderer corresponding to the parameters of the configuration
+ * is created and added (but not started).
+ *
+ */
+ public static PmdAnalysis create(PMDConfiguration config) {
+ PmdAnalysis pmd = new PmdAnalysis(config);
+
+ // note: do not filter files by language
+ // they could be ignored later. The problem is if you call
+ // addRuleSet later, then you could be enabling new languages
+ // So the files should not be pruned in advance
+ FileCollectionUtil.collectFiles(config, pmd.files());
+
+ if (config.getReportFormat() != null) {
+ Renderer renderer = config.createRenderer(true);
+ pmd.addRenderer(renderer);
+ }
+
+ if (!config.getRuleSetPaths().isEmpty()) {
+ final net.sourceforge.pmd.lang.rule.RuleSetLoader ruleSetLoader = pmd.newRuleSetLoader();
+ final List ruleSets = ruleSetLoader.loadRuleSetsWithoutException(config.getRuleSetPaths());
+ pmd.addRuleSets(ruleSets);
+ }
+
+ for (Language language : config.getLanguageRegistry()) {
+ LanguagePropertyBundle props = config.getLanguageProperties(language);
+ assert props.getLanguage().equals(language);
+ pmd.langProperties.put(language, props);
+
+ LanguageVersion forcedVersion = config.getForceLanguageVersion();
+ if (forcedVersion != null && forcedVersion.getLanguage().equals(language)) {
+ props.setLanguageVersion(forcedVersion.getVersion());
+ }
+
+ // TODO replace those with actual language properties when the
+ // CLI syntax is implemented.
+ props.setProperty(LanguagePropertyBundle.SUPPRESS_MARKER, config.getSuppressMarker());
+ if (props instanceof JvmLanguagePropertyBundle) {
+ ((JvmLanguagePropertyBundle) props).setClassLoader(config.getClassLoader());
+ }
+ }
+
+ for (Path path : config.getRelativizeRoots()) {
+ pmd.fileNameRenderer.relativizeWith(path);
+ }
+
+ return pmd;
+ }
+
+ // test only
+ List rulesets() {
+ return ruleSets;
+ }
+
+ // test only
+ List renderers() {
+ return renderers;
+ }
+
+
+ /**
+ * Returns the file collector for the analysed sources.
+ */
+ public FileCollector files() {
+ return collector; // todo user can close collector programmatically
+ }
+
+ /**
+ * Returns a new ruleset loader, which can be used to create new
+ * rulesets (add them then with {@link #addRuleSet(RuleSet)}).
+ *
+ *
+ */
+ public net.sourceforge.pmd.lang.rule.RuleSetLoader newRuleSetLoader() {
+ return RuleSetLoader.fromPmdConfig(configuration);
+ }
+
+ /**
+ * Add a new renderer. The given renderer must not already be started,
+ * it will be started by {@link #performAnalysis()}.
+ *
+ * @throws NullPointerException If the parameter is null
+ */
+ public void addRenderer(Renderer renderer) {
+ AssertionUtil.requireParamNotNull("renderer", renderer);
+ this.renderers.add(renderer);
+ }
+
+ /**
+ * Add several renderers at once.
+ *
+ * @throws NullPointerException If the parameter is null, or any of its items is null.
+ */
+ public void addRenderers(Collection renderers) {
+ renderers.forEach(this::addRenderer);
+ }
+
+ /**
+ * Add a new listener. As per the contract of {@link GlobalAnalysisListener},
+ * this object must be ready for interaction. However, nothing will
+ * be done with the listener until {@link #performAnalysis()} is called.
+ * The listener will be closed by {@link #performAnalysis()}, or
+ * {@link #close()}, whichever happens first.
+ *
+ * @throws NullPointerException If the parameter is null
+ */
+ public void addListener(GlobalAnalysisListener listener) {
+ AssertionUtil.requireParamNotNull("listener", listener);
+ this.listeners.add(listener);
+ }
+
+ /**
+ * Add several listeners at once.
+ *
+ * @throws NullPointerException If the parameter is null, or any of its items is null.
+ * @see #addListener(GlobalAnalysisListener)
+ */
+ public void addListeners(Collection extends GlobalAnalysisListener> listeners) {
+ listeners.forEach(this::addListener);
+ }
+
+ /**
+ * Add a new ruleset.
+ *
+ * @throws NullPointerException If the parameter is null
+ */
+ public void addRuleSet(RuleSet ruleSet) {
+ AssertionUtil.requireParamNotNull("rule set", ruleSet);
+ this.ruleSets.add(ruleSet);
+ }
+
+ /**
+ * Add several rulesets at once.
+ *
+ * @throws NullPointerException If the parameter is null, or any of its items is null.
+ */
+ public void addRuleSets(Collection ruleSets) {
+ ruleSets.forEach(this::addRuleSet);
+ }
+
+ /**
+ * Returns an unmodifiable view of the ruleset list. That will be
+ * processed.
+ */
+ public List getRulesets() {
+ return Collections.unmodifiableList(ruleSets);
+ }
+
+
+ /**
+ * Returns a mutable bundle of language properties that are associated
+ * to the given language (always the same for a given language).
+ *
+ * @param language A language, which must be registered
+ */
+ public LanguagePropertyBundle getLanguageProperties(Language language) {
+ configuration.checkLanguageIsRegistered(language);
+ return langProperties.computeIfAbsent(language, Language::newPropertyBundle);
+ }
+
+
+ public ConfigurableFileNameRenderer fileNameRenderer() {
+ return fileNameRenderer;
+ }
+
+ /**
+ * Run PMD with the current state of this instance. This will start
+ * and finish the registered renderers, and close all
+ * {@linkplain #addListener(GlobalAnalysisListener) registered listeners}.
+ * All files collected in the {@linkplain #files() file collector} are
+ * processed. This does not return a report, as the analysis results
+ * are consumed by {@link GlobalAnalysisListener} instances (of which
+ * Renderers are a special case). Note that this does
+ * not throw, errors are instead accumulated into a {@link PmdReporter}.
+ */
+ public void performAnalysis() {
+ performAnalysisImpl(Collections.emptyList());
+ }
+
+ /**
+ * Run PMD with the current state of this instance. This will start
+ * and finish the registered renderers. All files collected in the
+ * {@linkplain #files() file collector} are processed. Returns the
+ * output report. Note that this does not throw, errors are instead
+ * accumulated into a {@link PmdReporter}.
+ */
+ public Report performAnalysisAndCollectReport() {
+ try (Report.GlobalReportBuilderListener reportBuilder = new Report.GlobalReportBuilderListener()) {
+ performAnalysisImpl(listOf(reportBuilder)); // closes the report builder
+ return reportBuilder.getResultImpl();
+ }
+ }
+
+ void performAnalysisImpl(List extends Report.GlobalReportBuilderListener> extraListeners) {
+ try (FileCollector files = collector) {
+ files.filterLanguages(getApplicableLanguages(false));
+ performAnalysisImpl(extraListeners, files.getCollectedFiles());
+ }
+ }
+
+ void performAnalysisImpl(List extends Report.GlobalReportBuilderListener> extraListeners, List textFiles) {
+ net.sourceforge.pmd.lang.rule.internal.RuleSets rulesets = new net.sourceforge.pmd.lang.rule.internal.RuleSets(this.ruleSets);
+
+ GlobalAnalysisListener listener;
+ try {
+ @SuppressWarnings("PMD.CloseResource")
+ AnalysisCacheListener cacheListener = new AnalysisCacheListener(configuration.getAnalysisCache(),
+ rulesets,
+ configuration.getClassLoader(),
+ textFiles);
+ listener = GlobalAnalysisListener.tee(listOf(createComposedRendererListener(renderers),
+ GlobalAnalysisListener.tee(listeners),
+ GlobalAnalysisListener.tee(extraListeners),
+ cacheListener));
+
+ // Initialize listeners
+ try (ListenerInitializer initializer = listener.initializer()) {
+ initializer.setNumberOfFilesToAnalyze(textFiles.size());
+ initializer.setFileNameRenderer(fileNameRenderer());
+ }
+ } catch (Exception e) {
+ reporter.errorEx("Exception while initializing analysis listeners", e);
+ throw new RuntimeException("Exception while initializing analysis listeners", e);
+ }
+
+ try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.FILE_PROCESSING)) {
+ for (final Rule rule : removeBrokenRules(rulesets)) {
+ // todo Just like we throw for invalid properties, "broken rules"
+ // shouldn't be a "config error". This is the only instance of
+ // config errors...
+ // see https://github.com/pmd/pmd/issues/3901
+ listener.onConfigError(new Report.ConfigurationError(rule, rule.dysfunctionReason()));
+ }
+
+ encourageToUseIncrementalAnalysis(configuration);
+
+ try (LanguageProcessorRegistry lpRegistry = LanguageProcessorRegistry.create(
+ // only start the applicable languages (and dependencies)
+ new LanguageRegistry(getApplicableLanguages(true)),
+ langProperties,
+ reporter
+ )) {
+ // Note the analysis task is shared: all processors see
+ // the same file list, which may contain files for other
+ // languages.
+ AnalysisTask analysisTask = InternalApiBridge.createAnalysisTask(
+ rulesets,
+ textFiles,
+ listener,
+ configuration.getThreads(),
+ configuration.getAnalysisCache(),
+ reporter,
+ lpRegistry
+ );
+
+ List analyses = new ArrayList<>();
+ try {
+ for (Language lang : lpRegistry.getLanguages()) {
+ analyses.add(lpRegistry.getProcessor(lang).launchAnalysis(analysisTask));
+ }
+ } finally {
+ Exception e = IOUtil.closeAll(analyses);
+ if (e != null) {
+ reporter.errorEx("Error while joining analysis", e);
+ }
+ }
+
+ } catch (LanguageTerminationException e) {
+ reporter.errorEx("Error while closing language processors", e);
+ }
+ } finally {
+ try {
+ listener.close();
+ } catch (Exception e) {
+ reporter.errorEx("Exception while closing analysis listeners", e);
+ // todo better exception
+ throw new RuntimeException("Exception while closing analysis listeners", e);
+ }
+ }
+ }
+
+
+ private GlobalAnalysisListener createComposedRendererListener(List renderers) throws Exception {
+ if (renderers.isEmpty()) {
+ return GlobalAnalysisListener.noop();
+ }
+
+ List rendererListeners = new ArrayList<>(renderers.size());
+ for (Renderer renderer : renderers) {
+ try {
+ @SuppressWarnings("PMD.CloseResource")
+ GlobalAnalysisListener listener =
+ Objects.requireNonNull(renderer.newListener(), "Renderer should provide non-null listener");
+ rendererListeners.add(listener);
+ } catch (Exception ioe) {
+ // close listeners so far, throw their close exception or the ioe
+ IOUtil.ensureClosed(rendererListeners, ioe);
+ throw AssertionUtil.shouldNotReachHere("ensureClosed should have thrown");
+ }
+ }
+ return GlobalAnalysisListener.tee(rendererListeners);
+ }
+
+ private Set getApplicableLanguages(boolean quiet) {
+ Set languages = new HashSet<>();
+ LanguageVersionDiscoverer discoverer = configuration.getLanguageVersionDiscoverer();
+
+ for (RuleSet ruleSet : ruleSets) {
+ for (Rule rule : ruleSet.getRules()) {
+ Language ruleLanguage = rule.getLanguage();
+ Objects.requireNonNull(ruleLanguage, "Rule has no language " + rule);
+ if (!languages.contains(ruleLanguage)) {
+ LanguageVersion version = discoverer.getDefaultLanguageVersion(ruleLanguage);
+ if (RuleSet.applies((net.sourceforge.pmd.lang.rule.Rule) rule, version)) {
+ configuration.checkLanguageIsRegistered(ruleLanguage);
+ languages.add(ruleLanguage);
+ if (!quiet) {
+ LOG.trace("Using {} version ''{}''", version.getLanguage().getName(), version.getTerseName());
+ }
+ }
+ }
+ }
+ }
+
+ // collect all dependencies, they shouldn't be filtered out
+ LanguageRegistry reg = configuration.getLanguageRegistry();
+ boolean changed;
+ do {
+ changed = false;
+ for (Language lang : new HashSet<>(languages)) {
+ for (String depId : lang.getDependencies()) {
+ Language depLang = reg.getLanguageById(depId);
+ if (depLang == null) {
+ // todo maybe report all then throw
+ throw new IllegalStateException(
+ "Language " + lang.getId() + " has unsatisfied dependencies: "
+ + depId + " is not found in " + reg
+ );
+ }
+ changed |= languages.add(depLang);
+ }
+ }
+ } while (changed);
+ return languages;
+ }
+
+ /**
+ * Remove and return the misconfigured rules from the rulesets and log them
+ * for good measure.
+ */
+ private Set removeBrokenRules(final RuleSets ruleSets) {
+ final Set brokenRules = new HashSet<>();
+ ruleSets.removeDysfunctionalRules(brokenRules);
+
+ for (final Rule rule : brokenRules) {
+ reporter.warn("Removed misconfigured rule: {0} cause: {1}",
+ rule.getName(), rule.dysfunctionReason());
+ }
+
+ return brokenRules;
+ }
+
+
+ public PmdReporter getReporter() {
+ return reporter;
+ }
+
+ @Override
+ public void close() {
+ if (closed) {
+ return;
+ }
+ closed = true;
+ collector.close();
+
+ // close listeners if analysis is not run.
+ IOUtil.closeAll(listeners);
+
+ /*
+ * Make sure it's our own classloader before attempting to close it....
+ * Maven + Jacoco provide us with a cloaseable classloader that if closed
+ * will throw a ClassNotFoundException.
+ */
+ if (configuration.getClassLoader() instanceof ClasspathClassLoader) {
+ IOUtil.tryCloseClassLoader(configuration.getClassLoader());
+ }
+ }
+
+ public ReportStats runAndReturnStats() {
+ if (getRulesets().isEmpty()) {
+ return ReportStats.empty();
+ }
+
+ @SuppressWarnings("PMD.CloseResource")
+ ReportStatsListener listener = new ReportStatsListener();
+
+ addListener(listener);
+
+ try {
+ performAnalysis();
+ } catch (Exception e) {
+ getReporter().errorEx("Exception during processing", e);
+ ReportStats stats = listener.getResult();
+ printErrorDetected(1 + stats.getNumErrors());
+ return stats; // should have been closed
+ }
+ ReportStats stats = listener.getResult();
+
+ if (stats.getNumErrors() > 0) {
+ printErrorDetected(stats.getNumErrors());
+ }
+
+ return stats;
+ }
+
+ static void printErrorDetected(PmdReporter reporter, int errors) {
+ String msg = LogMessages.errorDetectedMessage(errors, "PMD");
+ // note: using error level here increments the error count of the reporter,
+ // which we don't want.
+ reporter.info(StringUtil.quoteMessageFormat(msg));
+ }
+
+ void printErrorDetected(int errors) {
+ printErrorDetected(getReporter(), errors);
+ }
+
+ private static void encourageToUseIncrementalAnalysis(final PMDConfiguration configuration) {
+ final PmdReporter reporter = configuration.getReporter();
+
+ if (!configuration.isIgnoreIncrementalAnalysis()
+ && configuration.getAnalysisCache() instanceof NoopAnalysisCache
+ && reporter.isLoggable(Level.WARN)) {
+ final String version =
+ PMDVersion.isUnknown() || PMDVersion.isSnapshot() ? "latest" : "pmd-doc-" + PMDVersion.VERSION;
+ reporter.warn("This analysis could be faster, please consider using Incremental Analysis: "
+ + "https://docs.pmd-code.org/{0}/pmd_userdocs_incremental_analysis.html", version);
+ }
+ }
+
+ // ---- compatibility
+
+ // new method to be compatible with PMD 6 - Report has changed package
+ public net.sourceforge.pmd.Report performAnalysisAndCollectReport$$bridge() { // SUPPRESS CHECKSTYLE ignore
+ return performAnalysisAndCollectReport();
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/Report.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/Report.java
index 35b312b7b5..a5eff60bf1 100644
--- a/pmd-compat6/src/main/java/net/sourceforge/pmd/Report.java
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/Report.java
@@ -26,10 +26,11 @@ import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
+import net.sourceforge.pmd.reporting.ViolationSuppressor;
import net.sourceforge.pmd.util.BaseResultProducingCloseable;
/**
- * A {@link Report} collects all informations during a PMD execution. This
+ * A {@link Report} collects all information during a PMD execution. This
* includes violations, suppressed violations, metrics, error during processing
* and configuration errors.
*
@@ -46,7 +47,7 @@ import net.sourceforge.pmd.util.BaseResultProducingCloseable;
* These methods create a new {@link Report} rather than modifying their receiver.
*
*/
-public final class Report {
+public class Report {
// todo move to package reporting
private final List violations = synchronizedList(new ArrayList<>());
@@ -312,7 +313,7 @@ public final class Report {
* A {@link FileAnalysisListener} that accumulates events into a
* {@link Report}.
*/
- public static final class ReportBuilderListener extends BaseResultProducingCloseable implements FileAnalysisListener {
+ public static /*final*/ class ReportBuilderListener extends BaseResultProducingCloseable implements FileAnalysisListener {
private final Report report;
@@ -330,17 +331,17 @@ public final class Report {
}
@Override
- public void onRuleViolation(RuleViolation violation) {
+ public void onRuleViolation(net.sourceforge.pmd.reporting.RuleViolation violation) {
report.addRuleViolation(violation);
}
@Override
- public void onSuppressedRuleViolation(SuppressedViolation violation) {
+ public void onSuppressedRuleViolation(net.sourceforge.pmd.reporting.Report.SuppressedViolation violation) {
report.addSuppressedViolation(violation);
}
@Override
- public void onError(ProcessingError error) {
+ public void onError(net.sourceforge.pmd.reporting.Report.ProcessingError error) {
report.addError(error);
}
@@ -354,9 +355,9 @@ public final class Report {
* A {@link GlobalAnalysisListener} that accumulates the events of
* all files into a {@link Report}.
*/
- public static final class GlobalReportBuilderListener extends BaseResultProducingCloseable implements GlobalAnalysisListener {
+ public static /*final*/ class GlobalReportBuilderListener extends BaseResultProducingCloseable implements GlobalAnalysisListener {
- private final Report report = new Report();
+ private final net.sourceforge.pmd.reporting.Report report = new net.sourceforge.pmd.reporting.Report();
@Override
public FileAnalysisListener startFileAnalysis(TextFile file) {
@@ -365,12 +366,12 @@ public final class Report {
}
@Override
- public void onConfigError(ConfigurationError error) {
+ public void onConfigError(net.sourceforge.pmd.reporting.Report.ConfigurationError error) {
report.addConfigError(error);
}
@Override
- protected Report getResultImpl() {
+ protected net.sourceforge.pmd.reporting.Report getResultImpl() {
return report;
}
}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/Rule.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/Rule.java
new file mode 100644
index 0000000000..29116c858f
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/Rule.java
@@ -0,0 +1,321 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// Old version of this class. In PMD 7, this has been moved into sub-package "rule".
+// Changes:
+// - deepCopy
+
+package net.sourceforge.pmd;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.regex.Pattern;
+
+import net.sourceforge.pmd.lang.Language;
+import net.sourceforge.pmd.lang.LanguageProcessor;
+import net.sourceforge.pmd.lang.LanguageVersion;
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.rule.RulePriority;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
+import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.properties.PropertySource;
+import net.sourceforge.pmd.reporting.RuleContext;
+
+/**
+ * This is the basic Rule interface for PMD rules.
+ *
+ *
+ * Thread safety: PMD will create one instance of a rule per
+ * thread. The instances are not shared across different threads. However, a
+ * single rule instance is reused for analyzing multiple files.
+ *
+ */
+public interface Rule extends PropertySource {
+
+ // TODO these should not be properties
+
+ /**
+ * The property descriptor to universally suppress violations with messages
+ * matching a regular expression.
+ */
+ PropertyDescriptor> VIOLATION_SUPPRESS_REGEX_DESCRIPTOR =
+ PropertyFactory.regexProperty("violationSuppressRegex")
+ .desc("Suppress violations with messages matching a regular expression")
+ .toOptional("")
+ .defaultValue(Optional.empty())
+ .build();
+
+ /**
+ * Name of the property to universally suppress violations on nodes which
+ * match a given relative XPath expression.
+ */
+ PropertyDescriptor> VIOLATION_SUPPRESS_XPATH_DESCRIPTOR =
+ PropertyFactory.stringProperty("violationSuppressXPath")
+ .desc("Suppress violations on nodes which match a given relative XPath expression.")
+ .toOptional("")
+ .defaultValue(Optional.empty())
+ .build();
+
+ /**
+ * Get the Language of this Rule.
+ *
+ * @return the language
+ */
+ Language getLanguage();
+
+ /**
+ * Set the Language of this Rule.
+ *
+ * @param language
+ * the language
+ */
+ void setLanguage(Language language);
+
+ /**
+ * Get the minimum LanguageVersion to which this Rule applies. If this value
+ * is null it indicates there is no minimum bound.
+ *
+ * @return the minimum language version
+ */
+ LanguageVersion getMinimumLanguageVersion();
+
+ /**
+ * Set the minimum LanguageVersion to which this Rule applies.
+ *
+ * @param minimumLanguageVersion
+ * the minimum language version
+ */
+ void setMinimumLanguageVersion(LanguageVersion minimumLanguageVersion);
+
+ /**
+ * Get the maximum LanguageVersion to which this Rule applies. If this value
+ * is null it indicates there is no maximum bound.
+ *
+ * @return the maximum language version
+ */
+ LanguageVersion getMaximumLanguageVersion();
+
+ /**
+ * Set the maximum LanguageVersion to which this Rule applies.
+ *
+ * @param maximumLanguageVersion
+ * the maximum language version
+ */
+ void setMaximumLanguageVersion(LanguageVersion maximumLanguageVersion);
+
+ /**
+ * Gets whether this Rule is deprecated. A deprecated Rule is one which:
+ *
+ *
is scheduled for removal in a future version of PMD
+ *
or, has been removed and replaced with a non-functioning place-holder
+ * and will be completely removed in a future version of PMD
+ *
or, has been renamed/moved and the old name will be completely
+ * removed in a future version of PMD
+ *
+ *
+ * @return true if this rule is deprecated
+ */
+ boolean isDeprecated();
+
+ /**
+ * Sets whether this Rule is deprecated.
+ *
+ * @param deprecated
+ * whether this rule is deprecated
+ */
+ void setDeprecated(boolean deprecated);
+
+ /**
+ * Get the name of this Rule.
+ *
+ * @return the name
+ */
+ @Override
+ String getName();
+
+ /**
+ * Set the name of this Rule.
+ *
+ * @param name
+ * the name
+ */
+ void setName(String name);
+
+ /**
+ * Get the version of PMD in which this Rule was added. Return
+ * null if not applicable.
+ *
+ * @return version of PMD since when this rule was added
+ */
+ String getSince();
+
+ /**
+ * Set the version of PMD in which this Rule was added.
+ *
+ * @param since
+ * the version of PMD since when this rule was added
+ */
+ void setSince(String since);
+
+ /**
+ * Get the implementation class of this Rule.
+ *
+ * @return the implementation class name of this rule.
+ */
+ String getRuleClass();
+
+ /**
+ * Set the class of this Rule.
+ *
+ * @param ruleClass
+ * the class name of this rule.
+ */
+ void setRuleClass(String ruleClass);
+
+ /**
+ * Get the name of the RuleSet containing this Rule.
+ *
+ * @return the name of th ruleset containing this rule.
+ * @see RuleSet
+ */
+ String getRuleSetName();
+
+ /**
+ * Set the name of the RuleSet containing this Rule.
+ *
+ * @param name
+ * the name of the ruleset containing this rule.
+ * @see RuleSet
+ */
+ void setRuleSetName(String name);
+
+ /**
+ * Get the message to show when this Rule identifies a violation.
+ *
+ * @return the message to show for a violation.
+ */
+ String getMessage();
+
+ /**
+ * Set the message to show when this Rule identifies a violation.
+ *
+ * @param message
+ * the message to show for a violation.
+ */
+ void setMessage(String message);
+
+ /**
+ * Get the description of this Rule.
+ *
+ * @return the description
+ */
+ String getDescription();
+
+ /**
+ * Set the description of this Rule.
+ *
+ * @param description
+ * the description
+ */
+ void setDescription(String description);
+
+ /**
+ * Get the list of examples for this Rule.
+ *
+ * @return the list of examples for this rule.
+ */
+ List getExamples();
+
+ /**
+ * Add a single example for this Rule.
+ *
+ * @param example
+ * a single example to add
+ */
+ void addExample(String example);
+
+ /**
+ * Get a URL for external information about this Rule.
+ *
+ * @return the URL for external information about this rule.
+ */
+ String getExternalInfoUrl();
+
+ /**
+ * Set a URL for external information about this Rule.
+ *
+ * @param externalInfoUrl
+ * the URL for external information about this rule.
+ */
+ void setExternalInfoUrl(String externalInfoUrl);
+
+ /**
+ * Get the priority of this Rule.
+ *
+ * @return the priority
+ */
+ RulePriority getPriority();
+
+ /**
+ * Set the priority of this Rule.
+ *
+ * @param priority
+ * the priority
+ */
+ void setPriority(RulePriority priority);
+
+
+ /**
+ * Returns the object that selects the nodes to which this rule applies.
+ * The selected nodes will be handed to {@link #apply(Node, RuleContext)}.
+ */
+ RuleTargetSelector getTargetSelector();
+
+ /**
+ * Initialize the rule using the language processor if needed.
+ *
+ * @param languageProcessor The processor for the rule's language
+ */
+ default void initialize(LanguageProcessor languageProcessor) {
+ // by default do nothing
+ }
+
+ /**
+ * Start processing. Called once per file, before apply() is first called.
+ *
+ * @param ctx the rule context
+ */
+ void start(RuleContext ctx);
+
+
+ /**
+ * Process the given node. The nodes that are fed to this method
+ * are the nodes selected by {@link #getTargetSelector()}.
+ *
+ * @param target Node on which to apply the rule
+ * @param ctx Rule context, handling violations
+ */
+ void apply(Node target, RuleContext ctx);
+
+ /**
+ * End processing. Called once per file, after apply() is last called.
+ *
+ * @param ctx
+ * the rule context
+ */
+ void end(RuleContext ctx);
+
+ /**
+ * Creates a new copy of this rule.
+ * @return A new exact copy of this rule
+ */
+ net.sourceforge.pmd.lang.rule.Rule deepCopy();
+
+ // new method to be compatible with PMD 6 - Rule has changed package
+ default Rule deepCopy$$bridge() { // SUPPRESS CHECKSTYLE ignore
+ return deepCopy();
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/RulePriority.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RulePriority.java
new file mode 100644
index 0000000000..c624f1200e
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RulePriority.java
@@ -0,0 +1,138 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// Copy of net.sourceforge.pmd.lang.rule.RulePriority
+// Added method:
+// - asPMD7RulePriority
+
+package net.sourceforge.pmd;
+
+/**
+ * These are the possible Rule priority values.
+ *
+ * For backward compatibility, priorities range in value from 1 to 5, with 5
+ * being the lowest priority. This means the ordinal value of the Enum should be
+ * avoided in favor of {@link RulePriority#getPriority()} and
+ * {@link RulePriority#valueOf(int)}
+ *
+ * @see How
+ * to define rules priority
+ */
+public enum RulePriority {
+
+ /** High: Change absolutely required. Behavior is critically broken/buggy */
+ HIGH(1, "High"),
+ /**
+ * Medium to high: Change highly recommended. Behavior is quite likely to be
+ * broken/buggy.
+ */
+ MEDIUM_HIGH(2, "Medium High"),
+ /**
+ * Medium: Change recommended. Behavior is confusing, perhaps buggy, and/or
+ * against standards/best practices.
+ */
+ MEDIUM(3, "Medium"),
+ /**
+ * Medium to low: Change optional. Behavior is not likely to be buggy, but
+ * more just flies in the face of standards/style/good taste.
+ */
+ MEDIUM_LOW(4, "Medium Low"),
+ /**
+ * Low: Change highly optional. Nice to have, such as a consistent naming
+ * policy for package/class/fields...
+ */
+ LOW(5, "Low");
+
+ private final int priority;
+ private final String name;
+
+ RulePriority(int priority, String name) {
+ this.priority = priority;
+ this.name = name;
+ }
+
+ /**
+ * Get the priority value as a number. This is the value to be used in the
+ * externalized form of a priority (e.g. in RuleSet XML).
+ *
+ * @return The int value of the priority.
+ */
+ public int getPriority() {
+ return priority;
+ }
+
+ /**
+ * Get the descriptive name of this priority.
+ *
+ * @return The descriptive name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the descriptive name of the priority.
+ *
+ * @return descriptive name of the priority
+ * @see #getName()
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * Get the priority which corresponds to the given number as returned by
+ * {@link RulePriority#getPriority()}. If the number is an invalid value,
+ * then {@link RulePriority#LOW} will be returned.
+ *
+ * @param priority
+ * The numeric priority value.
+ * @return The priority.
+ */
+ public static RulePriority valueOf(int priority) {
+ try {
+ return RulePriority.values()[priority - 1];
+ } catch (ArrayIndexOutOfBoundsException e) {
+ return LOW;
+ }
+ }
+
+ /**
+ * Returns the priority which corresponds to the given number as returned by
+ * {@link RulePriority#getPriority()}. If the number is an invalid value,
+ * then null will be returned.
+ *
+ * @param priority The numeric priority value.
+ */
+ public static RulePriority valueOfNullable(int priority) {
+ try {
+ return RulePriority.values()[priority - 1];
+ } catch (ArrayIndexOutOfBoundsException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the priority which corresponds to the given number as returned by
+ * {@link RulePriority#getPriority()}. If the number is an invalid value,
+ * then null will be returned.
+ *
+ * @param priority The numeric priority value.
+ */
+ public static RulePriority valueOfNullable(String priority) {
+ try {
+ int integer = Integer.parseInt(priority);
+ return RulePriority.values()[integer - 1];
+ } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
+ return null;
+ }
+ }
+
+ // ---- compatibility extensions
+
+ public net.sourceforge.pmd.lang.rule.RulePriority asPMD7RulePriority() {
+ return net.sourceforge.pmd.lang.rule.RulePriority.valueOf(name());
+ }
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java
similarity index 98%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java
rename to pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java
index 610676a92c..2e79697725 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java
@@ -2,6 +2,9 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
+// This class has been taken from 7.0.0-SNAPSHOT
+// Before removing RuleSetFactoryCompatibility (#4314)
+
package net.sourceforge.pmd;
import java.text.MessageFormat;
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetLoadException.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetLoadException.java
new file mode 100644
index 0000000000..4af60a4d22
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetLoadException.java
@@ -0,0 +1,17 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd;
+
+import org.checkerframework.checker.nullness.qual.NonNull;
+
+public class RuleSetLoadException extends net.sourceforge.pmd.lang.rule.RuleSetLoadException {
+ public RuleSetLoadException(RuleSetReferenceId rsetId, @NonNull Throwable cause) {
+ super(rsetId, cause);
+ }
+
+ public RuleSetLoadException(RuleSetReferenceId rsetId, String message) {
+ super(rsetId, message);
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetLoader.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetLoader.java
new file mode 100644
index 0000000000..20e91f3069
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetLoader.java
@@ -0,0 +1,32 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// Copy from PMD 7 with minimized functionality.
+// Only the methods called by maven-pmd-plugin are kept,
+// but they do nothing. That means, that maven-pmd-plugin can't report deprecated
+// rules properly anymore.
+// The ruleset for actual PMD analysis is loaded by PMD itself later on, and not
+// through this class.
+
+package net.sourceforge.pmd;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import net.sourceforge.pmd.lang.rule.RuleSet;
+
+public final class RuleSetLoader {
+ public RuleSetLoader warnDeprecated(boolean warn) {
+ return this;
+ }
+
+ public List loadFromResources(Collection paths) {
+ return Collections.emptyList();
+ }
+
+ public static RuleSetLoader fromPmdConfig(PMDConfiguration configuration) {
+ return new RuleSetLoader();
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java
new file mode 100644
index 0000000000..0cb348899a
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java
@@ -0,0 +1,15 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd;
+
+public class RuleSetReferenceId extends net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId {
+ public RuleSetReferenceId(String id) {
+ super(id);
+ }
+
+ public RuleSetReferenceId(String id, RuleSetReferenceId externalRuleSetReferenceId) {
+ super(id, externalRuleSetReferenceId);
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSets.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSets.java
new file mode 100644
index 0000000000..601dffd5a1
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSets.java
@@ -0,0 +1,221 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// This class has been taken from 7.0.0-SNAPSHOT
+// And it is kept in the old package.
+// The moved class is in net.sourceforge.pmd.lang.rule.internal
+
+package net.sourceforge.pmd;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import net.sourceforge.pmd.benchmark.TimeTracker;
+import net.sourceforge.pmd.benchmark.TimedOperation;
+import net.sourceforge.pmd.benchmark.TimedOperationCategory;
+import net.sourceforge.pmd.lang.LanguageProcessorRegistry;
+import net.sourceforge.pmd.lang.ast.RootNode;
+import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.internal.RuleApplicator;
+import net.sourceforge.pmd.reporting.FileAnalysisListener;
+import net.sourceforge.pmd.util.log.PmdReporter;
+
+/**
+ * Grouping of Rules per Language in a RuleSet.
+ *
+ * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
+ */
+public class RuleSets {
+
+ private final List ruleSets;
+
+ private RuleApplicator ruleApplicator;
+
+ /**
+ * Copy constructor. Deep copies RuleSets.
+ *
+ * @param ruleSets The RuleSets to copy.
+ */
+ public RuleSets(final RuleSets ruleSets) {
+ List rsets = new ArrayList<>();
+ for (final RuleSet rs : ruleSets.ruleSets) {
+ rsets.add(new RuleSet(rs));
+ }
+ this.ruleSets = Collections.unmodifiableList(rsets);
+ }
+
+ public RuleSets(Collection extends RuleSet> ruleSets) {
+ this.ruleSets = Collections.unmodifiableList(new ArrayList<>(ruleSets));
+ }
+
+ /**
+ * Public constructor. Add the given rule set.
+ *
+ * @param ruleSet the RuleSet
+ */
+ public RuleSets(RuleSet ruleSet) {
+ this.ruleSets = Collections.singletonList(ruleSet);
+ }
+
+ public void initializeRules(LanguageProcessorRegistry lpReg, PmdReporter reporter) {
+ // this is abusing the mutability of RuleSet, will go away eventually.
+ for (RuleSet rset : ruleSets) {
+ for (Iterator iterator = rset.getRules().iterator(); iterator.hasNext();) {
+ Rule rule = iterator.next();
+ try {
+ rule.initialize(lpReg.getProcessor(rule.getLanguage()));
+ } catch (Exception e) {
+ reporter.errorEx(
+ "Exception while initializing rule " + rule.getName() + ", the rule will not be run", e);
+ iterator.remove();
+ }
+ }
+ }
+ }
+
+ private RuleApplicator prepareApplicator() {
+ return RuleApplicator.build(ruleSets.stream().flatMap(it -> it.getRules().stream())::iterator);
+ }
+
+ /**
+ * Get all the RuleSets.
+ *
+ * @return RuleSet[]
+ */
+ public RuleSet[] getAllRuleSets() {
+ return ruleSets.toArray(new RuleSet[0]);
+ }
+
+ // internal
+ List getRuleSetsInternal() {
+ return ruleSets;
+ }
+
+ public Iterator getRuleSetsIterator() {
+ return ruleSets.iterator();
+ }
+
+ /**
+ * Return all rules from all rulesets.
+ *
+ * @return Set
+ */
+ public Set getAllRules() {
+ Set result = new HashSet<>();
+ for (RuleSet r : ruleSets) {
+ result.addAll(r.getRules());
+ }
+ return result;
+ }
+
+ /**
+ * Check if a given source file should be checked by rules in this RuleSets.
+ *
+ * @param file
+ * the source file to check
+ * @return true if the file should be checked,
+ * false otherwise
+ */
+ public boolean applies(TextFile file) {
+ for (RuleSet ruleSet : ruleSets) {
+ if (ruleSet.applies(file)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Apply all applicable rules to the compilation units. Applicable means the
+ * language of the rules must match the language of the source (@see
+ * applies).
+ *
+ * @param root the List of compilation units; the type these must have,
+ * depends on the source language
+ * @param listener Listener that will handle events while analysing.
+ */
+ public void apply(RootNode root, FileAnalysisListener listener) {
+ if (ruleApplicator == null) {
+ // initialize here instead of ctor, because some rules properties
+ // are set after creating the ruleset, and jaxen xpath queries
+ // initialize their XPath expressions when calling getRuleChainVisits()... fixme
+ this.ruleApplicator = prepareApplicator();
+ }
+
+ try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.RULE_AST_INDEXATION)) {
+ ruleApplicator.index(root);
+ }
+
+ for (RuleSet ruleSet : ruleSets) {
+ if (ruleSet.applies(root.getTextDocument().getFileId())) {
+ ruleApplicator.apply(ruleSet.getRules(), listener);
+ }
+ }
+ }
+
+ /**
+ * Returns the first Rule found with the given name.
+ *
+ * Note: Since we support multiple languages, rule names are not expected to
+ * be unique within any specific ruleset.
+ *
+ * @param ruleName
+ * the exact name of the rule to find
+ * @return the rule or null if not found
+ */
+ public Rule getRuleByName(String ruleName) {
+ Rule rule = null;
+ for (Iterator i = ruleSets.iterator(); i.hasNext() && rule == null;) {
+ RuleSet ruleSet = i.next();
+ rule = ruleSet.getRuleByName(ruleName);
+ }
+ return rule;
+ }
+
+ /**
+ * Determines the total count of rules that are used in all rule sets.
+ *
+ * @return the count
+ */
+ public int ruleCount() {
+ int count = 0;
+ for (RuleSet r : ruleSets) {
+ count += r.getRules().size();
+ }
+ return count;
+ }
+
+
+ /**
+ * Remove and collect any rules that report problems.
+ *
+ * @param collector
+ */
+ public void removeDysfunctionalRules(Collection collector) {
+ for (RuleSet ruleSet : ruleSets) {
+ ruleSet.removeDysfunctionalRules(collector);
+ }
+ }
+
+ /**
+ * Retrieves a checksum of the rulesets being used. Any change to any rule
+ * of any ruleset should trigger a checksum change.
+ *
+ * @return The checksum for this ruleset collection.
+ */
+ public long getChecksum() {
+ long checksum = 1;
+ for (final RuleSet ruleSet : ruleSets) {
+ checksum = checksum * 31 + ruleSet.getChecksum();
+ }
+ return checksum;
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleViolation.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleViolation.java
index dcb3030052..b1d685bf46 100644
--- a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleViolation.java
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleViolation.java
@@ -3,7 +3,9 @@
*/
// This class has been taken from 7.0.0-SNAPSHOT
-// Changes: getFilename
+// Changes:
+// - getFilename
+// - getRule returns n.s.pmd.rule.Rule or the old n.s.pmd.Rule
package net.sourceforge.pmd;
@@ -68,7 +70,7 @@ public interface RuleViolation {
*
* @return The identifying Rule.
*/
- Rule getRule();
+ net.sourceforge.pmd.lang.rule.Rule getRule();
/**
* Get the description of this violation.
@@ -193,4 +195,9 @@ public interface RuleViolation {
default String getFilename() {
return getLocation().getFileId().getFileName();
}
+
+ // returns the PMD 6 compatible Rule
+ default net.sourceforge.pmd.Rule getRule$$bridge() { // SUPPRESS CHECKSTYLE ignore
+ return getRule();
+ }
}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java
index f75312c469..a63b348db2 100644
--- a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java
@@ -4,5 +4,5 @@
package net.sourceforge.pmd.cpd;
-public class EcmascriptTokenizer extends net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptTokenizer {
+public class EcmascriptTokenizer extends net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptCpdLexer implements Tokenizer {
}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java
index 76b768afd8..2e6f8d112b 100644
--- a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java
@@ -4,5 +4,5 @@
package net.sourceforge.pmd.cpd;
-public class JSPTokenizer extends net.sourceforge.pmd.lang.jsp.cpd.JSPTokenizer {
+public class JSPTokenizer extends net.sourceforge.pmd.lang.jsp.cpd.JspCpdLexer implements Tokenizer {
}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java
index 113663cffa..39f2013699 100644
--- a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java
@@ -9,14 +9,14 @@ import java.util.Properties;
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
import net.sourceforge.pmd.lang.java.internal.JavaLanguageProperties;
-public class JavaTokenizer extends net.sourceforge.pmd.lang.java.cpd.JavaTokenizer {
+public class JavaTokenizer extends net.sourceforge.pmd.lang.java.cpd.JavaCpdLexer implements Tokenizer {
public JavaTokenizer(Properties properties) {
super(convertLanguageProperties(properties));
}
- private static final String IGNORE_LITERALS = "ignore_literals";
- private static final String IGNORE_IDENTIFIERS = "ignore_identifiers";
- private static final String IGNORE_ANNOTATIONS = "ignore_annotations";
+ public static final String IGNORE_LITERALS = "ignore_literals";
+ public static final String IGNORE_IDENTIFIERS = "ignore_identifiers";
+ public static final String IGNORE_ANNOTATIONS = "ignore_annotations";
private static JavaLanguageProperties convertLanguageProperties(Properties properties) {
boolean ignoreAnnotations = Boolean.parseBoolean(properties.getProperty(IGNORE_ANNOTATIONS, "false"));
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/LanguageFactory.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/LanguageFactory.java
new file mode 100644
index 0000000000..09769cd57b
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/LanguageFactory.java
@@ -0,0 +1,22 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// This class is here just to make maven-pmd-plugin compile with
+// pmd 7.0.0 including this compat6 module.
+// It would only be used, if a custom language (other than java, jsp or javascript)
+// would be requested.
+
+package net.sourceforge.pmd.cpd;
+
+import java.util.Properties;
+
+public final class LanguageFactory {
+ private LanguageFactory() {
+ // utility class
+ }
+
+ public static Language createLanguage(String name, Properties properties) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java
new file mode 100644
index 0000000000..ece7fc3618
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java
@@ -0,0 +1,8 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.cpd;
+
+public interface Tokenizer extends CpdLexer {
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/Rule.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/Rule.java
new file mode 100644
index 0000000000..a152534e5f
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/Rule.java
@@ -0,0 +1,11 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// The class net.sourceforge.pmd.Rule has been moved into sub-package rule
+// in 7.0.0-SNAPSHOT. All rules should be interchangeable.
+
+package net.sourceforge.pmd.lang.rule;
+
+public interface Rule extends net.sourceforge.pmd.Rule {
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java
new file mode 100644
index 0000000000..eb11ac7e77
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java
@@ -0,0 +1,8 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule;
+
+public class XPathRule extends net.sourceforge.pmd.lang.rule.xpath.XPathRule {
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java
new file mode 100644
index 0000000000..dbf505107a
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java
@@ -0,0 +1,27 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule.internal;
+
+import java.util.Collection;
+
+import net.sourceforge.pmd.lang.rule.RuleSet;
+
+public class RuleSets extends net.sourceforge.pmd.RuleSets {
+ public RuleSets(net.sourceforge.pmd.RuleSets ruleSets) {
+ super(ruleSets);
+ }
+
+ public RuleSets(net.sourceforge.pmd.lang.rule.internal.RuleSets ruleSets) {
+ super(ruleSets);
+ }
+
+ public RuleSets(Collection extends RuleSet> ruleSets) {
+ super(ruleSets);
+ }
+
+ public RuleSets(RuleSet ruleSet) {
+ super(ruleSet);
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java
new file mode 100644
index 0000000000..7d5778af9c
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java
@@ -0,0 +1,172 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// This class has been taken from 7.0.0-SNAPSHOT
+// Changes: not final anymore to allow a subclass in the old package
+
+package net.sourceforge.pmd.lang.rule.xpath;
+
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ContextedRuntimeException;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.sourceforge.pmd.lang.LanguageProcessor;
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.rule.AbstractRule;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
+import net.sourceforge.pmd.lang.rule.xpath.internal.DeprecatedAttrLogger;
+import net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery;
+import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
+
+
+/**
+ * Rule that tries to match an XPath expression against a DOM view of an AST.
+ */
+public /*final*/ class XPathRule extends AbstractRule {
+
+ private static final Logger LOG = LoggerFactory.getLogger(XPathRule.class);
+
+ /**
+ * @deprecated Use {@link #XPathRule(XPathVersion, String)}
+ */
+ @Deprecated
+ public static final PropertyDescriptor XPATH_DESCRIPTOR =
+ PropertyFactory.stringProperty("xpath")
+ .desc("XPath expression")
+ .defaultValue("")
+ .build();
+
+ /**
+ * This is initialized only once when calling {@link #apply(Node, RuleContext)} or {@link #getTargetSelector()}.
+ */
+ private SaxonXPathRuleQuery xpathRuleQuery;
+
+
+ // this is shared with rules forked by deepCopy, used by the XPathRuleQuery
+ private DeprecatedAttrLogger attrLogger = DeprecatedAttrLogger.create(this);
+
+
+ /**
+ * @deprecated This is now only used by the ruleset loader. When
+ * we have syntactic sugar for XPath rules in the XML, we won't
+ * need this anymore.
+ */
+ @Deprecated
+ public XPathRule() {
+ definePropertyDescriptor(XPATH_DESCRIPTOR);
+ }
+
+ /**
+ * Make a new XPath rule with the given version + expression
+ *
+ * @param version Version of the XPath language
+ * @param expression XPath expression
+ *
+ * @throws NullPointerException If any of the arguments is null
+ */
+ public XPathRule(XPathVersion version, String expression) {
+ this();
+
+ Objects.requireNonNull(version, "XPath version is null");
+ Objects.requireNonNull(expression, "XPath expression is null");
+
+ setProperty(XPathRule.XPATH_DESCRIPTOR, expression);
+ }
+
+
+ @Override
+ public Rule deepCopy() {
+ XPathRule rule = (XPathRule) super.deepCopy();
+ rule.attrLogger = this.attrLogger;
+ return rule;
+ }
+
+ /**
+ * Returns the XPath expression that implements this rule.
+ */
+ public String getXPathExpression() {
+ return getProperty(XPATH_DESCRIPTOR);
+ }
+
+
+ @Override
+ public void apply(Node target, RuleContext ctx) {
+ SaxonXPathRuleQuery query = getQueryMaybeInitialize();
+
+ List nodesWithViolation;
+ try {
+ nodesWithViolation = query.evaluate(target);
+ } catch (PmdXPathException e) {
+ throw addExceptionContext(e);
+ }
+
+ for (Node nodeWithViolation : nodesWithViolation) {
+ addViolation(ctx, nodeWithViolation, nodeWithViolation.getImage());
+ }
+ }
+
+ private ContextedRuntimeException addExceptionContext(PmdXPathException e) {
+ return e.addRuleName(getName());
+ }
+
+ @Override
+ public void initialize(LanguageProcessor languageProcessor) {
+ String xpath = getXPathExpression();
+ XPathVersion version = XPathVersion.DEFAULT;
+
+ try {
+ xpathRuleQuery = new SaxonXPathRuleQuery(xpath,
+ version,
+ getPropertiesByPropertyDescriptor(),
+ languageProcessor.services().getXPathHandler(),
+ attrLogger);
+ } catch (PmdXPathException e) {
+ throw addExceptionContext(e);
+ }
+ }
+
+ private SaxonXPathRuleQuery getQueryMaybeInitialize() throws PmdXPathException {
+ if (xpathRuleQuery == null) {
+ throw new IllegalStateException("Not initialized");
+ }
+ return xpathRuleQuery;
+ }
+
+
+ @Override
+ protected @NonNull RuleTargetSelector buildTargetSelector() {
+
+ List visits = getQueryMaybeInitialize().getRuleChainVisits();
+
+ logXPathRuleChainUsage(!visits.isEmpty());
+
+ return visits.isEmpty() ? RuleTargetSelector.forRootOnly()
+ : RuleTargetSelector.forXPathNames(visits);
+ }
+
+
+ private void logXPathRuleChainUsage(boolean usesRuleChain) {
+ LOG.debug("{} rule chain for XPath rule: {} ({})",
+ usesRuleChain ? "Using" : "no",
+ getName(),
+ getRuleSetName());
+ }
+
+
+ @Override
+ public String dysfunctionReason() {
+ if (StringUtils.isBlank(getXPathExpression())) {
+ return "Missing XPath expression";
+ }
+ return null;
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/renderers/Renderer.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/renderers/Renderer.java
new file mode 100644
index 0000000000..3013dbc7d1
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/renderers/Renderer.java
@@ -0,0 +1,288 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+// This class has been taken from 7.0.0-SNAPSHOT
+// Changes: renderFileReport
+
+package net.sourceforge.pmd.renderers;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import net.sourceforge.pmd.annotation.Experimental;
+import net.sourceforge.pmd.benchmark.TimeTracker;
+import net.sourceforge.pmd.benchmark.TimedOperation;
+import net.sourceforge.pmd.benchmark.TimedOperationCategory;
+import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.properties.PropertySource;
+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;
+import net.sourceforge.pmd.reporting.Report.ConfigurationError;
+import net.sourceforge.pmd.reporting.Report.GlobalReportBuilderListener;
+import net.sourceforge.pmd.reporting.Report.ProcessingError;
+import net.sourceforge.pmd.reporting.Report.ReportBuilderListener;
+import net.sourceforge.pmd.reporting.Report.SuppressedViolation;
+import net.sourceforge.pmd.reporting.RuleViolation;
+
+/**
+ * This is an interface for rendering a Report. When a Renderer is being
+ * invoked, the sequence of method calls is something like the following:
+ *
+ *
{@link Renderer#startFileAnalysis(TextFile)} for each source file
+ * processed
+ *
{@link Renderer#renderFileReport(Report)} for each Report instance
+ *
{@link Renderer#end()}
+ *
+ *
+ * An implementation of the Renderer interface is expected to have a default
+ * constructor. Properties should be defined using the
+ * {@link #definePropertyDescriptor(PropertyDescriptor)}
+ * method. After the instance is created, the property values are set. This
+ * means, you won't have access to property values in your constructor.
+ */
+// TODO Are implementations expected to be thread-safe?
+public interface Renderer extends PropertySource {
+
+ /**
+ * Get the name of the Renderer.
+ *
+ * @return The name of the Renderer.
+ */
+ @Override
+ String getName();
+
+ /**
+ * Set the name of the Renderer.
+ *
+ * @param name
+ * The name of the Renderer.
+ */
+ void setName(String name);
+
+ /**
+ * Get the description of the Renderer.
+ *
+ * @return The description of the Renderer.
+ */
+ String getDescription();
+
+ /**
+ * Return the default filename extension to use.
+ *
+ * @return String
+ */
+ String defaultFileExtension();
+
+ /**
+ * Set the description of the Renderer.
+ *
+ * @param description
+ * The description of the Renderer.
+ */
+ void setDescription(String description);
+
+ /**
+ * Get the indicator for whether to show suppressed violations.
+ *
+ * @return true if suppressed violations should show,
+ * false otherwise.
+ */
+ boolean isShowSuppressedViolations();
+
+ /**
+ * Set the indicator for whether to show suppressed violations.
+ *
+ * @param showSuppressedViolations
+ * Whether to show suppressed violations.
+ */
+ void setShowSuppressedViolations(boolean showSuppressedViolations);
+
+ /**
+ * Get the Writer for the Renderer.
+ *
+ * @return The Writer.
+ */
+ Writer getWriter();
+
+ /**
+ * Set the {@link FileNameRenderer} used to render file paths to the report.
+ * Note that this renderer does not have to use the parameter to output paths.
+ * Some report formats require a specific format for paths (eg a URI), and are
+ * allowed to circumvent the provided strategy.
+ *
+ * @param fileNameRenderer a non-null file name renderer
+ */
+ void setFileNameRenderer(FileNameRenderer fileNameRenderer);
+
+ /**
+ * Set the Writer for the Renderer.
+ *
+ * @param writer The Writer.
+ */
+ void setWriter(Writer writer);
+
+ /**
+ * This method is called before any source files are processed. The Renderer
+ * will have been fully initialized by the time this method is called, so
+ * the Writer and other state will be available.
+ *
+ * @throws IOException
+ */
+ void start() throws IOException;
+
+ /**
+ * This method is called each time a source file is processed. It is called
+ * after {@link Renderer#start()}, but before
+ * {@link Renderer#renderFileReport(Report)} and {@link Renderer#end()}.
+ *
+ * This method may be invoked by different threads which are processing
+ * files independently. Therefore, any non-trivial implementation of this
+ * method needs to be thread-safe.
+ *
+ * @param dataSource
+ * The source file.
+ */
+ void startFileAnalysis(TextFile dataSource);
+
+ /**
+ * Render the given file Report. There may be multiple Report instances
+ * which need to be rendered if produced by different threads. It is called
+ * after {@link Renderer#start()} and
+ * {@link Renderer#startFileAnalysis(TextFile)}, but before
+ * {@link Renderer#end()}.
+ *
+ * @param report
+ * A file Report.
+ * @throws IOException
+ *
+ * @see Report
+ */
+ void renderFileReport(Report report) throws IOException;
+
+ /**
+ * This method is at the very end of the Rendering process, after
+ * {@link Renderer#renderFileReport(Report)}.
+ */
+ void end() throws IOException;
+
+ void flush() throws IOException;
+
+ /**
+ * Sets the filename where the report should be written to. If no filename is provided,
+ * the renderer should write to stdout.
+ *
+ *
Implementations must initialize the writer of the renderer.
+ *
+ *
See {@link AbstractRenderer#setReportFile(String)} for the default impl.
+ *
+ * @param reportFilename the filename (optional).
+ */
+ @Experimental
+ void setReportFile(String reportFilename);
+
+
+
+ /**
+ * Returns a new analysis listener, that handles violations by rendering
+ * them in an implementation-defined way.
+ */
+ // TODO the default implementation matches the current behavior,
+ // ie violations are batched by file and forwarded to the renderer
+ // when the file is done. Many renderers could directly handle
+ // violations as they come though.
+ default GlobalAnalysisListener newListener() throws IOException {
+ try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) {
+ this.start();
+ }
+
+ return new GlobalAnalysisListener() {
+
+ // guard for the close routine
+ final Object reportMergeLock = new Object();
+
+ final GlobalReportBuilderListener configErrorReport = new GlobalReportBuilderListener();
+
+ @Override
+ public void onConfigError(ConfigurationError error) {
+ configErrorReport.onConfigError(error);
+ }
+
+ @Override
+ public ListenerInitializer initializer() {
+ return new ListenerInitializer() {
+ @Override
+ public void setFileNameRenderer(FileNameRenderer fileNameRenderer) {
+ Renderer.this.setFileNameRenderer(fileNameRenderer);
+ }
+ };
+ }
+
+ @Override
+ public FileAnalysisListener startFileAnalysis(TextFile file) {
+ Renderer renderer = Renderer.this;
+
+ renderer.startFileAnalysis(file); // this routine is thread-safe by contract
+ return new FileAnalysisListener() {
+ final ReportBuilderListener reportBuilder = new ReportBuilderListener();
+
+ @Override
+ public void onRuleViolation(RuleViolation violation) {
+ reportBuilder.onRuleViolation(violation);
+ }
+
+ @Override
+ public void onSuppressedRuleViolation(SuppressedViolation violation) {
+ reportBuilder.onSuppressedRuleViolation(violation);
+ }
+
+ @Override
+ public void onError(ProcessingError error) {
+ reportBuilder.onError(error);
+ }
+
+ @Override
+ public void close() throws Exception {
+ reportBuilder.close();
+ synchronized (reportMergeLock) {
+ // TODO renderFileReport should be thread-safe instead
+ try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) {
+ renderer.renderFileReport(reportBuilder.getResult());
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "FileRendererListener[" + Renderer.this + "]";
+ }
+ };
+ }
+
+ @Override
+ public void close() throws Exception {
+ configErrorReport.close();
+ Renderer.this.renderFileReport(configErrorReport.getResult());
+ try (TimedOperation ignored = TimeTracker.startOperation(TimedOperationCategory.REPORTING)) {
+ end();
+ flush();
+ }
+ }
+ };
+ }
+
+ // --- compat
+ default void renderFileReport(net.sourceforge.pmd.Report report) throws IOException {
+ Report newReport = new Report();
+ newReport.merge(report);
+ renderFileReport(newReport);
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/reporting/Report.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/reporting/Report.java
new file mode 100644
index 0000000000..22d8b59758
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/reporting/Report.java
@@ -0,0 +1,43 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.reporting;
+
+import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.document.FileId;
+
+public class Report extends net.sourceforge.pmd.Report {
+
+ public static class ConfigurationError extends net.sourceforge.pmd.Report.ConfigurationError {
+ public ConfigurationError(Rule theRule, String theIssue) {
+ super(theRule, theIssue);
+ }
+ }
+
+ public static class ProcessingError extends net.sourceforge.pmd.Report.ProcessingError {
+ public ProcessingError(Throwable error, FileId file) {
+ super(error, file);
+ }
+ }
+
+ public static class SuppressedViolation extends net.sourceforge.pmd.Report.SuppressedViolation {
+ private final RuleViolation rv;
+
+ public SuppressedViolation(RuleViolation rv, ViolationSuppressor suppressor, String userMessage) {
+ super(rv, suppressor, userMessage);
+ this.rv = rv;
+ }
+
+ @Override
+ public net.sourceforge.pmd.reporting.RuleViolation getRuleViolation() {
+ return rv;
+ }
+ }
+
+ public static final class GlobalReportBuilderListener extends net.sourceforge.pmd.Report.GlobalReportBuilderListener {
+ }
+
+ public static final class ReportBuilderListener extends net.sourceforge.pmd.Report.ReportBuilderListener {
+ }
+}
diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/reporting/RuleViolation.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/reporting/RuleViolation.java
new file mode 100644
index 0000000000..d501b9820e
--- /dev/null
+++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/reporting/RuleViolation.java
@@ -0,0 +1,8 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.reporting;
+
+public interface RuleViolation extends net.sourceforge.pmd.RuleViolation {
+}
diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml
index 2f57145455..12d73daa38 100644
--- a/pmd-core/pom.xml
+++ b/pmd-core/pom.xml
@@ -86,11 +86,6 @@
slf4j-simpletest
-
- com.github.tomakehurst
- wiremock-jre8
- test
- org.hamcresthamcrest
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java
index 578f16b1e6..b11df3bd2c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java
@@ -28,6 +28,8 @@ import net.sourceforge.pmd.cache.internal.NoopAnalysisCache;
import net.sourceforge.pmd.internal.util.ClasspathClassLoader;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
+import net.sourceforge.pmd.lang.rule.RulePriority;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.renderers.RendererFactory;
import net.sourceforge.pmd.util.AssertionUtil;
@@ -45,9 +47,6 @@ import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
* These can be file paths or classpath resources.
*
Use {@link #setMinimumPriority(RulePriority)} to control the minimum priority a
* rule must have to be included. Defaults to the lowest priority, ie all rules are loaded.
- *
Use {@link #setRuleSetFactoryCompatibilityEnabled(boolean)} to disable the
- * compatibility measures for removed and renamed rules in the rulesets that will
- * be loaded.
*
*
*
Source files
@@ -107,7 +106,6 @@ public class PMDConfiguration extends AbstractConfiguration {
// Rule and source file options
private List ruleSets = new ArrayList<>();
private RulePriority minimumPriority = RulePriority.LOW;
- private boolean ruleSetFactoryCompatibilityEnabled = true;
// Reporting options
private String reportFormat;
@@ -450,28 +448,6 @@ public class PMDConfiguration extends AbstractConfiguration {
this.failOnViolation = failOnViolation;
}
- /**
- * Checks if the rule set factory compatibility feature is enabled.
- *
- * @return true, if the rule set factory compatibility feature is enabled
- *
- * @see RuleSetLoader#enableCompatibility(boolean)
- */
- public boolean isRuleSetFactoryCompatibilityEnabled() {
- return ruleSetFactoryCompatibilityEnabled;
- }
-
- /**
- * Sets the rule set factory compatibility feature enabled/disabled.
- *
- * @param ruleSetFactoryCompatibilityEnabled {@code true} if the feature should be enabled
- *
- * @see RuleSetLoader#enableCompatibility(boolean)
- */
- public void setRuleSetFactoryCompatibilityEnabled(boolean ruleSetFactoryCompatibilityEnabled) {
- this.ruleSetFactoryCompatibilityEnabled = ruleSetFactoryCompatibilityEnabled;
- }
-
/**
* Retrieves the currently used analysis cache. Will never be null.
*
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java
index a8094ecd59..e3a211cefa 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java
@@ -21,7 +21,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
-import net.sourceforge.pmd.Report.GlobalReportBuilderListener;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
@@ -43,11 +42,17 @@ import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
import net.sourceforge.pmd.lang.document.FileCollector;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.reporting.ConfigurableFileNameRenderer;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.reporting.ListenerInitializer;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.Report.GlobalReportBuilderListener;
import net.sourceforge.pmd.reporting.ReportStats;
import net.sourceforge.pmd.reporting.ReportStatsListener;
import net.sourceforge.pmd.util.AssertionUtil;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java
deleted file mode 100644
index 486f6b71e5..0000000000
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java
+++ /dev/null
@@ -1,496 +0,0 @@
-/**
- * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
- */
-
-package net.sourceforge.pmd;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-import org.apache.commons.lang3.StringUtils;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-import net.sourceforge.pmd.annotation.InternalApi;
-import net.sourceforge.pmd.util.internal.ResourceLoader;
-import net.sourceforge.pmd.util.log.PmdReporter;
-
-/**
- * This class is used to parse a RuleSet reference value. Most commonly used for
- * specifying a RuleSet to process, or in a Rule 'ref' attribute value in the
- * RuleSet XML. The RuleSet reference can refer to either an external RuleSet or
- * the current RuleSet when used as a Rule 'ref' attribute value. An individual
- * Rule in the RuleSet can be indicated.
- *
- * For an external RuleSet, referring to the entire RuleSet, the format is
- * ruleSetName, where the RuleSet name is either a resource file path to
- * a RuleSet that ends with '.xml', or a simple RuleSet name.
- *
- * A simple RuleSet name, is one which contains no path separators, and either
- * contains a '-' or is entirely numeric release number. A simple name of the
- * form [language]-[name] is short for the full RuleSet name
- * rulesets/[language]/[name].xml. A numeric release simple name of
- * the form [release] is short for the full PMD Release RuleSet
- * name rulesets/releases/[release].xml.
- *
- * For an external RuleSet, referring to a single Rule, the format is
- * ruleSetName/ruleName, where the RuleSet name is as described above. A
- * Rule with the ruleName should exist in this external RuleSet.
- *
- * For the current RuleSet, the format is ruleName, where the Rule name
- * is not RuleSet name (i.e. contains no path separators, '-' or '.xml' in it,
- * and is not all numeric). A Rule with the ruleName should exist in the
- * current RuleSet.
- *
- *
- *
Examples
- *
- *
String
- *
RuleSet file name
- *
Rule
- *
- *
- *
- *
rulesets/java/basic.xml
- *
rulesets/java/basic.xml
- *
all
- *
- *
- *
rulesets/java/basic.xml/EmptyCatchBlock
- *
rulesets/java/basic.xml
- *
EmptyCatchBlock
- *
- *
- *
EmptyCatchBlock
- *
null
- *
EmptyCatchBlock
- *
- *
- *
- *
- * @deprecated This is part of the internals of the {@link RuleSetLoader}.
- */
-@Deprecated
-@InternalApi
-public class RuleSetReferenceId {
-
- // todo this class has issues... What is even an "external" ruleset?
- // terminology and API should be clarified.
-
- private final boolean external;
- private final String ruleSetFileName;
- private final boolean allRules;
- private final String ruleName;
- private final RuleSetReferenceId externalRuleSetReferenceId;
-
- private final String originalRef;
-
- /**
- * Construct a RuleSetReferenceId for the given single ID string.
- *
- * @param id
- * The id string.
- * @throws IllegalArgumentException
- * If the ID contains a comma character.
- */
- public RuleSetReferenceId(final String id) {
-
- this(id, null, null);
- }
-
- private RuleSetReferenceId(final String ruleSetFileName, boolean external, String ruleName, RuleSetReferenceId externalRuleSetReferenceId) {
- this.ruleSetFileName = Objects.requireNonNull(ruleSetFileName);
- this.originalRef = ruleName == null ? ruleSetFileName : ruleSetFileName + "/" + ruleName;
- this.allRules = ruleName == null;
- this.external = external;
- this.ruleName = ruleName;
- this.externalRuleSetReferenceId = externalRuleSetReferenceId;
- }
-
- /**
- * Construct a RuleSetReferenceId for the given single ID string. If an
- * external RuleSetReferenceId is given, the ID must refer to a non-external
- * Rule. The external RuleSetReferenceId will be responsible for producing
- * the InputStream containing the Rule.
- *
- * @param id The id string.
- * @param externalRuleSetReferenceId A RuleSetReferenceId to associate with this new instance.
- *
- * @throws IllegalArgumentException If the ID contains a comma character.
- * @throws IllegalArgumentException If external RuleSetReferenceId is not external.
- * @throws IllegalArgumentException If the ID is not Rule reference when there is an external
- * RuleSetReferenceId.
- */
- public RuleSetReferenceId(final String id, final RuleSetReferenceId externalRuleSetReferenceId) {
- this(id, externalRuleSetReferenceId, null);
- }
-
- /**
- * Construct a RuleSetReferenceId for the given single ID string. If an
- * external RuleSetReferenceId is given, the ID must refer to a non-external
- * Rule. The external RuleSetReferenceId will be responsible for producing
- * the InputStream containing the Rule.
- *
- * @param id The id string.
- * @param externalRuleSetReferenceId A RuleSetReferenceId to associate with this new instance.
- *
- * @throws IllegalArgumentException If the ID contains a comma character.
- * @throws IllegalArgumentException If external RuleSetReferenceId is not external.
- * @throws IllegalArgumentException If the ID is not Rule reference when there is an external
- * RuleSetReferenceId.
- */
- RuleSetReferenceId(final String id,
- final RuleSetReferenceId externalRuleSetReferenceId,
- final @Nullable PmdReporter err) {
- this.originalRef = id;
-
- if (externalRuleSetReferenceId != null && !externalRuleSetReferenceId.isExternal()) {
- throw new IllegalArgumentException("Cannot pair with non-external <" + externalRuleSetReferenceId + ">.");
- }
-
- if (id != null && id.indexOf(',') >= 0) {
- throw new IllegalArgumentException(
- "A single RuleSetReferenceId cannot contain ',' (comma) characters: " + id);
- }
-
- // Damn this parsing sucks, but my brain is just not working to let me
- // write a simpler scheme.
-
- if (isValidUrl(id)) {
- // A full RuleSet name
- external = true;
- ruleSetFileName = StringUtils.strip(id);
- allRules = true;
- ruleName = null;
- } else if (isFullRuleSetName(id)) {
- // A full RuleSet name
- external = true;
- ruleSetFileName = id;
- allRules = true;
- ruleName = null;
- } else {
- String tempRuleName = getRuleName(id);
- String tempRuleSetFileName = tempRuleName != null && id != null
- ? id.substring(0, id.length() - tempRuleName.length() - 1) : id;
-
- if (isValidUrl(tempRuleSetFileName)) {
- // remaining part is a xml ruleset file, so the tempRuleName is
- // probably a real rule name
- external = true;
- ruleSetFileName = StringUtils.strip(tempRuleSetFileName);
- ruleName = StringUtils.strip(tempRuleName);
- allRules = tempRuleName == null;
- } else if (isHttpUrl(id)) {
- // it's a url, we can't determine whether it's a full ruleset or
- // a single rule - so falling back to
- // a full RuleSet name
- external = true;
- ruleSetFileName = StringUtils.strip(id);
- allRules = true;
- ruleName = null;
- } else if (isFullRuleSetName(tempRuleSetFileName)) {
- // remaining part is a xml ruleset file, so the tempRuleName is
- // probably a real rule name
- external = true;
- ruleSetFileName = tempRuleSetFileName;
- ruleName = tempRuleName;
- allRules = tempRuleName == null;
- } else {
- // resolve the ruleset name - it's maybe a built in ruleset
- String expandedRuleset = resolveDeprecatedBuiltInRulesetShorthand(tempRuleSetFileName);
- String builtinRuleSet = expandedRuleset == null ? tempRuleSetFileName : expandedRuleset;
- if (checkRulesetExists(builtinRuleSet)) {
- if (expandedRuleset != null && err != null) {
- err.warn(
- "Ruleset reference ''{0}'' uses a deprecated form, use ''{1}'' instead",
- tempRuleSetFileName, builtinRuleSet
- );
- }
-
- external = true;
- ruleSetFileName = builtinRuleSet;
- ruleName = tempRuleName;
- allRules = tempRuleName == null;
- } else {
- // well, we didn't find the ruleset, so it's probably not a
- // internal ruleset.
- // at this time, we don't know, whether the tempRuleName is
- // a name of the rule
- // or the file name of the ruleset file.
- // It is assumed, that tempRuleName is actually the filename
- // of the ruleset,
- // if there are more separator characters in the remaining
- // ruleset filename (tempRuleSetFileName).
- // This means, the only reliable way to specify single rules
- // within a custom rulesest file is
- // only possible, if the ruleset file has a .xml file
- // extension.
- if (tempRuleSetFileName == null || tempRuleSetFileName.contains(File.separator)) {
- external = true;
- ruleSetFileName = id;
- ruleName = null;
- allRules = true;
- } else {
- external = externalRuleSetReferenceId != null && externalRuleSetReferenceId.isExternal();
- ruleSetFileName = externalRuleSetReferenceId != null
- ? externalRuleSetReferenceId.getRuleSetFileName() : null;
- ruleName = id;
- allRules = false;
- }
- }
- }
- }
-
- if (this.external && this.ruleName != null && !this.ruleName.equals(id) && externalRuleSetReferenceId != null) {
- throw new IllegalArgumentException(
- "Cannot pair external <" + this + "> with external <" + externalRuleSetReferenceId + ">.");
- }
- this.externalRuleSetReferenceId = externalRuleSetReferenceId;
- }
-
- @Nullable RuleSetReferenceId getParentRulesetIfThisIsARule() {
- if (ruleName == null) {
- return null;
- }
- return new RuleSetReferenceId(
- ruleSetFileName,
- external,
- null,
-
- null
- );
- }
-
- /**
- * Tries to load the given ruleset.
- *
- * @param name
- * the ruleset name
- * @return true if the ruleset could be loaded,
- * false otherwise.
- */
- private boolean checkRulesetExists(final String name) {
- boolean resourceFound = false;
- if (name != null) {
- try (InputStream ignored = new ResourceLoader().loadClassPathResourceAsStreamOrThrow(name)) {
- resourceFound = true;
- } catch (Exception ignored) {
- // ignored
- }
- }
- return resourceFound;
- }
-
- /**
- * Assumes that the ruleset name given is e.g. "java-basic". Then it will
- * return the full classpath name for the ruleset, in this example it would
- * return "rulesets/java/basic.xml".
- *
- * @param name
- * the ruleset name
- * @return the full classpath to the ruleset
- */
- private String resolveDeprecatedBuiltInRulesetShorthand(final String name) {
- if (name == null) {
- return null;
- }
- // Likely a simple RuleSet name
- int index = name.indexOf('-');
- if (index > 0) {
- // Standard short name
- return "rulesets/" + name.substring(0, index) + '/' + name.substring(index + 1) + ".xml";
- }
- // A release RuleSet?
- if (name.matches("[0-9]+.*")) {
- return "rulesets/releases/" + name + ".xml";
- }
- // Appears to be a non-standard RuleSet name
- return null;
- }
-
- /**
- * Extracts the rule name out of a ruleset path. E.g. for
- * "/my/ruleset.xml/MyRule" it would return "MyRule". If no single rule is
- * specified, null is returned.
- *
- * @param rulesetName
- * the full rule set path
- * @return the rule name or null.
- */
- private String getRuleName(final String rulesetName) {
- String result = null;
- if (rulesetName != null) {
- // Find last path separator if it exists... this might be a rule
- // name
- final int separatorIndex = Math.max(rulesetName.lastIndexOf('/'), rulesetName.lastIndexOf('\\'));
- if (separatorIndex >= 0 && separatorIndex != rulesetName.length() - 1) {
- result = rulesetName.substring(separatorIndex + 1);
- }
- }
- return result;
- }
-
- private static boolean isHttpUrl(String name) {
- String stripped = StringUtils.strip(name);
- return stripped != null && (stripped.startsWith("http://") || stripped.startsWith("https://"));
- }
-
- private static boolean isValidUrl(String name) {
- if (isHttpUrl(name)) {
- String url = StringUtils.strip(name);
- try {
- // FIXME : Do we really need to perform a request? if it's a url we should treat it as one even if the server is down
- HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
- connection.setRequestMethod("HEAD");
- connection.setConnectTimeout(ResourceLoader.TIMEOUT);
- connection.setReadTimeout(ResourceLoader.TIMEOUT);
- int responseCode = connection.getResponseCode();
- if (responseCode == 200) {
- return true;
- }
- } catch (IOException e) {
- return false;
- }
- }
- return false;
- }
-
- private static boolean isFullRuleSetName(String name) {
-
- return name != null && name.endsWith(".xml");
- }
-
- /**
- * Parse a String comma separated list of RuleSet reference IDs into a List
- * of RuleReferenceId instances.
- *
- * @param referenceString A comma separated list of RuleSet reference IDs.
- *
- * @return The corresponding List of RuleSetReferenceId instances.
- */
- // TODO deprecate and remove
- public static List parse(String referenceString) {
- return parse(referenceString, null);
- }
-
- static List parse(String referenceString,
- PmdReporter err) {
- List references = new ArrayList<>();
- if (referenceString != null && referenceString.trim().length() > 0) {
-
- if (referenceString.indexOf(',') == -1) {
- references.add(new RuleSetReferenceId(referenceString, null, err));
- } else {
- for (String name : referenceString.split(",")) {
- references.add(new RuleSetReferenceId(name.trim(), null, err));
- }
- }
- }
- return references;
- }
-
- /**
- * Is this an external RuleSet reference?
- *
- * @return true if this is an external reference,
- * false otherwise.
- */
- public boolean isExternal() {
- return external;
- }
-
- /**
- * Is this a reference to all Rules in a RuleSet, or a single Rule?
- *
- * @return true if this is a reference to all Rules,
- * false otherwise.
- */
- public boolean isAllRules() {
- return allRules;
- }
-
- /**
- * Get the RuleSet file name.
- *
- * @return The RuleSet file name if this is an external reference,
- * null otherwise.
- */
- public String getRuleSetFileName() {
- return ruleSetFileName;
- }
-
- /**
- * Get the Rule name.
- *
- * @return The Rule name. The Rule name.
- */
- public String getRuleName() {
- return ruleName;
- }
-
- /**
- * Try to load the RuleSet resource with the specified ResourceLoader. Multiple
- * attempts to get independent InputStream instances may be made, so
- * subclasses must ensure they support this behavior. Delegates to an
- * external RuleSetReferenceId if there is one associated with this
- * instance.
- *
- * @param rl The {@link ResourceLoader} to use.
- * @return An InputStream to that resource.
- */
- public InputStream getInputStream(final ResourceLoader rl) throws IOException {
- if (externalRuleSetReferenceId == null) {
- if (StringUtils.isBlank(ruleSetFileName)) {
- throw notFoundException();
- }
- try {
- return rl.loadResourceAsStream(ruleSetFileName);
- } catch (FileNotFoundException ignored) {
- throw notFoundException();
- }
- } else {
- return externalRuleSetReferenceId.getInputStream(rl);
- }
- }
-
- private FileNotFoundException notFoundException() {
- return new FileNotFoundException("Cannot resolve rule/ruleset reference '" + originalRef
- + "'" + ". Make sure the resource is a valid file or URL and is on the CLASSPATH. "
- + "Use --debug (or a fine log level) to see the current classpath.");
- }
-
- /**
- * Return the String form of this Rule reference.
- *
- * @return Return the String form of this Rule reference, which is
- * ruleSetFileName for all Rule external references,
- * ruleSetFileName/ruleName, for a single Rule external
- * references, or ruleName otherwise.
- *
- * @deprecated Do not rely on the format of this method, it may be changed in PMD 7.
- */
- @Override
- @Deprecated
- public String toString() {
- if (ruleSetFileName != null) {
- if (allRules) {
- return ruleSetFileName;
- } else {
- return ruleSetFileName + '/' + ruleName;
- }
-
- } else {
- if (allRules) {
- return "anonymous all Rule";
- } else {
- return ruleName;
- }
- }
- }
-}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AbstractAnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AbstractAnalysisCache.java
index 733ddf6581..7108a368b7 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AbstractAnalysisCache.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AbstractAnalysisCache.java
@@ -26,9 +26,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sourceforge.pmd.PMDVersion;
-import net.sourceforge.pmd.Report.ProcessingError;
-import net.sourceforge.pmd.RuleSets;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
@@ -36,7 +33,10 @@ import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextDocument;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
+import net.sourceforge.pmd.reporting.Report.ProcessingError;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* Abstract implementation of the analysis cache. Handles all operations, except for persistence.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCache.java
index 8568e449af..13e9f6ee6b 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCache.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCache.java
@@ -8,12 +8,12 @@ import java.io.IOException;
import java.util.Collection;
import java.util.List;
-import net.sourceforge.pmd.RuleSets;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.document.TextDocument;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* An analysis cache for incremental analysis.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCacheListener.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCacheListener.java
index 002ac4a3d9..fdd719c614 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCacheListener.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCacheListener.java
@@ -7,8 +7,8 @@ package net.sourceforge.pmd.cache.internal;
import java.io.IOException;
import java.util.Collection;
-import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisResult.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisResult.java
index e5a44a0c0d..3de09d07df 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisResult.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisResult.java
@@ -7,7 +7,7 @@ package net.sourceforge.pmd.cache.internal;
import java.util.ArrayList;
import java.util.List;
-import net.sourceforge.pmd.RuleViolation;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* The result of a single file analysis.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleMapper.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleMapper.java
index 2e3b270171..1fd7a362a2 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleMapper.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleMapper.java
@@ -7,8 +7,8 @@ package net.sourceforge.pmd.cache.internal;
import java.util.HashMap;
import java.util.Map;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleSets;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
/**
* A mapper from rule class names to rule instances for cached rules.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleViolation.java
index 18fcde4e0f..41defe0c2e 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleViolation.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleViolation.java
@@ -14,11 +14,11 @@ import java.util.Map.Entry;
import org.checkerframework.checker.nullness.qual.NonNull;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.FileLocation;
import net.sourceforge.pmd.lang.document.TextRange2d;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.reporting.RuleViolation;
import net.sourceforge.pmd.util.StringUtil;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/FileAnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/FileAnalysisCache.java
index de286efb9a..2fcd061b52 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/FileAnalysisCache.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/FileAnalysisCache.java
@@ -19,13 +19,13 @@ import java.util.Map;
import java.util.stream.Collectors;
import net.sourceforge.pmd.PMDVersion;
-import net.sourceforge.pmd.RuleSets;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* An analysis cache backed by a regular file.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/NoopAnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/NoopAnalysisCache.java
index 4e4528340d..da030a4317 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/NoopAnalysisCache.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/NoopAnalysisCache.java
@@ -8,11 +8,11 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import net.sourceforge.pmd.RuleSets;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.document.TextDocument;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* A NOOP analysis cache. Easier / safer than null-checking.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyCpdLexer.java
similarity index 91%
rename from pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyCpdLexer.java
index 0d3de7a45d..db0988c0ff 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyCpdLexer.java
@@ -20,9 +20,10 @@ import net.sourceforge.pmd.util.StringUtil;
* Higher-quality lexers should be implemented with a lexer generator.
*
*
In PMD 7, this replaces AbstractTokenizer, which provided nearly
- * no more functionality.
+ * no more functionality.
+ *
Note: This class has been called AnyTokenizer in PMD 6.
*/
-public class AnyTokenizer implements Tokenizer {
+public class AnyCpdLexer implements CpdLexer {
private static final Pattern DEFAULT_PATTERN = makePattern("");
@@ -40,15 +41,15 @@ public class AnyTokenizer implements Tokenizer {
private final Pattern pattern;
private final String commentStart;
- public AnyTokenizer() {
+ public AnyCpdLexer() {
this(DEFAULT_PATTERN, "");
}
- public AnyTokenizer(String eolCommentStart) {
+ public AnyCpdLexer(String eolCommentStart) {
this(makePattern(eolCommentStart), eolCommentStart);
}
- private AnyTokenizer(Pattern pattern, String commentStart) {
+ private AnyCpdLexer(Pattern pattern, String commentStart) {
this.pattern = pattern;
this.commentStart = commentStart;
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java
index 52e7309f69..3f54d51ff9 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java
@@ -23,7 +23,7 @@ import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
+import net.sourceforge.pmd.lang.ast.LexException;
import net.sourceforge.pmd.lang.document.FileCollector;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextDocument;
@@ -137,10 +137,10 @@ public final class CpdAnalysis implements AutoCloseable {
this.listener = cpdListener;
}
- private int doTokenize(TextDocument document, Tokenizer tokenizer, Tokens tokens) throws IOException, TokenMgrError {
+ private int doTokenize(TextDocument document, CpdLexer cpdLexer, Tokens tokens) throws IOException, LexException {
LOGGER.trace("Tokenizing {}", document.getFileId().getAbsolutePath());
int lastTokenSize = tokens.size();
- Tokenizer.tokenize(tokenizer, document, tokens);
+ CpdLexer.tokenize(cpdLexer, document, tokens);
return tokens.size() - lastTokenSize - 1; /* EOF */
}
@@ -152,12 +152,12 @@ public final class CpdAnalysis implements AutoCloseable {
public void performAnalysis(Consumer consumer) {
try (SourceManager sourceManager = new SourceManager(files.getCollectedFiles())) {
- Map tokenizers =
+ Map tokenizers =
sourceManager.getTextFiles().stream()
.map(it -> it.getLanguageVersion().getLanguage())
.distinct()
.filter(it -> it instanceof CpdCapableLanguage)
- .collect(Collectors.toMap(lang -> lang, lang -> ((CpdCapableLanguage) lang).createCpdTokenizer(configuration.getLanguageProperties(lang))));
+ .collect(Collectors.toMap(lang -> lang, lang -> ((CpdCapableLanguage) lang).createCpdLexer(configuration.getLanguageProperties(lang))));
Map numberOfTokensPerFile = new HashMap<>();
@@ -170,7 +170,7 @@ public final class CpdAnalysis implements AutoCloseable {
int newTokens = doTokenize(textDocument, tokenizers.get(textFile.getLanguageVersion().getLanguage()), tokens);
numberOfTokensPerFile.put(textDocument.getFileId(), newTokens);
listener.addedFile(1);
- } catch (TokenMgrError | IOException e) {
+ } catch (LexException | IOException e) {
if (e instanceof FileAnalysisException) { // NOPMD
((FileAnalysisException) e).setFileId(textFile.getFileId());
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdCapableLanguage.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdCapableLanguage.java
index 34f854268d..6484713f14 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdCapableLanguage.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdCapableLanguage.java
@@ -16,7 +16,7 @@ public interface CpdCapableLanguage extends Language {
/**
- * Create a new {@link Tokenizer} for this language, given
+ * Create a new {@link CpdLexer} for this language, given
* a property bundle with configuration. The bundle was created by
* this instance using {@link #newPropertyBundle()}. It can be assumed
* that the bundle will never be mutated anymore, and this method
@@ -26,7 +26,7 @@ public interface CpdCapableLanguage extends Language {
*
* @return A new language processor
*/
- default Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new AnyTokenizer();
+ default CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new AnyCpdLexer();
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdLexer.java
similarity index 65%
rename from pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdLexer.java
index 5c37848c0c..5a88b259eb 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdLexer.java
@@ -10,8 +10,10 @@ import net.sourceforge.pmd.lang.document.TextDocument;
/**
* Tokenizes a source file into tokens consumable by CPD.
+ *
+ *
Note: This interface has been called Tokenizer in PMD 6.
*/
-public interface Tokenizer {
+public interface CpdLexer {
/**
* Tokenize the source code and record tokens using the provided token factory.
@@ -22,15 +24,15 @@ public interface Tokenizer {
* Wraps a call to {@link #tokenize(TextDocument, TokenFactory)} to properly
* create and close the token factory.
*/
- static void tokenize(Tokenizer tokenizer, TextDocument textDocument, Tokens tokens) throws IOException {
+ static void tokenize(CpdLexer cpdLexer, TextDocument textDocument, Tokens tokens) throws IOException {
try (TokenFactory tf = Tokens.factoryForFile(textDocument, tokens)) {
- tokenizer.tokenize(textDocument, tf);
+ cpdLexer.tokenize(textDocument, tf);
}
}
- static Tokens tokenize(Tokenizer tokenizer, TextDocument textDocument) throws IOException {
+ static Tokens tokenize(CpdLexer cpdLexer, TextDocument textDocument) throws IOException {
Tokens tokens = new Tokens();
- tokenize(tokenizer, textDocument, tokens);
+ tokenize(cpdLexer, textDocument, tokens);
return tokens;
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java
index 033f40822c..54e98722b2 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java
@@ -142,8 +142,8 @@ public class GUI implements CPDListener {
.extensions(extension)
.name("By extension...")) {
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new AnyTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new AnyCpdLexer();
}
};
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/TokenFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/TokenFactory.java
index 4a7e5a3e49..cfc2eba638 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/TokenFactory.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/TokenFactory.java
@@ -7,12 +7,12 @@ package net.sourceforge.pmd.cpd;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
+import net.sourceforge.pmd.lang.ast.LexException;
import net.sourceforge.pmd.lang.document.FileLocation;
import net.sourceforge.pmd.lang.document.TextDocument;
/**
- * Proxy to record tokens from within {@link Tokenizer#tokenize(TextDocument, TokenFactory)}.
+ * Proxy to record tokens from within {@link CpdLexer#tokenize(TextDocument, TokenFactory)}.
*/
public interface TokenFactory extends AutoCloseable {
@@ -43,7 +43,7 @@ public interface TokenFactory extends AutoCloseable {
recordToken(image, location.getStartLine(), location.getStartColumn(), location.getEndLine(), location.getEndColumn());
}
- TokenMgrError makeLexException(int line, int column, String message, @Nullable Throwable cause);
+ LexException makeLexException(int line, int column, String message, @Nullable Throwable cause);
/**
* Sets the image of an existing token entry.
@@ -57,7 +57,7 @@ public interface TokenFactory extends AutoCloseable {
/**
* This adds the EOF token, it must be called when
- * {@link Tokenizer#tokenize(TextDocument, TokenFactory)} is done.
+ * {@link CpdLexer#tokenize(TextDocument, TokenFactory)} is done.
*/
@Override
void close();
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java
index f87877f95a..105efdcaa8 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java
@@ -13,7 +13,7 @@ import java.util.Map.Entry;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
+import net.sourceforge.pmd.lang.ast.LexException;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextDocument;
@@ -91,7 +91,7 @@ public class Tokens {
/**
* Creates a token factory to process the given file with
- * {@link Tokenizer#tokenize(TextDocument, TokenFactory)}.
+ * {@link CpdLexer#tokenize(TextDocument, TokenFactory)}.
* Tokens are accumulated in the {@link Tokens} parameter.
*
* @param file Document for the file to process
@@ -115,8 +115,8 @@ public class Tokens {
}
@Override
- public TokenMgrError makeLexException(int line, int column, String message, @Nullable Throwable cause) {
- return new TokenMgrError(line, column, fileId, message, cause);
+ public LexException makeLexException(int line, int column, String message, @Nullable Throwable cause) {
+ return new LexException(line, column, fileId, message, cause);
}
@Override
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrCpdLexer.java
similarity index 82%
rename from pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrCpdLexer.java
index 07e2610d06..3c06996210 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrTokenizer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/AntlrCpdLexer.java
@@ -10,16 +10,16 @@ import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.Lexer;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrToken;
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
import net.sourceforge.pmd.lang.document.TextDocument;
/**
- * Generic implementation of a {@link Tokenizer} useful to any Antlr grammar.
+ * Generic implementation of a {@link CpdLexer} useful to any Antlr grammar.
*/
-public abstract class AntlrTokenizer extends TokenizerBase {
+public abstract class AntlrCpdLexer extends CpdLexerBase {
@Override
protected final TokenManager makeLexerImpl(TextDocument doc) throws IOException {
CharStream charStream = CharStreams.fromReader(doc.newReader(), doc.getFileId().getAbsolutePath());
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/TokenizerBase.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/CpdLexerBase.java
similarity index 87%
rename from pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/TokenizerBase.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/CpdLexerBase.java
index e43627bba7..22478fa344 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/TokenizerBase.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/CpdLexerBase.java
@@ -6,16 +6,16 @@ package net.sourceforge.pmd.cpd.impl;
import java.io.IOException;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.cpd.TokenFactory;
-import net.sourceforge.pmd.cpd.Tokenizer;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.GenericToken;
import net.sourceforge.pmd.lang.document.TextDocument;
/**
- * Generic base class for a {@link Tokenizer}.
+ * Generic base class for a {@link CpdLexer}.
*/
-public abstract class TokenizerBase> implements Tokenizer {
+public abstract class CpdLexerBase> implements CpdLexer {
protected abstract TokenManager makeLexerImpl(TextDocument doc) throws IOException;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/JavaCCTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/JavaCCTokenizer.java
deleted file mode 100644
index 319d9dd0f3..0000000000
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/JavaCCTokenizer.java
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
- */
-
-package net.sourceforge.pmd.cpd.impl;
-
-import net.sourceforge.pmd.cpd.Tokenizer;
-import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
-
-/**
- * Base class for a {@link Tokenizer} for a language implemented by a JavaCC tokenizer.
- */
-public abstract class JavaCCTokenizer extends TokenizerBase {
-
-}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/JavaccCpdLexer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/JavaccCpdLexer.java
new file mode 100644
index 0000000000..7f5641aedb
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/JavaccCpdLexer.java
@@ -0,0 +1,15 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.cpd.impl;
+
+import net.sourceforge.pmd.cpd.CpdLexer;
+import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
+
+/**
+ * Base class for a {@link CpdLexer} for a language implemented by a JavaCC tokenizer.
+ */
+public abstract class JavaccCpdLexer extends CpdLexerBase {
+
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/package-info.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/package-info.java
index 7e2f66591f..aa699a7319 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/package-info.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/impl/package-info.java
@@ -3,6 +3,6 @@
*/
/**
- * Utilities to implement a CPD {@link net.sourceforge.pmd.cpd.Tokenizer}.
+ * Utilities to implement a CPD {@link net.sourceforge.pmd.cpd.CpdLexer}.
*/
package net.sourceforge.pmd.cpd.impl;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/package-info.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/package-info.java
index ecb7637667..224bcc8f6a 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/package-info.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/package-info.java
@@ -6,6 +6,6 @@
* Token-based copy-paste detection.
*
* @see net.sourceforge.pmd.cpd.CpdAnalysis
- * @see net.sourceforge.pmd.cpd.Tokenizer
+ * @see net.sourceforge.pmd.cpd.CpdLexer
*/
package net.sourceforge.pmd.cpd;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java
index 7a7618e264..08d11470c5 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java
@@ -6,10 +6,10 @@ package net.sourceforge.pmd.lang;
import java.util.List;
-import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.cache.internal.AnalysisCache;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.util.log.PmdReporter;
@@ -29,12 +29,12 @@ public final class InternalApiBridge {
private InternalApiBridge() {}
public static LanguageProcessor.AnalysisTask createAnalysisTask(RuleSets rulesets,
- List files,
- GlobalAnalysisListener listener,
- int threadCount,
- AnalysisCache analysisCache,
- PmdReporter messageReporter,
- LanguageProcessorRegistry lpRegistry) {
+ List files,
+ GlobalAnalysisListener listener,
+ int threadCount,
+ AnalysisCache analysisCache,
+ PmdReporter messageReporter,
+ LanguageProcessorRegistry lpRegistry) {
return new LanguageProcessor.AnalysisTask(rulesets, files, listener, threadCount, analysisCache, messageReporter, lpRegistry);
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java
index 269f0be8c3..48bcdbcce8 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java
@@ -9,9 +9,9 @@ import java.util.List;
import org.checkerframework.checker.nullness.qual.NonNull;
-import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.cache.internal.AnalysisCache;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.util.log.PmdReporter;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersion.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersion.java
index d14f147ec9..4867572717 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersion.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersion.java
@@ -7,7 +7,7 @@ package net.sourceforge.pmd.lang;
import java.util.List;
import java.util.Objects;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
/**
* Represents a version of a {@link Language}. Language instances provide
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java
index 3e6d3063a5..f1650cc9a1 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java
@@ -7,12 +7,12 @@ package net.sourceforge.pmd.lang;
import java.util.Collections;
import java.util.List;
-import net.sourceforge.pmd.ViolationSuppressor;
import net.sourceforge.pmd.annotation.Experimental;
import net.sourceforge.pmd.lang.ast.Parser;
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler;
import net.sourceforge.pmd.reporting.ViolationDecorator;
+import net.sourceforge.pmd.reporting.ViolationSuppressor;
import net.sourceforge.pmd.util.designerbindings.DesignerBindings;
import net.sourceforge.pmd.util.designerbindings.DesignerBindings.DefaultDesignerBindings;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java
index 5c4c95cc08..c510759c10 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/PlainTextLanguage.java
@@ -5,9 +5,9 @@
package net.sourceforge.pmd.lang;
import net.sourceforge.pmd.annotation.Experimental;
-import net.sourceforge.pmd.cpd.AnyTokenizer;
+import net.sourceforge.pmd.cpd.AnyCpdLexer;
import net.sourceforge.pmd.cpd.CpdCapableLanguage;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.ast.AstInfo;
import net.sourceforge.pmd.lang.ast.Parser;
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
@@ -47,8 +47,8 @@ public final class PlainTextLanguage extends SimpleLanguageModuleBase implements
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new AnyTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new AnyCpdLexer();
}
private static final class TextLvh implements LanguageVersionHandler {
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/FileAnalysisException.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/FileAnalysisException.java
index 94214a0bf4..d843d80f68 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/FileAnalysisException.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/FileAnalysisException.java
@@ -16,7 +16,7 @@ import net.sourceforge.pmd.lang.document.FileLocation;
/**
* An exception that occurs while processing a file. Subtypes include
*
- *
{@link TokenMgrError}: lexical syntax errors
+ *
{@link LexException}: lexical syntax errors
*
{@link ParseException}: syntax errors
*
{@link SemanticException}: exceptions occurring after the parsing
* phase, because the source code is semantically invalid
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/TokenMgrError.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/LexException.java
similarity index 84%
rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/TokenMgrError.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/LexException.java
index 28bee8a79e..3aea6b656d 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/TokenMgrError.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/LexException.java
@@ -16,8 +16,10 @@ import net.sourceforge.pmd.util.StringUtil;
/**
* An error thrown during lexical analysis of a file.
+ *
+ *
Note: This exception has been called TokenMgrError in PMD 6.
*/
-public final class TokenMgrError extends FileAnalysisException {
+public final class LexException extends FileAnalysisException {
private final int line;
private final int column;
@@ -31,7 +33,7 @@ public final class TokenMgrError extends FileAnalysisException {
* @param message Message of the error
* @param cause Cause of the error, if any
*/
- public TokenMgrError(int line, int column, @Nullable FileId filename, String message, @Nullable Throwable cause) {
+ public LexException(int line, int column, @Nullable FileId filename, String message, @Nullable Throwable cause) {
super(message, cause);
this.line = max(line, 1);
this.column = max(column, 1);
@@ -44,7 +46,7 @@ public final class TokenMgrError extends FileAnalysisException {
* Constructor called by JavaCC.
*/
@InternalApi
- public TokenMgrError(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
+ public LexException(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
super(makeReason(eofSeen, lexStateName, errorAfter, curChar));
line = max(errorLine, 1);
column = max(errorColumn, 1);
@@ -76,7 +78,7 @@ public final class TokenMgrError extends FileAnalysisException {
* @return A new exception
*/
@Override
- public TokenMgrError setFileId(FileId fileId) {
+ public LexException setFileId(FileId fileId) {
super.setFileId(fileId);
return this;
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java
index 866748fd3b..b41c244870 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java
@@ -72,11 +72,12 @@ public interface Node extends Reportable {
* node. This is usually an identifier, but you should check that using the Designer. On most nodes though, this
* method returns {@code null}.
*
- * @deprecated Should be replaced with methods that have more specific
- * names in node classes.
+ *
Note:
+ * This method will be deprecated in the future (#4787).
+ * It will be replaced with methods that have more specific names in node classes. In some cases, there
+ * are already alternatives available that should be used.
*/
- @Deprecated
- @DeprecatedUntil700
+ // @Deprecated // todo deprecate (#4787)
default String getImage() {
return null;
}
@@ -85,12 +86,13 @@ public interface Node extends Reportable {
/**
* Returns true if this node's image is equal to the given string.
*
+ *
Note:
+ * This method will be deprecated in the future (#4787).
+ * See {@link #getImage()}.
+ *
* @param image The image to check
- *
- * @deprecated See {@link #getImage()}
*/
- @Deprecated
- @DeprecatedUntil700
+ // @Deprecated // todo deprecate (#4787)
default boolean hasImageEqualTo(String image) {
return Objects.equals(getImage(), image);
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java
index 6233d29a11..5828195850 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrTokenManager.java
@@ -10,7 +10,7 @@ import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import net.sourceforge.pmd.lang.TokenManager;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
+import net.sourceforge.pmd.lang.ast.LexException;
import net.sourceforge.pmd.lang.document.TextDocument;
/**
@@ -63,7 +63,7 @@ public class AntlrTokenManager implements TokenManager {
final int charPositionInLine,
final String msg,
final RecognitionException ex) {
- throw new TokenMgrError(line, charPositionInLine, textDoc.getFileId(), msg, ex);
+ throw new LexException(line, charPositionInLine, textDoc.getFileId(), msg, ex);
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/AbstractJjtreeNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/AbstractJjtreeNode.java
index bd11611c28..0a8e70b58b 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/AbstractJjtreeNode.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/AbstractJjtreeNode.java
@@ -38,7 +38,7 @@ public abstract class AbstractJjtreeNode, N e
}
@Override
- // @Deprecated // todo deprecate, will change tree dump tests
+ // @Deprecated // todo deprecate, will change tree dump tests (#4787)
public String getImage() {
return image;
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java
index 5887805ec4..5b727d6dd3 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java
@@ -10,7 +10,7 @@ import java.util.List;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.cpd.impl.JavaCCTokenizer;
+import net.sourceforge.pmd.cpd.impl.JavaccCpdLexer;
import net.sourceforge.pmd.lang.ast.impl.TokenDocument;
import net.sourceforge.pmd.lang.document.TextDocument;
@@ -18,7 +18,7 @@ import net.sourceforge.pmd.lang.document.TextDocument;
* Token document for Javacc implementations. This is a helper object
* for generated token managers. Note: the extension point is a custom
* implementation of {@link TokenDocumentBehavior}, see {@link JjtreeParserAdapter#tokenBehavior()},
- * {@link JavaCCTokenizer#tokenBehavior()}
+ * {@link JavaccCpdLexer#tokenBehavior()}
*/
public final class JavaccTokenDocument extends TokenDocument {
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileId.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileId.java
index 452ee2ae2e..98da0536da 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileId.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileId.java
@@ -11,8 +11,8 @@ import java.nio.file.Paths;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.renderers.Renderer;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* An identifier for a {@link TextFile}. This is not a path, but provides
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileLocation.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileLocation.java
index e42fe4e212..e9a6d89ab2 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileLocation.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileLocation.java
@@ -9,10 +9,10 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.ast.GenericToken;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.reporting.Reportable;
+import net.sourceforge.pmd.reporting.RuleViolation;
import net.sourceforge.pmd.util.AssertionUtil;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/CpdOnlyLanguageModuleBase.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/CpdOnlyLanguageModuleBase.java
index b66848e2ed..5da636b741 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/CpdOnlyLanguageModuleBase.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/CpdOnlyLanguageModuleBase.java
@@ -5,7 +5,7 @@
package net.sourceforge.pmd.lang.impl;
import net.sourceforge.pmd.cpd.CpdCapableLanguage;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguageModuleBase;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
@@ -27,5 +27,5 @@ public abstract class CpdOnlyLanguageModuleBase extends LanguageModuleBase imple
}
@Override
- public abstract Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle);
+ public abstract CpdLexer createCpdLexer(LanguagePropertyBundle bundle);
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MonoThreadProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MonoThreadProcessor.java
index fe26c289f6..8e629fb06d 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MonoThreadProcessor.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MonoThreadProcessor.java
@@ -4,9 +4,9 @@
package net.sourceforge.pmd.lang.impl;
-import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.lang.LanguageProcessor.AnalysisTask;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
/**
* @author Romain Pelisse <belaran@gmail.com>
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java
index db0feb12f4..138c6c3981 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java
@@ -12,9 +12,9 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.lang.LanguageProcessor.AnalysisTask;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.util.log.PmdReporter;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java
index 0944c73172..dfb7b042b7 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java
@@ -9,9 +9,6 @@ import static net.sourceforge.pmd.util.CollectionUtil.listOf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleSets;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
@@ -28,7 +25,10 @@ import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
import net.sourceforge.pmd.lang.ast.SemanticException;
import net.sourceforge.pmd.lang.document.TextDocument;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.internal.RuleSets;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* A processing task for a single file.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractDelegateRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractDelegateRule.java
index a780a65178..cf71429403 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractDelegateRule.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractDelegateRule.java
@@ -7,15 +7,13 @@ package net.sourceforge.pmd.lang.rule;
import java.util.List;
import java.util.Map;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RulePriority;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageProcessor;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertySource;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* Base class for Rule implementations which delegate to another Rule instance.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java
index 697a3fbcb9..a73a30a8d5 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java
@@ -15,16 +15,14 @@ import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;
-import net.sourceforge.pmd.InternalApiBridge;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RulePriority;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.RootNode;
import net.sourceforge.pmd.properties.AbstractPropertySource;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.InternalApiBridge;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* Basic abstract implementation of all parser-independent methods of the Rule
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractVisitorRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractVisitorRule.java
index 9ef6e4a472..f633fe66f5 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractVisitorRule.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractVisitorRule.java
@@ -4,9 +4,9 @@
package net.sourceforge.pmd.lang.rule;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.AstVisitor;
import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.reporting.RuleContext;
public abstract class AbstractVisitorRule extends AbstractRule {
@Override
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/Rule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/Rule.java
similarity index 98%
rename from pmd-core/src/main/java/net/sourceforge/pmd/Rule.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/Rule.java
index e6ceb8753e..6123fc07bd 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/Rule.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/Rule.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule;
import java.util.List;
import java.util.Optional;
@@ -12,10 +12,10 @@ import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageProcessor;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.ast.Node;
-import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
import net.sourceforge.pmd.properties.PropertySource;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* This is the basic Rule interface for PMD rules.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleFactory.java
similarity index 98%
rename from pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleFactory.java
index 14c491535d..23a4448936 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleFactory.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd.rules;
+package net.sourceforge.pmd.lang.rule;
import static net.sourceforge.pmd.util.internal.xml.SchemaConstants.CLASS;
import static net.sourceforge.pmd.util.internal.xml.SchemaConstants.DELIMITER;
@@ -41,14 +41,10 @@ import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RulePriority;
-import net.sourceforge.pmd.RuleSetReference;
-import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersion;
-import net.sourceforge.pmd.lang.rule.RuleReference;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReference;
import net.sourceforge.pmd.properties.ConstraintViolatedException;
import net.sourceforge.pmd.properties.NumericConstraints;
import net.sourceforge.pmd.properties.PropertyBuilder;
@@ -75,9 +71,7 @@ import com.github.oowekyala.ooxml.messages.XmlException;
* @author Clément Fournier
* @since 6.0.0
*/
-@InternalApi
-@Deprecated
-public class RuleFactory {
+class RuleFactory {
private final ResourceLoader resourceLoader;
private final LanguageRegistry languageRegistry;
@@ -85,7 +79,7 @@ public class RuleFactory {
/**
* @param resourceLoader The resource loader to load the rule from jar
*/
- public RuleFactory(ResourceLoader resourceLoader,
+ RuleFactory(ResourceLoader resourceLoader,
LanguageRegistry languageRegistry) {
this.resourceLoader = resourceLoader;
this.languageRegistry = languageRegistry;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RulePriority.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RulePriority.java
similarity index 98%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RulePriority.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RulePriority.java
index 8f8b97996b..2007fcf0aa 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RulePriority.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RulePriority.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule;
/**
* These are the possible Rule priority values.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleReference.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleReference.java
index 4572a31ce5..075f88fbf4 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleReference.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleReference.java
@@ -12,10 +12,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RulePriority;
-import net.sourceforge.pmd.RuleSetReference;
import net.sourceforge.pmd.lang.LanguageVersion;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReference;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.util.StringUtil;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSet.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSet.java
similarity index 99%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSet.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSet.java
index 86416a56f2..47cd37243c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSet.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSet.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule;
import java.util.ArrayList;
import java.util.Arrays;
@@ -26,8 +26,8 @@ import net.sourceforge.pmd.internal.util.PredicateUtil;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextFile;
-import net.sourceforge.pmd.lang.rule.RuleReference;
-import net.sourceforge.pmd.lang.rule.XPathRule;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReference;
+import net.sourceforge.pmd.lang.rule.xpath.XPathRule;
/**
* This class represents a collection of rules along with some optional filter
@@ -626,7 +626,8 @@ public class RuleSet implements ChecksumAware {
* @return true if the file should be checked,
* false otherwise
*/
- boolean applies(TextFile file) {
+ @InternalApi
+ public boolean applies(TextFile file) {
return applies(file.getFileId());
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetFactory.java
similarity index 96%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetFactory.java
index 4d8d954461..e86d1836b4 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetFactory.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule;
import static net.sourceforge.pmd.util.CollectionUtil.setOf;
import static net.sourceforge.pmd.util.internal.xml.SchemaConstants.DESCRIPTION;
@@ -45,10 +45,11 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
-import net.sourceforge.pmd.RuleSet.RuleSetBuilder;
+import net.sourceforge.pmd.PMDVersion;
import net.sourceforge.pmd.lang.LanguageRegistry;
-import net.sourceforge.pmd.lang.rule.RuleReference;
-import net.sourceforge.pmd.rules.RuleFactory;
+import net.sourceforge.pmd.lang.rule.RuleSet.RuleSetBuilder;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReference;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId;
import net.sourceforge.pmd.util.StringUtil;
import net.sourceforge.pmd.util.internal.ResourceLoader;
import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter;
@@ -80,7 +81,6 @@ final class RuleSetFactory {
private final LanguageRegistry languageRegistry;
private final RulePriority minimumPriority;
private final boolean warnDeprecated;
- private final RuleSetFactoryCompatibility compatibilityFilter;
private final PmdReporter reporter;
private final boolean includeDeprecatedRuleReferences;
@@ -90,7 +90,6 @@ final class RuleSetFactory {
LanguageRegistry languageRegistry,
RulePriority minimumPriority,
boolean warnDeprecated,
- RuleSetFactoryCompatibility compatFilter,
boolean includeDeprecatedRuleReferences,
PmdReporter reporter) {
this.resourceLoader = resourceLoader;
@@ -99,7 +98,6 @@ final class RuleSetFactory {
this.warnDeprecated = warnDeprecated;
this.includeDeprecatedRuleReferences = includeDeprecatedRuleReferences;
- this.compatibilityFilter = compatFilter;
this.reporter = reporter;
}
@@ -165,9 +163,9 @@ final class RuleSetFactory {
private @NonNull RuleSet readDocument(RuleSetReferenceId ruleSetReferenceId, boolean withDeprecatedRuleReferences) {
try (CheckedInputStream inputStream = new CheckedInputStream(ruleSetReferenceId.getInputStream(resourceLoader), new Adler32())) {
- if (!ruleSetReferenceId.isExternal()) {
+ if (!ruleSetReferenceId.isAbsolute()) {
throw new IllegalArgumentException(
- "Cannot parse a RuleSet from a non-external reference: <" + ruleSetReferenceId + ">.");
+ "Cannot parse a RuleSet from a non-absolute reference: <" + ruleSetReferenceId + ">.");
}
XmlMessageHandler printer = getXmlMessagePrinter();
@@ -374,7 +372,6 @@ final class RuleSetFactory {
// has been reported
continue;
}
- excludedRuleName = compatibilityFilter.applyExclude(ref, excludedRuleName, this.warnDeprecated);
if (excludedRuleName != null) {
excludedRulesCheck.put(excludedRuleName, child);
}
@@ -441,15 +438,12 @@ final class RuleSetFactory {
private RuleSetReferenceId parseReferenceAndWarn(String ref,
Node xmlPlace,
PmdXmlReporter err) {
- ref = compatibilityFilter.applyRef(ref, this.warnDeprecated);
if (ref == null) {
err.at(xmlPlace).warn("Rule reference references a deleted rule, ignoring");
return null; // deleted rule
}
// only emit a warning if we check for deprecated syntax
- PmdReporter subReporter = warnDeprecated ? err.at(xmlPlace) : PmdReporter.quiet();
-
- List references = RuleSetReferenceId.parse(ref, subReporter);
+ List references = RuleSetReferenceId.parse(ref);
if (references.size() > 1 && warnDeprecated) {
err.at(xmlPlace).warn("Using a comma separated list as a ref attribute is deprecated. "
+ "All references but the first are ignored.");
@@ -527,13 +521,13 @@ final class RuleSetFactory {
RuleSetFactory ruleSetFactory = toLoader().filterAbovePriority(RulePriority.LOW).warnDeprecated(false).toFactory();
boolean isSameRuleSet = false;
- if (!otherRuleSetReferenceId.isExternal()
+ if (!otherRuleSetReferenceId.isAbsolute()
&& containsRule(ruleSetReferenceId, otherRuleSetReferenceId.getRuleName())) {
- otherRuleSetReferenceId = new RuleSetReferenceId(ref, ruleSetReferenceId, err.at(REF.getAttributeNode(ruleNode)));
+ otherRuleSetReferenceId = new RuleSetReferenceId(ref, ruleSetReferenceId);
isSameRuleSet = true;
- } else if (otherRuleSetReferenceId.isExternal()
+ } else if (otherRuleSetReferenceId.isAbsolute()
&& otherRuleSetReferenceId.getRuleSetFileName().equals(ruleSetReferenceId.getRuleSetFileName())) {
- otherRuleSetReferenceId = new RuleSetReferenceId(otherRuleSetReferenceId.getRuleName(), ruleSetReferenceId, err.at(REF.getAttributeNode(ruleNode)));
+ otherRuleSetReferenceId = new RuleSetReferenceId(otherRuleSetReferenceId.getRuleName(), ruleSetReferenceId);
isSameRuleSet = true;
}
// do not ignore deprecated rule references
@@ -664,7 +658,6 @@ final class RuleSetFactory {
return new RuleSetLoader().loadResourcesWith(resourceLoader)
.filterAbovePriority(minimumPriority)
.warnDeprecated(warnDeprecated)
- .enableCompatibility(compatibilityFilter != null)
.includeDeprecatedRuleReferences(includeDeprecatedRuleReferences);
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoadException.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java
similarity index 84%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoadException.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java
index b83355e1c6..c87ba35118 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoadException.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java
@@ -2,11 +2,12 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule;
import org.checkerframework.checker.nullness.qual.NonNull;
import net.sourceforge.pmd.annotation.InternalApi;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId;
/**
* An exception that is thrown when something wrong occurs while
@@ -14,7 +15,7 @@ import net.sourceforge.pmd.annotation.InternalApi;
* XML is not well-formed, does not respect the ruleset schema, is
* not a valid ruleset or is otherwise unparsable.
*/
-public final class RuleSetLoadException extends RuntimeException {
+public class RuleSetLoadException extends RuntimeException {
/** Constructors are internal. */
@InternalApi
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java
similarity index 87%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java
index 2e9ae672fd..0fa046c824 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -17,13 +17,14 @@ import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
-import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId;
import net.sourceforge.pmd.util.CollectionUtil;
import net.sourceforge.pmd.util.internal.ResourceLoader;
import net.sourceforge.pmd.util.log.PmdReporter;
@@ -41,7 +42,6 @@ public final class RuleSetLoader {
private ResourceLoader resourceLoader = new ResourceLoader(RuleSetLoader.class.getClassLoader());
private RulePriority minimumPriority = RulePriority.LOW;
private boolean warnDeprecated = true;
- private @NonNull RuleSetFactoryCompatibility compatFilter = RuleSetFactoryCompatibility.DEFAULT;
private boolean includeDeprecatedRuleReferences = false;
private @NonNull PmdReporter reporter = PmdReporter.quiet();
@@ -102,29 +102,9 @@ public final class RuleSetLoader {
return this;
}
- /**
- * Enable translating old rule references to newer ones, if they have
- * been moved or renamed. This is enabled by default, if disabled,
- * unresolved references will not be translated and will produce an
- * error.
- *
- * @return This instance, modified
- */
- public RuleSetLoader enableCompatibility(boolean enable) {
- return setCompatibility(enable ? RuleSetFactoryCompatibility.DEFAULT
- : RuleSetFactoryCompatibility.EMPTY);
- }
-
- // test only
- RuleSetLoader setCompatibility(@NonNull RuleSetFactoryCompatibility filter) {
- this.compatFilter = filter;
- return this;
- }
-
/**
* Follow deprecated rule references. By default this is off,
- * and those references will be ignored (with a warning depending
- * on {@link #enableCompatibility(boolean)}).
+ * and those references will be ignored.
*
* @return This instance, modified
*/
@@ -147,16 +127,11 @@ public final class RuleSetLoader {
this.languageRegistry,
this.minimumPriority,
this.warnDeprecated,
- this.compatFilter,
this.includeDeprecatedRuleReferences,
this.reporter
);
}
- private @Nullable PmdReporter filteredReporter() {
- return warnDeprecated ? reporter : null;
- }
-
/**
* Parses and returns a ruleset from its location. The location may
* be a file system path, or a resource path (see {@link #loadResourcesWith(ClassLoader)}).
@@ -166,7 +141,7 @@ public final class RuleSetLoader {
* @throws RuleSetLoadException If any error occurs (eg, invalid syntax, or resource not found)
*/
public RuleSet loadFromResource(String rulesetPath) {
- return loadFromResource(new RuleSetReferenceId(rulesetPath, null, filteredReporter()));
+ return loadFromResource(new RuleSetReferenceId(rulesetPath, null));
}
/**
@@ -178,12 +153,25 @@ public final class RuleSetLoader {
* @throws RuleSetLoadException If any error occurs (eg, invalid syntax)
*/
public RuleSet loadFromString(String filename, final String rulesetXmlContent) {
- return loadFromResource(new RuleSetReferenceId(filename, null, filteredReporter()) {
- @Override
- public InputStream getInputStream(ResourceLoader rl) {
- return new ByteArrayInputStream(rulesetXmlContent.getBytes(StandardCharsets.UTF_8));
- }
- });
+ if (filename == null || filename.isEmpty()) {
+ throw new IllegalArgumentException("Invalid empty filename");
+ }
+
+ ResourceLoader oldLoader = this.resourceLoader;
+ try {
+ loadResourcesWith(new ResourceLoader() {
+ @Override
+ public @NonNull InputStream loadResourceAsStream(String name) throws IOException {
+ if (Objects.equals(name, filename)) {
+ return new ByteArrayInputStream(rulesetXmlContent.getBytes(StandardCharsets.UTF_8));
+ }
+ return oldLoader.loadResourceAsStream(name);
+ }
+ });
+ return loadFromResource(new RuleSetReferenceId(filename, null));
+ } finally {
+ loadResourcesWith(oldLoader);
+ }
}
/**
@@ -278,7 +266,6 @@ public final class RuleSetLoader {
*/
public static RuleSetLoader fromPmdConfig(PMDConfiguration configuration) {
return new RuleSetLoader().filterAbovePriority(configuration.getMinimumPriority())
- .enableCompatibility(configuration.isRuleSetFactoryCompatibilityEnabled())
.withLanguages(configuration.getLanguageRegistry())
.withReporter(configuration.getReporter());
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetWriter.java
similarity index 99%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetWriter.java
index 6bf03db1a0..66fedc4333 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetWriter.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule;
import java.io.OutputStream;
import java.util.HashSet;
@@ -34,7 +34,7 @@ import org.w3c.dom.Text;
import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageVersion;
-import net.sourceforge.pmd.lang.rule.RuleReference;
+import net.sourceforge.pmd.lang.rule.internal.RuleSetReference;
import net.sourceforge.pmd.properties.PropertyConstraint;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertySerializer;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java
index 8c4151942b..0fabbdc1c0 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java
@@ -12,7 +12,6 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
-import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.RootNode;
import net.sourceforge.pmd.lang.rule.internal.TargetSelectorInternal;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java
index 65e27670a9..e61d28ebff 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java
@@ -11,11 +11,6 @@ import org.apache.commons.lang3.exception.ExceptionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.InternalApiBridge;
-import net.sourceforge.pmd.Report.ProcessingError;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
@@ -23,7 +18,12 @@ import net.sourceforge.pmd.internal.SystemProps;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.RootNode;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.RuleSet;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
+import net.sourceforge.pmd.reporting.InternalApiBridge;
+import net.sourceforge.pmd.reporting.Report.ProcessingError;
+import net.sourceforge.pmd.reporting.RuleContext;
import net.sourceforge.pmd.util.AssertionUtil;
import net.sourceforge.pmd.util.StringUtil;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReference.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSetReference.java
similarity index 86%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReference.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSetReference.java
index cdc6e5f77c..89590dd04a 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReference.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSetReference.java
@@ -2,21 +2,19 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule.internal;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
-import net.sourceforge.pmd.annotation.InternalApi;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
/**
* This class represents a reference to RuleSet.
*
- * @deprecated This is part of the internals of the {@link RuleSetLoader}.
+ *
Note: This is part of the internals of the {@link RuleSetLoader}.
*/
-@Deprecated
-@InternalApi
public class RuleSetReference {
private final String ruleSetFileName;
private final boolean allRules;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSetReferenceId.java
new file mode 100644
index 0000000000..c2666a4e13
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSetReferenceId.java
@@ -0,0 +1,342 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule.internal;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.commons.lang3.StringUtils;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
+import net.sourceforge.pmd.util.internal.ResourceLoader;
+
+/**
+ * This class is used to reference either a complete ruleset with all rules or to reference a single rule
+ * within a rule set.
+ *
+ *
A {@link RuleSetReferenceId} is said to be "absolute" if it knows about the ruleset it references.
+ * It is "relative", if only the name of the referenced rule is known. In that case, the {@link RuleSetReferenceId}
+ * needs to be paired with an absolute reference.
+ *
+ *
This class can parse reference values from string. Most commonly used for
+ * specifying a RuleSet to process, or in a Rule 'ref' attribute value in the
+ * RuleSet XML. The RuleSet reference can refer to either a specific RuleSet file or
+ * the current RuleSet when used as a Rule 'ref' attribute value. An individual
+ * Rule in the RuleSet can be selected.
+ *
+ *
For referring an entire RuleSet, the format is
+ * ruleSetName, where the ruleSetName is a resource file path, a classpath or a URL
+ * that ends with '.xml'.
+ *
+ *
Referring to a single Rule, the format is
+ * ruleSetName/ruleName, where the ruleSetName is as described above. A
+ * Rule with the ruleName should exist in the referenced RuleSet.
+ *
+ *
For the current RuleSet, the format is ruleName, where the Rule name
+ * is not RuleSet name (i.e. contains no path separators or '.xml' in it).
+ * A Rule with the ruleName should exist in the current RuleSet.
+ *
+ *
Note: When specifying a URL, the URL won't be checked until the ruleset is actually loaded. This might result
+ * in ambiguity in the following cases: if "https://example.org/ruleset/MyRule" will be interpreted as reference
+ * to a rulesets and all rules are referenced. To avoid this ambiguity, rulesets should always use the extension ".xml",
+ * e.g. "https://example.org/ruleset.xml/MyRule".
+ *
+ *
Note: This is part of the internals of the {@link RuleSetLoader}.
+ */
+public class RuleSetReferenceId {
+
+ // might be a file path, classpath or URI. Can be null.
+ private final @Nullable String ruleSetReference;
+ // referenced rule within the ruleSet. Can be null.
+ private final @Nullable String ruleName;
+
+ private final @NonNull String originalRef;
+
+
+ // Helper constructor, that does not parse the ruleSetReference string
+ private RuleSetReferenceId(final String ruleSetReference, final String ruleName) {
+ this.ruleSetReference = ruleSetReference;
+ this.ruleName = ruleName;
+ this.originalRef = ruleSetReference;
+ }
+
+ /**
+ * Construct a RuleSetReferenceId for the given single reference string.
+ *
+ * @param reference
+ * The reference string.
+ * @throws IllegalArgumentException
+ * If the ID contains a comma character.
+ */
+ public RuleSetReferenceId(final String reference) {
+ this(reference, (RuleSetReferenceId) null);
+ }
+
+ /**
+ * Construct a RuleSetReferenceId for the given single ID string. If an
+ * absolute RuleSetReferenceId is given, the ID must refer to a simple
+ * Rule. The rule will be resolved within the given absolute RuleSetReference.
+ *
+ * @param id The id string.
+ * @param absoluteRuleSetReferenceId A RuleSetReferenceId to associate with this new instance.
+ *
+ * @throws IllegalArgumentException If the ID contains a comma character.
+ * @throws IllegalArgumentException If absolute RuleSetReferenceId is not absolute.
+ * @throws IllegalArgumentException If the ID is not Rule reference when there is an absoluteRuleSetReferenceId
+ */
+ public RuleSetReferenceId(final String id, final RuleSetReferenceId absoluteRuleSetReferenceId) {
+ this.originalRef = StringUtils.trim(id);
+
+ if (originalRef != null && originalRef.indexOf(',') >= 0) {
+ throw new IllegalArgumentException(
+ "A single RuleSetReferenceId cannot contain ',' (comma) characters: " + id);
+ }
+ if (absoluteRuleSetReferenceId != null && !absoluteRuleSetReferenceId.isAbsolute()) {
+ throw new IllegalArgumentException("Cannot pair with relative <" + absoluteRuleSetReferenceId + ">.");
+ }
+ if (isFullRuleSetName(originalRef) && absoluteRuleSetReferenceId != null) {
+ throw new IllegalArgumentException(
+ "Cannot pair absolute <" + originalRef + "> with absolute <" + absoluteRuleSetReferenceId + ">.");
+ }
+ if (originalRef == null && absoluteRuleSetReferenceId == null) {
+ throw new IllegalArgumentException("Either ID or absoluteRuleSetReferenceId is required");
+ }
+
+ // try to split originalRef into ruleset and rule
+ String tempRuleName = getRuleName(originalRef);
+ String tempRuleSetReference = tempRuleName == null
+ ? null
+ : originalRef.substring(0, originalRef.length() - tempRuleName.length() - 1);
+ if (isFullRuleSetName(tempRuleSetReference) && absoluteRuleSetReferenceId != null) {
+ throw new IllegalArgumentException(
+ "Cannot pair absolute <" + originalRef + "> with absolute <" + absoluteRuleSetReferenceId + ">.");
+ }
+
+ if (absoluteRuleSetReferenceId != null && absoluteRuleSetReferenceId.isAbsolute()) {
+ // referencing a rule within another ruleset
+ ruleSetReference = absoluteRuleSetReferenceId.getRuleSetFileName();
+ ruleName = originalRef;
+ } else if (isFullRuleSetName(originalRef)) {
+ // A full RuleSet name - ends with .xml
+ ruleSetReference = originalRef;
+ ruleName = null;
+ } else {
+ if (isFullRuleSetName(tempRuleSetReference)) {
+ // only interpret last part as rule name, if the remaining part is a full ruleset name (ending in .xml)
+ ruleSetReference = tempRuleSetReference;
+ ruleName = tempRuleName;
+ } else if (originalRef.indexOf('/') == -1 && originalRef.indexOf('\\') == -1) {
+ // it's a simple name, assume we only reference a rule name here
+ ruleSetReference = null;
+ ruleName = originalRef;
+ } else {
+ // in any other case, the name is more complex, likely a URI or something
+ // assuming a complete ruleset reference
+ ruleSetReference = originalRef;
+ ruleName = null;
+ }
+ }
+ }
+
+ public @Nullable RuleSetReferenceId getParentRulesetIfThisIsARule() {
+ if (ruleName == null) {
+ return null;
+ }
+ return new RuleSetReferenceId(ruleSetReference, (String) null);
+ }
+
+
+ /**
+ * Extracts the rule name out of a ruleset path. E.g. for
+ * "/my/ruleset.xml/MyRule" it would return "MyRule". If no single rule is
+ * specified (in other words: no separated last path name part), {@code null} is returned.
+ *
+ * @param rulesetName
+ * the full rule set path
+ * @return the rule name or null.
+ */
+ private String getRuleName(final String rulesetName) {
+ String result = null;
+ if (rulesetName != null) {
+ // Find last path separator if it exists... this might be a rule
+ // name
+ final int separatorIndex = Math.max(rulesetName.lastIndexOf('/'), rulesetName.lastIndexOf('\\'));
+ if (separatorIndex >= 0 && separatorIndex != rulesetName.length() - 1) {
+ result = rulesetName.substring(separatorIndex + 1);
+ }
+ }
+ return result;
+ }
+
+ private static boolean isFullRuleSetName(String name) {
+ return name != null && name.toLowerCase(Locale.ROOT).endsWith(".xml");
+ }
+
+ /**
+ * Parse a String comma separated list of RuleSet reference IDs into a List
+ * of RuleReferenceId instances.
+ *
+ * @param referenceString A comma separated list of RuleSet reference IDs.
+ *
+ * @return The corresponding List of RuleSetReferenceId instances.
+ */
+ // TODO deprecate and remove
+ public static List parse(String referenceString) {
+ List references = new ArrayList<>();
+ if (referenceString != null && referenceString.trim().length() > 0) {
+
+ if (referenceString.indexOf(',') == -1) {
+ references.add(new RuleSetReferenceId(referenceString));
+ } else {
+ for (String name : referenceString.split(",")) {
+ references.add(new RuleSetReferenceId(name.trim()));
+ }
+ }
+ }
+ return references;
+ }
+
+ /**
+ * Does this {@link RuleSetReferenceId} contain a reference to a ruleset. That means, it either
+ * references all rules with the ruleset or a specific rule. But in any case, the ruleset is known.
+ *
+ * @return {@code true} if the ruleset is known, {@code false} when only the rule name is known.
+ */
+ public boolean isAbsolute() {
+ return ruleSetReference != null;
+ }
+
+ /**
+ * Is this a reference to all Rules in a RuleSet, or a single Rule?
+ *
+ * @return true if this is a reference to all Rules,
+ * false otherwise.
+ */
+ public boolean isAllRules() {
+ return ruleName == null;
+ }
+
+ /**
+ * Get the RuleSet file name.
+ *
+ * @return The RuleSet file name if this is an absolute reference,
+ * null otherwise.
+ */
+ public String getRuleSetFileName() {
+ return ruleSetReference;
+ }
+
+ /**
+ * Get the Rule name.
+ *
+ * @return The Rule name. The Rule name.
+ */
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ /**
+ * Try to load the RuleSet resource with the specified ResourceLoader. Multiple
+ * attempts to get independent InputStream instances may be made, so
+ * subclasses must ensure they support this behavior.
+ *
+ * @param rl The {@link ResourceLoader} to use.
+ * @return An InputStream to that resource.
+ */
+ public InputStream getInputStream(final ResourceLoader rl) throws IOException {
+ if (!isAbsolute()) {
+ throw new IllegalArgumentException("Cannot resolve rule/ruleset reference '" + this + "' - reference is not absolute");
+ }
+ try {
+ return rl.loadResourceAsStream(ruleSetReference);
+ } catch (FileNotFoundException ignored) {
+ throw notFoundException();
+ }
+ }
+
+ private FileNotFoundException notFoundException() {
+ return new FileNotFoundException("Cannot resolve rule/ruleset reference '" + originalRef
+ + "'" + ". Make sure the resource is a valid file or URL and is on the CLASSPATH. "
+ + "Use --debug (or a fine log level) to see the current classpath.");
+ }
+
+ /**
+ * Return the String form of this Rule reference.
+ *
+ * @return Return the String form of this Rule reference, which is
+ * ruleSetFileName for all Rule absolute references,
+ * ruleSetFileName/ruleName, for a single Rule absolute
+ * references, or ruleName otherwise.
+ */
+ public String toNormalizedReference() {
+ if (isAbsolute()) {
+ if (isAllRules()) {
+ return ruleSetReference;
+ } else {
+ return ruleSetReference + '/' + ruleName;
+ }
+ } else {
+ return ruleName;
+ }
+ }
+
+ /**
+ * String representation of this reference. Do not rely on the format of this method,
+ * instead use {@link #toNormalizedReference()}.
+ */
+ @Override
+ public String toString() {
+ return toNormalizedReference();
+ }
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSets.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java
similarity index 97%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleSets.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java
index 178e424cf1..7d05afd410 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSets.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.lang.rule.internal;
import java.util.ArrayList;
import java.util.Collection;
@@ -12,14 +12,14 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.benchmark.TimeTracker;
import net.sourceforge.pmd.benchmark.TimedOperation;
import net.sourceforge.pmd.benchmark.TimedOperationCategory;
import net.sourceforge.pmd.lang.LanguageProcessorRegistry;
import net.sourceforge.pmd.lang.ast.RootNode;
import net.sourceforge.pmd.lang.document.TextFile;
-import net.sourceforge.pmd.lang.rule.internal.RuleApplicator;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.RuleSet;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.util.log.PmdReporter;
@@ -27,11 +27,7 @@ import net.sourceforge.pmd.util.log.PmdReporter;
* Grouping of Rules per Language in a RuleSet.
*
* @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
- *
- * @deprecated Internal API
*/
-@Deprecated
-@InternalApi
public class RuleSets {
private final List ruleSets;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/package-info.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/package-info.java
new file mode 100644
index 0000000000..a802199683
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/package-info.java
@@ -0,0 +1,9 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+/**
+ * Contains {@link net.sourceforge.pmd.lang.rule.Rule} and {@link net.sourceforge.pmd.lang.rule.RuleSet}
+ * related classes.
+ */
+package net.sourceforge.pmd.lang.rule;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/CommentNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/CommentNode.java
new file mode 100644
index 0000000000..7d700481ed
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/CommentNode.java
@@ -0,0 +1,17 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule.xpath;
+
+import net.sourceforge.pmd.lang.ast.Node;
+
+public interface CommentNode extends Node {
+
+ String getData();
+
+ @Override
+ default String getXPathNodeName() {
+ return "#comment";
+ }
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/TextNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/TextNode.java
new file mode 100644
index 0000000000..00d2b5e6c1
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/TextNode.java
@@ -0,0 +1,16 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule.xpath;
+
+import net.sourceforge.pmd.lang.ast.Node;
+
+public interface TextNode extends Node {
+ String getText();
+
+ @Override
+ default String getXPathNodeName() {
+ return "#text";
+ }
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java
similarity index 71%
rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java
index e5cc2ea252..d9b021501b 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java
@@ -2,12 +2,9 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd.lang.rule;
+package net.sourceforge.pmd.lang.rule.xpath;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
@@ -16,17 +13,16 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.LanguageProcessor;
import net.sourceforge.pmd.lang.ast.Node;
-import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException;
-import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
+import net.sourceforge.pmd.lang.rule.AbstractRule;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
import net.sourceforge.pmd.lang.rule.xpath.internal.DeprecatedAttrLogger;
import net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
@@ -36,8 +32,6 @@ public final class XPathRule extends AbstractRule {
private static final Logger LOG = LoggerFactory.getLogger(XPathRule.class);
- // TODO move to XPath subpackage
-
/**
* @deprecated Use {@link #XPathRule(XPathVersion, String)}
*/
@@ -48,17 +42,6 @@ public final class XPathRule extends AbstractRule {
.defaultValue("")
.build();
- /**
- * @deprecated Use {@link #XPathRule(XPathVersion, String)}
- */
- @Deprecated
- @DeprecatedUntil700
- public static final PropertyDescriptor VERSION_DESCRIPTOR =
- PropertyFactory.enumProperty("version", getXPathVersions())
- .desc("XPath specification version")
- .defaultValue(XPathVersion.DEFAULT)
- .build();
-
/**
* This is initialized only once when calling {@link #apply(Node, RuleContext)} or {@link #getTargetSelector()}.
*/
@@ -77,7 +60,6 @@ public final class XPathRule extends AbstractRule {
@Deprecated
public XPathRule() {
definePropertyDescriptor(XPATH_DESCRIPTOR);
- definePropertyDescriptor(VERSION_DESCRIPTOR);
}
/**
@@ -95,7 +77,6 @@ public final class XPathRule extends AbstractRule {
Objects.requireNonNull(expression, "XPath expression is null");
setProperty(XPathRule.XPATH_DESCRIPTOR, expression);
- setProperty(XPathRule.VERSION_DESCRIPTOR, XPathVersion.ofId(version.getXmlName()));
}
@@ -106,14 +87,6 @@ public final class XPathRule extends AbstractRule {
return rule;
}
- /**
- * Returns the version for this rule. Returns null if this is not
- * set or invalid.
- */
- public XPathVersion getVersion() {
- return getProperty(VERSION_DESCRIPTOR);
- }
-
/**
* Returns the XPath expression that implements this rule.
*/
@@ -145,11 +118,7 @@ public final class XPathRule extends AbstractRule {
@Override
public void initialize(LanguageProcessor languageProcessor) {
String xpath = getXPathExpression();
- XPathVersion version = getVersion();
-
- if (version == null) {
- throw new IllegalStateException("Invalid XPath version, should have been caught by Rule::dysfunctionReason");
- }
+ XPathVersion version = XPathVersion.DEFAULT;
try {
xpathRuleQuery = new SaxonXPathRuleQuery(xpath,
@@ -183,9 +152,8 @@ public final class XPathRule extends AbstractRule {
private void logXPathRuleChainUsage(boolean usesRuleChain) {
- LOG.debug("{} rule chain for XPath {} rule: {} ({})",
+ LOG.debug("{} rule chain for XPath rule: {} ({})",
usesRuleChain ? "Using" : "no",
- getProperty(XPathRule.VERSION_DESCRIPTOR),
getName(),
getRuleSetName());
}
@@ -193,19 +161,9 @@ public final class XPathRule extends AbstractRule {
@Override
public String dysfunctionReason() {
- if (getVersion() == null) {
- return "Invalid XPath version '" + getProperty(VERSION_DESCRIPTOR) + "'";
- } else if (StringUtils.isBlank(getXPathExpression())) {
+ if (StringUtils.isBlank(getXPathExpression())) {
return "Missing XPath expression";
}
return null;
}
-
- private static Map getXPathVersions() {
- Map tmp = new HashMap<>();
- for (XPathVersion v : XPathVersion.values()) {
- tmp.put(v.getXmlName(), v);
- }
- return Collections.unmodifiableMap(tmp);
- }
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/AbstractXPathFunctionDef.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/AbstractXPathFunctionDef.java
deleted file mode 100644
index 8963a9071b..0000000000
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/AbstractXPathFunctionDef.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
- */
-
-package net.sourceforge.pmd.lang.rule.xpath.impl;
-
-import net.sourceforge.pmd.lang.Language;
-
-import net.sf.saxon.lib.ExtensionFunctionDefinition;
-import net.sf.saxon.om.StructuredQName;
-
-
-/**
- * Base impl for an XPath function definition.
- * This uses Saxon API.
- *
- * @since 7.0.0
- */
-public abstract class AbstractXPathFunctionDef extends ExtensionFunctionDefinition {
-
- private static final String PMD_URI_PREFIX = "http://pmd.sourceforge.net/";
- private final StructuredQName qname;
-
- private AbstractXPathFunctionDef(String localName, String namespacePrefix, String uri) {
- this.qname = new StructuredQName(namespacePrefix, uri, localName);
- }
-
- protected AbstractXPathFunctionDef(String localName) {
- this(localName, "pmd", PMD_URI_PREFIX + "pmd-core");
- }
-
- protected AbstractXPathFunctionDef(String localName, Language language) {
- this(localName, "pmd-" + language.getId(), PMD_URI_PREFIX + "pmd-" + language.getId());
- }
-
- @Override
- public final StructuredQName getFunctionQName() {
- return qname;
- }
-}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathFunctionDefinition.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathFunctionDefinition.java
new file mode 100644
index 0000000000..a684f835bc
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathFunctionDefinition.java
@@ -0,0 +1,126 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule.xpath.impl;
+
+import javax.xml.namespace.QName;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import net.sourceforge.pmd.lang.Language;
+import net.sourceforge.pmd.lang.ast.Node;
+
+/**
+ * Base impl for an XPath function definition.
+ *
+ * @since 7.0.0
+ */
+public abstract class XPathFunctionDefinition {
+
+ private static final String PMD_URI_PREFIX = "http://pmd.sourceforge.net/";
+ private final QName qname;
+
+ private XPathFunctionDefinition(String localName, String namespacePrefix, String uri) {
+ this.qname = new QName(uri, localName, namespacePrefix);
+ }
+
+ protected XPathFunctionDefinition(String localName) {
+ this(localName, "pmd", PMD_URI_PREFIX + "pmd-core");
+ }
+
+ protected XPathFunctionDefinition(String localName, Language language) {
+ this(localName, "pmd-" + language.getId(), PMD_URI_PREFIX + "pmd-" + language.getId());
+ }
+
+ public final QName getQName() {
+ return qname;
+ }
+
+ /**
+ * Defines the types of the function arguments. By default, an empty array is returned, indicating
+ * that the function takes no arguments.
+ */
+ public Type[] getArgumentTypes() {
+ return new Type[0];
+ }
+
+ /**
+ * Defines the return type of the function.
+ */
+ public abstract Type getResultType();
+
+ /**
+ * If the function depends on the context item, then
+ * this method should return {@code true}.
+ *
+ *
Note: Only if this is true, the contextNode parameter will be present in the
+ * {@link FunctionCall#call(Node, Object[])} method.
+ */
+ public boolean dependsOnContext() {
+ return false;
+ }
+
+ /**
+ * Create a call on this function. This method is called, when a function call
+ * is found in the XPath expression.
+ */
+ public abstract FunctionCall makeCallExpression();
+
+ /**
+ * Supported types of a custom XPath function. These can be used as {@link #getResultType() result types}
+ * or {@link #getArgumentTypes() argument types}.
+ */
+ public enum Type {
+ /** Represents {@link String}. */
+ SINGLE_STRING,
+ /** Represents {@link Boolean}. */
+ SINGLE_BOOLEAN,
+ /** Represents {@link Integer}. */
+ SINGLE_INTEGER,
+ /** Represents any node. Usually used as an argument type. */
+ SINGLE_ELEMENT,
+ /** Represents a {@link java.util.List} of {@link String}, potentially empty. */
+ STRING_SEQUENCE,
+ /** Represents a {@link java.util.Optional} {@link String}. */
+ OPTIONAL_STRING,
+ /** Represents a {@link java.util.Optional} {@link Double}. */
+ OPTIONAL_DECIMAL,
+ }
+
+ /**
+ * Provides the actual implementation of a custom XPath function.
+ */
+ public interface FunctionCall {
+ /**
+ * This method is called at runtime to evaluate the XPath function expression.
+ *
+ * @param contextNode the context node or {@code null}, if this function doesn't depend on the context.
+ * See {@link XPathFunctionDefinition#dependsOnContext()}.
+ * @param arguments The arguments converted as the corresponding java types.
+ * See {@link XPathFunctionDefinition#getArgumentTypes()}.
+ * @return The result of the function. This should be the corresponding java type of
+ * {@link XPathFunctionDefinition#getResultType()}.
+ * @throws XPathFunctionException when any problem during evaluation occurs, like invalid arguments.
+ */
+ Object call(@Nullable Node contextNode, Object[] arguments) throws XPathFunctionException;
+
+ /**
+ * This is called once before the function is evaluated. It can be used to optimize the
+ * implementation by doing expensive operations only once and cache the result.
+ * This is useful, if the argument of the function is of type {@link String} and is provided
+ * as a String literal in the XPath expression.
+ *
+ *
This is an optional step. The default implementation does nothing.
+ *
+ * @param arguments The arguments converted as the corresponding java types.
+ * See {@link XPathFunctionDefinition#getArgumentTypes()}.
+ * Note: This array might contain {@code null} elements, if the values are
+ * not known yet because they are dynamic. Only literal values are available.
+ * @throws XPathFunctionException when any problem during initialization occurs, like invalid arguments.
+ */
+ default void staticInit(Object[] arguments) throws XPathFunctionException {
+ // default implementation does nothing
+ }
+ }
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathFunctionException.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathFunctionException.java
new file mode 100644
index 0000000000..11704594af
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathFunctionException.java
@@ -0,0 +1,19 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule.xpath.impl;
+
+/**
+ * Indicates a problem during the execution of a custom
+ * XPath function.
+ */
+public class XPathFunctionException extends Exception {
+ public XPathFunctionException(String message) {
+ super(message);
+ }
+
+ public XPathFunctionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathHandler.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathHandler.java
index 0ef25b7884..73af54e17d 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathHandler.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/XPathHandler.java
@@ -11,8 +11,6 @@ import java.util.Set;
import net.sourceforge.pmd.lang.rule.xpath.internal.DefaultXPathFunctions;
import net.sourceforge.pmd.util.CollectionUtil;
-import net.sf.saxon.lib.ExtensionFunctionDefinition;
-
/**
* Interface for performing Language specific XPath handling, such as
@@ -24,7 +22,7 @@ public interface XPathHandler {
* Returns the set of extension functions for this language module.
* These are the additional functions available in XPath queries.
*/
- Set getRegisteredExtensionFunctions();
+ Set getRegisteredExtensionFunctions();
static XPathHandler noFunctionDefinitions() {
@@ -34,8 +32,8 @@ public interface XPathHandler {
/**
* Returns a default XPath handler.
*/
- static XPathHandler getHandlerForFunctionDefs(ExtensionFunctionDefinition first, ExtensionFunctionDefinition... defs) {
- Set set = new HashSet<>(CollectionUtil.setOf(first, defs));
+ static XPathHandler getHandlerForFunctionDefs(XPathFunctionDefinition first, XPathFunctionDefinition... defs) {
+ Set set = new HashSet<>(CollectionUtil.setOf(first, defs));
set.addAll(DefaultXPathFunctions.getDefaultFunctions());
return () -> Collections.unmodifiableSet(set);
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/AstElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/AstElementNode.java
index c97f6c754d..230f96e32e 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/AstElementNode.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/AstElementNode.java
@@ -11,6 +11,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.mutable.MutableInt;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -18,6 +19,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.RootNode;
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
+import net.sourceforge.pmd.lang.rule.xpath.CommentNode;
+import net.sourceforge.pmd.lang.rule.xpath.TextNode;
import net.sourceforge.pmd.util.CollectionUtil;
import net.sf.saxon.Configuration;
@@ -67,13 +70,10 @@ public final class AstElementNode extends BaseNodeInfo implements SiblingCountin
}
private static int determineType(Node node) {
- // As of PMD 6.48.0, only the experimental HTML module uses this naming
- // convention to identify non-element nodes.
- // TODO PMD 7: maybe generalize this to other languages
- String name = node.getXPathNodeName();
- if ("#text".equals(name)) {
+ // As of PMD 7, only the HTML module uses these interfaces
+ if (node instanceof TextNode) {
return Type.TEXT;
- } else if ("#comment".equals(name)) {
+ } else if (node instanceof CommentNode) {
return Type.COMMENT;
}
return Type.ELEMENT;
@@ -209,8 +209,12 @@ public final class AstElementNode extends BaseNodeInfo implements SiblingCountin
@Override
public CharSequence getStringValueCS() {
- if (getNodeKind() == Type.TEXT || getNodeKind() == Type.COMMENT) {
- return getUnderlyingNode().getImage();
+ Node node = getUnderlyingNode();
+ if (node instanceof TextNode) {
+ return ((TextNode) node).getText();
+ }
+ if (node instanceof CommentNode) {
+ return ((CommentNode) node).getData();
}
// https://www.w3.org/TR/xpath-datamodel-31/#ElementNode
@@ -220,9 +224,11 @@ public final class AstElementNode extends BaseNodeInfo implements SiblingCountin
// descendants, the zero-length string.
// Since we represent all our Nodes as elements, there are no
- // text nodes
- // TODO: for some languages like html we have text nodes
- return "";
+ // text nodes usually, except for HTML module - there we have
+ // potentially text nodes
+ return node.descendants(TextNode.class).toStream()
+ .map(TextNode::getText)
+ .collect(Collectors.joining(""));
}
@Override
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/CoordinateXPathFunction.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/CoordinateXPathFunction.java
index 31d41783e2..59a4e83b8e 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/CoordinateXPathFunction.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/CoordinateXPathFunction.java
@@ -7,23 +7,15 @@ package net.sourceforge.pmd.lang.rule.xpath.internal;
import java.util.function.ToIntFunction;
import net.sourceforge.pmd.lang.ast.Node;
-import net.sourceforge.pmd.lang.rule.xpath.impl.AbstractXPathFunctionDef;
-
-import net.sf.saxon.expr.XPathContext;
-import net.sf.saxon.lib.ExtensionFunctionCall;
-import net.sf.saxon.om.Sequence;
-import net.sf.saxon.pattern.NodeKindTest;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.type.Type;
-import net.sf.saxon.value.Int64Value;
-import net.sf.saxon.value.SequenceType;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionDefinition;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionException;
/**
* A function that returns the current file name.
*
* @author Clément Fournier
*/
-public final class CoordinateXPathFunction extends AbstractXPathFunctionDef {
+public final class CoordinateXPathFunction extends XPathFunctionDefinition {
public static final CoordinateXPathFunction START_LINE =
new CoordinateXPathFunction("startLine", Node::getBeginLine);
@@ -34,9 +26,7 @@ public final class CoordinateXPathFunction extends AbstractXPathFunctionDef {
public static final CoordinateXPathFunction END_COLUMN =
new CoordinateXPathFunction("endColumn", Node::getEndColumn);
- private static final SequenceType[] A_SINGLE_ELEMENT = {
- NodeKindTest.makeNodeKindTest(Type.ELEMENT).one(),
- };
+ private static final Type[] A_SINGLE_ELEMENT = { Type.SINGLE_ELEMENT };
public static final String PMD_NODE_USER_DATA = "pmd.node";
private final ToIntFunction getter;
@@ -46,32 +36,26 @@ public final class CoordinateXPathFunction extends AbstractXPathFunctionDef {
}
@Override
- public SequenceType[] getArgumentTypes() {
+ public Type[] getArgumentTypes() {
return A_SINGLE_ELEMENT;
}
@Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.SINGLE_INTEGER;
+ public Type getResultType() {
+ return Type.SINGLE_INTEGER;
}
@Override
- public ExtensionFunctionCall makeCallExpression() {
- return new ExtensionFunctionCall() {
-
- @Override
- public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
- Node node = XPathElementToNodeHelper.itemToNode(arguments[0]);
- if (node == null) {
- throw new XPathException(
- "Cannot call function '" + getFunctionQName().getLocalPart()
- + "' on argument " + arguments[0]
- );
- }
- return Int64Value.makeIntegerValue(getter.applyAsInt(node));
+ public FunctionCall makeCallExpression() {
+ return (contextNode, arguments) -> {
+ Node node = XPathElementToNodeHelper.itemToNode(arguments[0]);
+ if (node == null) {
+ throw new XPathFunctionException(
+ "Cannot call function '" + getQName().getLocalPart()
+ + "' on argument " + arguments[0]
+ );
}
+ return getter.applyAsInt(node);
};
}
-
-
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DefaultXPathFunctions.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DefaultXPathFunctions.java
index bfd58f98fa..fddc9bc8e6 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DefaultXPathFunctions.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DefaultXPathFunctions.java
@@ -7,16 +7,15 @@ package net.sourceforge.pmd.lang.rule.xpath.internal;
import java.util.Set;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionDefinition;
import net.sourceforge.pmd.util.CollectionUtil;
-import net.sf.saxon.lib.ExtensionFunctionDefinition;
-
/**
* Default XPath functions provided by pmd-core.
*/
public final class DefaultXPathFunctions {
- private static final Set DEFAULTS =
+ private static final Set DEFAULTS =
CollectionUtil.immutableSetOf(
FileNameXPathFunction.INSTANCE,
CoordinateXPathFunction.START_LINE,
@@ -29,7 +28,7 @@ public final class DefaultXPathFunctions {
// utility class
}
- public static Set getDefaultFunctions() {
+ public static Set getDefaultFunctions() {
return DEFAULTS;
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java
index 5b0a6c3dc8..1190e0235e 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java
@@ -10,9 +10,9 @@ import java.util.concurrent.ConcurrentMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.lang.rule.XPathRule;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
+import net.sourceforge.pmd.lang.rule.xpath.XPathRule;
/**
* Records usages of deprecated attributes in XPath rules. This needs
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/FileNameXPathFunction.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/FileNameXPathFunction.java
index 97131458e1..1f170aee12 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/FileNameXPathFunction.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/FileNameXPathFunction.java
@@ -6,23 +6,16 @@ package net.sourceforge.pmd.lang.rule.xpath.internal;
import java.util.Objects;
-import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.RootNode;
-import net.sourceforge.pmd.lang.rule.xpath.impl.AbstractXPathFunctionDef;
-
-import net.sf.saxon.expr.XPathContext;
-import net.sf.saxon.lib.ExtensionFunctionCall;
-import net.sf.saxon.om.Sequence;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.value.SequenceType;
-import net.sf.saxon.value.StringValue;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionDefinition;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionException;
/**
* A function that returns the current file name.
*
* @author Clément Fournier
*/
-public final class FileNameXPathFunction extends AbstractXPathFunctionDef {
+public final class FileNameXPathFunction extends XPathFunctionDefinition {
public static final FileNameXPathFunction INSTANCE = new FileNameXPathFunction();
@@ -31,36 +24,31 @@ public final class FileNameXPathFunction extends AbstractXPathFunctionDef {
}
@Override
- public SequenceType[] getArgumentTypes() {
- return new SequenceType[0];
+ public Type getResultType() {
+ return Type.SINGLE_STRING;
}
@Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.STRING_SEQUENCE;
+ public boolean dependsOnContext() {
+ return true;
}
@Override
- public ExtensionFunctionCall makeCallExpression() {
- return new ExtensionFunctionCall() {
-
- @Override
- public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
- Node node = XPathElementToNodeHelper.itemToNode(context.getContextItem());
- if (node == null) {
- throw new XPathException(
- "Cannot call function '" + getFunctionQName().getLocalPart()
- + "' with context item " + context.getContextItem()
- );
- }
- RootNode root = node.getRoot();
- Objects.requireNonNull(root, "No root node in tree?");
-
- String fileName = root.getTextDocument().getFileId().getFileName();
- Objects.requireNonNull(fileName, "File name was not set");
-
- return new StringValue(fileName);
+ public FunctionCall makeCallExpression() {
+ return (node, arguments) -> {
+ if (node == null) {
+ throw new XPathFunctionException(
+ "Cannot call function '" + getQName().getLocalPart()
+ + "' without context item"
+ );
}
+ RootNode root = node.getRoot();
+ Objects.requireNonNull(root, "No root node in tree?");
+
+ String fileName = root.getTextDocument().getFileId().getFileName();
+ Objects.requireNonNull(fileName, "File name was not set");
+
+ return fileName;
};
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/SaxonExtensionFunctionDefinitionAdapter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/SaxonExtensionFunctionDefinitionAdapter.java
new file mode 100644
index 0000000000..31808f9fab
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/SaxonExtensionFunctionDefinitionAdapter.java
@@ -0,0 +1,172 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.rule.xpath.internal;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import javax.xml.namespace.QName;
+
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionDefinition;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionException;
+
+import net.sf.saxon.expr.Expression;
+import net.sf.saxon.expr.StaticContext;
+import net.sf.saxon.expr.StringLiteral;
+import net.sf.saxon.expr.XPathContext;
+import net.sf.saxon.lib.ExtensionFunctionCall;
+import net.sf.saxon.lib.ExtensionFunctionDefinition;
+import net.sf.saxon.om.EmptyAtomicSequence;
+import net.sf.saxon.om.Sequence;
+import net.sf.saxon.om.StructuredQName;
+import net.sf.saxon.pattern.NodeKindTest;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.value.BigDecimalValue;
+import net.sf.saxon.value.BooleanValue;
+import net.sf.saxon.value.EmptySequence;
+import net.sf.saxon.value.Int64Value;
+import net.sf.saxon.value.SequenceExtent;
+import net.sf.saxon.value.SequenceType;
+import net.sf.saxon.value.StringValue;
+
+/**
+ * Converts PMD's {@link XPathFunctionDefinition} into Saxon's {@link ExtensionFunctionDefinition}.
+ */
+public class SaxonExtensionFunctionDefinitionAdapter extends ExtensionFunctionDefinition {
+ private static final SequenceType SINGLE_ELEMENT_SEQUENCE_TYPE = NodeKindTest.ELEMENT.one();
+
+ private final XPathFunctionDefinition definition;
+
+ public SaxonExtensionFunctionDefinitionAdapter(XPathFunctionDefinition definition) {
+ this.definition = definition;
+ }
+
+ private SequenceType convertToSequenceType(XPathFunctionDefinition.Type type) {
+ switch (type) {
+ case SINGLE_STRING: return SequenceType.SINGLE_STRING;
+ case SINGLE_BOOLEAN: return SequenceType.SINGLE_BOOLEAN;
+ case SINGLE_ELEMENT: return SINGLE_ELEMENT_SEQUENCE_TYPE;
+ case SINGLE_INTEGER: return SequenceType.SINGLE_INTEGER;
+ case STRING_SEQUENCE: return SequenceType.STRING_SEQUENCE;
+ case OPTIONAL_STRING: return SequenceType.OPTIONAL_STRING;
+ case OPTIONAL_DECIMAL: return SequenceType.OPTIONAL_DECIMAL;
+ default:
+ throw new UnsupportedOperationException("Type " + type + " is not supported");
+ }
+ }
+
+ private SequenceType[] convertToSequenceTypes(XPathFunctionDefinition.Type[] types) {
+ SequenceType[] result = new SequenceType[types.length];
+ for (int i = 0; i < types.length; i++) {
+ result[i] = convertToSequenceType(types[i]);
+ }
+ return result;
+ }
+
+ @Override
+ public StructuredQName getFunctionQName() {
+ QName qName = definition.getQName();
+ return new StructuredQName(qName.getPrefix(), qName.getNamespaceURI(), qName.getLocalPart());
+ }
+
+ @Override
+ public SequenceType[] getArgumentTypes() {
+ return convertToSequenceTypes(definition.getArgumentTypes());
+ }
+
+ @Override
+ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
+ return convertToSequenceType(definition.getResultType());
+ }
+
+ @Override
+ public boolean dependsOnFocus() {
+ return definition.dependsOnContext();
+ }
+
+ @Override
+ public ExtensionFunctionCall makeCallExpression() {
+ XPathFunctionDefinition.FunctionCall call = definition.makeCallExpression();
+ return new ExtensionFunctionCall() {
+ @Override
+ public Expression rewrite(StaticContext context, Expression[] arguments) throws XPathException {
+ Object[] convertedArguments = new Object[definition.getArgumentTypes().length];
+ for (int i = 0; i < convertedArguments.length; i++) {
+ if (arguments[i] instanceof StringLiteral) {
+ convertedArguments[i] = ((StringLiteral) arguments[i]).getStringValue();
+ }
+ }
+ try {
+ call.staticInit(convertedArguments);
+ } catch (XPathFunctionException e) {
+ XPathException xPathException = new XPathException(e);
+ xPathException.setIsStaticError(true);
+ throw xPathException;
+ }
+ return null;
+ }
+
+ @Override
+ public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
+ Node contextNode = null;
+ if (definition.dependsOnContext()) {
+ contextNode = XPathElementToNodeHelper.itemToNode(context.getContextItem());
+ }
+ Object[] convertedArguments = new Object[definition.getArgumentTypes().length];
+ for (int i = 0; i < convertedArguments.length; i++) {
+ switch (definition.getArgumentTypes()[i]) {
+ case SINGLE_STRING:
+ convertedArguments[i] = arguments[i].head().getStringValue();
+ break;
+ case SINGLE_ELEMENT:
+ convertedArguments[i] = arguments[i].head();
+ break;
+ default:
+ throw new UnsupportedOperationException("Don't know how to convert argument type " + definition.getArgumentTypes()[i]);
+ }
+ }
+
+
+ Object result = null;
+ try {
+ result = call.call(contextNode, convertedArguments);
+ } catch (XPathFunctionException e) {
+ throw new XPathException(e);
+ }
+ Sequence convertedResult = null;
+ switch (definition.getResultType()) {
+ case SINGLE_BOOLEAN:
+ convertedResult = BooleanValue.get((Boolean) result);
+ break;
+ case SINGLE_INTEGER:
+ convertedResult = Int64Value.makeIntegerValue((Integer) result);
+ break;
+ case SINGLE_STRING:
+ convertedResult = new StringValue((String) result);
+ break;
+ case OPTIONAL_STRING:
+ convertedResult = result instanceof Optional && ((Optional) result).isPresent()
+ ? new StringValue(((Optional) result).get())
+ : EmptyAtomicSequence.INSTANCE;
+ break;
+ case STRING_SEQUENCE:
+ convertedResult = result instanceof List
+ ? new SequenceExtent(((List) result).stream().map(StringValue::new).collect(Collectors.toList()))
+ : EmptySequence.getInstance();
+ break;
+ case OPTIONAL_DECIMAL:
+ convertedResult = result instanceof Optional && ((Optional) result).isPresent()
+ ? new BigDecimalValue(((Optional) result).get())
+ : EmptySequence.getInstance();
+ break;
+ default:
+ throw new UnsupportedOperationException("Don't know how to convert result type " + definition.getResultType());
+ }
+ return convertedResult;
+ }
+ };
+ }
+}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/SaxonXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/SaxonXPathRuleQuery.java
index 70ec7b7e59..60945da303 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/SaxonXPathRuleQuery.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/SaxonXPathRuleQuery.java
@@ -17,10 +17,10 @@ import org.slf4j.LoggerFactory;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.RootNode;
-import net.sourceforge.pmd.lang.rule.XPathRule;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException.Phase;
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionDefinition;
import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.util.DataMap;
@@ -194,12 +194,13 @@ public class SaxonXPathRuleQuery {
for (final PropertyDescriptor> propertyDescriptor : properties.keySet()) {
final String name = propertyDescriptor.name();
- if (!"xpath".equals(name) && !XPathRule.VERSION_DESCRIPTOR.name().equals(name)) {
+ if (!"xpath".equals(name)) {
staticCtx.declareProperty(propertyDescriptor);
}
}
- for (ExtensionFunctionDefinition fun : xPathHandler.getRegisteredExtensionFunctions()) {
+ for (XPathFunctionDefinition xpathFun : xPathHandler.getRegisteredExtensionFunctions()) {
+ ExtensionFunctionDefinition fun = new SaxonExtensionFunctionDefinitionAdapter(xpathFun);
StructuredQName qname = fun.getFunctionQName();
staticCtx.declareNamespace(qname.getPrefix(), qname.getURI());
this.configuration.registerExtensionFunction(fun);
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/package-info.java b/pmd-core/src/main/java/net/sourceforge/pmd/package-info.java
new file mode 100644
index 0000000000..330b372655
--- /dev/null
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/package-info.java
@@ -0,0 +1,11 @@
+/*
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+/**
+ * This is the PMD programming mistake detector.
+ *
+ *
Use it through {@link net.sourceforge.pmd.PmdAnalysis} and
+ * {@link net.sourceforge.pmd.cpd.CpdAnalysis}.
+ */
+package net.sourceforge.pmd;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/package.html b/pmd-core/src/main/java/net/sourceforge/pmd/package.html
deleted file mode 100644
index a9ba343fd3..0000000000
--- a/pmd-core/src/main/java/net/sourceforge/pmd/package.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
- PMD
-
-
-
This is the PMD programming mistake detector. In order to use it,
- create a new instance of {@link net.sourceforge.pmd.PMD} and use its
- {@link net.sourceforge.pmd.PMD#processFiles} method.
-
-
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java
index a4e2fc708f..b9100c8f4c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java
@@ -8,8 +8,8 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleSetWriter;
import net.sourceforge.pmd.annotation.InternalApi;
+import net.sourceforge.pmd.lang.rule.RuleSetWriter;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertySource.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertySource.java
index 9d5ad1413a..0e0bb08f79 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertySource.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertySource.java
@@ -7,6 +7,8 @@ package net.sourceforge.pmd.properties;
import java.util.List;
import java.util.Map;
+import net.sourceforge.pmd.lang.rule.Rule;
+
/**
* Entity that manages a list of properties. Properties are described by
@@ -18,7 +20,7 @@ import java.util.Map;
*
*
Bad configuration of the properties may be reported by {@link #dysfunctionReason()}.
*
- *
Notable instances of this interface are {@linkplain net.sourceforge.pmd.Rule rules} and
+ *
- * A console renderer with optional color support under *nix systems.
+ * A console renderer with color support for terminal supporting ansi color codes.
*
- * Colorization is turned on by supplying -Dpmd.color - any value other
- * than '0' or 'false', enables color - including an empty value (''). Nota
- * Bene: colorization is atm only supported under *nix terminals accepting
- * ansi escape sequences, such as xterm, rxvt et cetera.
- *
*/
public class TextColorRenderer extends AbstractAccumulatingRenderer {
public static final String NAME = "textcolor";
- // What? TODO 7.0.0 Use a boolean property
- // TODO should the "textcolor" renderer really support "optional" colors?
- // either use text or textcolor...
- // This property is really weird, the standard boolean properties
- // are false unless value is exactly "true", this one is true unless
- // "false" or "0"...
- public static final PropertyDescriptor COLOR = PropertyFactory.stringProperty("color").desc("Enables colors with anything other than 'false' or '0'.").defaultValue("yes").build();
- private static final String SYSTEM_PROPERTY_PMD_COLOR = "pmd.color";
-
/**
* Directory from where java was invoked.
*/
private String pwd;
- private String yellowBold = "";
- private String whiteBold = "";
- private String redBold = "";
- private String red = "";
- private String cyan = "";
- private String green = "";
+ private String yellowBold = "\u001B[1;33m";
+ private String whiteBold = "\u001B[1;37m";
+ private String redBold = "\u001B[1;31m";
+ private String red = "\u001B[0;31m";
+ private String green = "\u001B[0;32m";
+ private String cyan = "\u001B[0;36m";
- private String colorReset = "";
+ private String colorReset = "\u001B[0m";
public TextColorRenderer() {
// This Renderer was originally submitted by Adrian Papari and was
// called the "PapariTextRenderer" pre-PMD 5.0.
super(NAME, "Text format, with color support (requires ANSI console support, e.g. xterm, rxvt, etc.).");
- definePropertyDescriptor(COLOR);
}
@Override
@@ -93,36 +75,10 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
return "txt";
}
- /**
- * Enables colors on *nix systems - not windows. Color support depends on
- * the pmd.color property, which should be set with the -D option during
- * execution - a set value other than 'false' or '0' enables color.
- *
- * btw, is it possible to do this on windows (ie; console colors)?
- */
- private void initializeColorsIfSupported() {
- if (isPropertyEnabled(getProperty(COLOR)) || isPropertyEnabled(System.getProperty(SYSTEM_PROPERTY_PMD_COLOR))) {
- this.yellowBold = "\u001B[1;33m";
- this.whiteBold = "\u001B[1;37m";
- this.redBold = "\u001B[1;31m";
- this.red = "\u001B[0;31m";
- this.green = "\u001B[0;32m";
- this.cyan = "\u001B[0;36m";
-
- this.colorReset = "\u001B[0m";
- }
- }
-
- private boolean isPropertyEnabled(String property) {
- return property != null && !("0".equals(property) || "false".equalsIgnoreCase(property));
- }
-
-
@Override
public void outputReport(Report report) throws IOException {
StringBuilder buf = new StringBuilder(500);
buf.append(System.lineSeparator());
- initializeColorsIfSupported();
String lastFile = null;
int numberOfErrors = 0;
int numberOfWarnings = 0;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextPadRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextPadRenderer.java
index 0b68d66206..77ced0a1c4 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextPadRenderer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextPadRenderer.java
@@ -7,7 +7,7 @@ package net.sourceforge.pmd.renderers;
import java.io.IOException;
import java.util.Iterator;
-import net.sourceforge.pmd.RuleViolation;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
*
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java
index 04702540fc..4e727c125c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java
@@ -7,8 +7,8 @@ package net.sourceforge.pmd.renderers;
import java.io.IOException;
import java.util.Iterator;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleViolation;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* Renderer to simple text format.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/VBHTMLRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/VBHTMLRenderer.java
index ae7a5f7927..2d751aedb4 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/VBHTMLRenderer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/VBHTMLRenderer.java
@@ -7,8 +7,8 @@ package net.sourceforge.pmd.renderers;
import java.io.IOException;
import java.util.Iterator;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleViolation;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* Renderer to another HTML format.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java
index ef3ac7f0de..7699d26c6c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java
@@ -25,11 +25,11 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.PMDVersion;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
import net.sourceforge.pmd.util.StringUtil;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/YAHTMLRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/YAHTMLRenderer.java
index db7dcd08ff..9001f5a05c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/YAHTMLRenderer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/YAHTMLRenderer.java
@@ -16,10 +16,10 @@ import java.util.TreeMap;
import org.apache.commons.lang3.StringUtils;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
import net.sourceforge.pmd.util.StringUtil;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLogBuilder.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLogBuilder.java
index d76c021b03..286d247f31 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLogBuilder.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/internal/sarif/SarifLogBuilder.java
@@ -11,8 +11,6 @@ import java.util.HashSet;
import java.util.List;
import net.sourceforge.pmd.PMDVersion;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.renderers.internal.sarif.SarifLog.ArtifactLocation;
import net.sourceforge.pmd.renderers.internal.sarif.SarifLog.AssociatedRule;
import net.sourceforge.pmd.renderers.internal.sarif.SarifLog.Component;
@@ -30,6 +28,8 @@ import net.sourceforge.pmd.renderers.internal.sarif.SarifLog.Run;
import net.sourceforge.pmd.renderers.internal.sarif.SarifLog.Tool;
import net.sourceforge.pmd.renderers.internal.sarif.SarifLog.ToolConfigurationNotification;
import net.sourceforge.pmd.renderers.internal.sarif.SarifLog.ToolExecutionNotification;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
public class SarifLogBuilder {
private final List rules = new ArrayList<>();
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/FileAnalysisListener.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/FileAnalysisListener.java
index 7ecc79018e..30e0778b41 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/FileAnalysisListener.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/FileAnalysisListener.java
@@ -8,11 +8,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.Report.ProcessingError;
-import net.sourceforge.pmd.Report.SuppressedViolation;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.internal.util.IOUtil;
+import net.sourceforge.pmd.reporting.Report.ProcessingError;
+import net.sourceforge.pmd.reporting.Report.SuppressedViolation;
import net.sourceforge.pmd.util.AssertionUtil;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/GlobalAnalysisListener.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/GlobalAnalysisListener.java
index 23330b416e..740d56e9a8 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/GlobalAnalysisListener.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/GlobalAnalysisListener.java
@@ -11,15 +11,14 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import net.sourceforge.pmd.PmdAnalysis;
-import net.sourceforge.pmd.Report.ConfigurationError;
-import net.sourceforge.pmd.Report.GlobalReportBuilderListener;
-import net.sourceforge.pmd.Report.ProcessingError;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.renderers.Renderer;
+import net.sourceforge.pmd.reporting.Report.ConfigurationError;
+import net.sourceforge.pmd.reporting.Report.GlobalReportBuilderListener;
+import net.sourceforge.pmd.reporting.Report.ProcessingError;
import net.sourceforge.pmd.util.AssertionUtil;
import net.sourceforge.pmd.util.BaseResultProducingCloseable;
import net.sourceforge.pmd.util.CollectionUtil;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/InternalApiBridge.java
similarity index 90%
rename from pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/reporting/InternalApiBridge.java
index 60be0d4447..ff6bb2b7fb 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/InternalApiBridge.java
@@ -2,10 +2,10 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.reporting;
import net.sourceforge.pmd.annotation.InternalApi;
-import net.sourceforge.pmd.reporting.FileAnalysisListener;
+import net.sourceforge.pmd.lang.rule.Rule;
/**
* Internal API.
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/NoopFileListener.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/NoopFileListener.java
index 737bbb8c57..223fb948f5 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/NoopFileListener.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/NoopFileListener.java
@@ -4,8 +4,6 @@
package net.sourceforge.pmd.reporting;
-import net.sourceforge.pmd.RuleViolation;
-
final class NoopFileListener implements FileAnalysisListener {
static final NoopFileListener INSTANCE = new NoopFileListener();
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ParametricRuleViolation.java
similarity index 92%
rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/reporting/ParametricRuleViolation.java
index 6697ff7728..61ac4cf9f2 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ParametricRuleViolation.java
@@ -2,16 +2,14 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd.lang.rule;
+package net.sourceforge.pmd.reporting;
import java.util.Collections;
import java.util.Map;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.document.FileLocation;
-import net.sourceforge.pmd.reporting.Reportable;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.util.AssertionUtil;
/**
@@ -20,8 +18,6 @@ import net.sourceforge.pmd.util.AssertionUtil;
@Deprecated
@InternalApi
public class ParametricRuleViolation implements RuleViolation {
- // todo move to package reporting
-
protected final Rule rule;
protected final String description;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/Report.java
similarity index 97%
rename from pmd-core/src/main/java/net/sourceforge/pmd/Report.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/reporting/Report.java
index d88dd692f3..a99a0bd184 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/Report.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.reporting;
import static java.util.Collections.synchronizedList;
@@ -15,16 +15,16 @@ import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
+import net.sourceforge.pmd.PmdAnalysis;
import net.sourceforge.pmd.annotation.Experimental;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer;
-import net.sourceforge.pmd.reporting.FileAnalysisListener;
-import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.util.BaseResultProducingCloseable;
/**
- * A {@link Report} collects all informations during a PMD execution. This
+ * A {@link Report} collects all information during a PMD execution. This
* includes violations, suppressed violations, metrics, error during processing
* and configuration errors.
*
@@ -42,8 +42,6 @@ import net.sourceforge.pmd.util.BaseResultProducingCloseable;
*
*/
public final class Report {
- // todo move to package reporting
-
private final List violations = synchronizedList(new ArrayList<>());
private final List suppressedRuleViolations = synchronizedList(new ArrayList<>());
private final List errors = synchronizedList(new ArrayList<>());
@@ -75,7 +73,7 @@ public final class Report {
}
/**
- * Gets the wrongly configured rule
+ * Gets the wrongly configured rule.
*
* @return the wrongly configured rule
*/
@@ -343,7 +341,7 @@ public final class Report {
}
@Override
- protected Report getResultImpl() {
+ public Report getResultImpl() {
return report;
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStatsListener.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStatsListener.java
index 27b8e96cb8..49d18837d3 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStatsListener.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ReportStatsListener.java
@@ -6,9 +6,8 @@ package net.sourceforge.pmd.reporting;
import java.util.concurrent.atomic.AtomicInteger;
-import net.sourceforge.pmd.Report.ProcessingError;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.document.TextFile;
+import net.sourceforge.pmd.reporting.Report.ProcessingError;
import net.sourceforge.pmd.util.BaseResultProducingCloseable;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/Reportable.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/Reportable.java
index 9b6eb5042e..574a8323ef 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/Reportable.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/Reportable.java
@@ -4,7 +4,6 @@
package net.sourceforge.pmd.reporting;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.ast.GenericToken;
import net.sourceforge.pmd.lang.ast.Node;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/RuleContext.java
similarity index 96%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/reporting/RuleContext.java
index b87bf86d9e..4f2674fe8b 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/RuleContext.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.reporting;
import static net.sourceforge.pmd.util.CollectionUtil.listOf;
@@ -15,16 +15,14 @@ import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.Report.SuppressedViolation;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.document.FileLocation;
import net.sourceforge.pmd.lang.document.TextRange2d;
import net.sourceforge.pmd.lang.rule.AbstractRule;
-import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
-import net.sourceforge.pmd.reporting.FileAnalysisListener;
-import net.sourceforge.pmd.reporting.ViolationDecorator;
+import net.sourceforge.pmd.reporting.Report.SuppressedViolation;
/**
* The API for rules to report violations or errors during analysis.
@@ -37,8 +35,6 @@ import net.sourceforge.pmd.reporting.ViolationDecorator;
* not unique throughout the analysis, a separate one is used per file and rule.
*/
public final class RuleContext {
- // todo move to package reporting
-
// Rule contexts do not need to be thread-safe, within PmdRunnable
// they are stack-local
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/RuleViolation.java
similarity index 98%
rename from pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/reporting/RuleViolation.java
index 3b0f1518a7..df63e96ea6 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/RuleViolation.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.reporting;
import java.util.Comparator;
import java.util.Map;
@@ -10,6 +10,7 @@ import java.util.Map;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.FileLocation;
+import net.sourceforge.pmd.lang.rule.Rule;
/**
* A RuleViolation is created by a Rule when it identifies a violation of the
@@ -22,8 +23,6 @@ import net.sourceforge.pmd.lang.document.FileLocation;
* @see Rule
*/
public interface RuleViolation {
- // todo move to package reporting
-
/**
* A comparator for rule violations. This compares all exposed attributes
* of a violation, filename first. The remaining parameters are compared
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ViolationDecorator.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ViolationDecorator.java
index d68ac3d9ab..ead8232db3 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ViolationDecorator.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ViolationDecorator.java
@@ -9,7 +9,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.ast.Node;
/**
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ViolationSuppressor.java
similarity index 97%
rename from pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java
rename to pmd-core/src/main/java/net/sourceforge/pmd/reporting/ViolationSuppressor.java
index 4d6c0edb30..a30dd01ede 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ViolationSuppressor.java
@@ -2,7 +2,7 @@
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
-package net.sourceforge.pmd;
+package net.sourceforge.pmd.reporting;
import java.util.List;
import java.util.Map;
@@ -12,12 +12,13 @@ import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.Report.SuppressedViolation;
import net.sourceforge.pmd.lang.ast.AstInfo;
import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
import net.sourceforge.pmd.lang.rule.xpath.internal.DeprecatedAttrLogger;
import net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery;
+import net.sourceforge.pmd.reporting.Report.SuppressedViolation;
/**
* An object that suppresses rule violations. Suppressors are used by
@@ -26,8 +27,6 @@ import net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery;
* no knowledge of language-specific suppressors.
*/
public interface ViolationSuppressor {
- // todo move to package reporting
-
/**
* Suppressor for the violationSuppressRegex property.
*/
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/package-info.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/package-info.java
index 2d9e959ca0..a1b362a05c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/package-info.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/package-info.java
@@ -4,9 +4,5 @@
/**
* Logic about reporting: violations, suppression etc.
- *
- *
TODO move {@link net.sourceforge.pmd.Report}, {@link net.sourceforge.pmd.RuleViolation},
- * {@link net.sourceforge.pmd.RuleContext}, {@link net.sourceforge.pmd.ViolationSuppressor}
- * into this package
*/
package net.sourceforge.pmd.reporting;
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java
index cd1df7976b..e76576c78e 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java
@@ -17,7 +17,7 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
/**
* @apiNote Internal API
@@ -53,9 +53,9 @@ public class ResourceLoader {
}
/**
- * Attempts to load the resource from file, a URL or the claspath
- *
- * Caller is responsible for closing the {@link InputStream}.
+ * Attempts to load the resource from file, a URL or the classpath.
+ *
+ *
Caller is responsible for closing the {@link InputStream}.
*
* @param name The resource to attempt and load
*
@@ -74,7 +74,7 @@ public class ResourceLoader {
}
}
- // Maybe it's a url?
+ // Maybe it's a URL?
try {
final HttpURLConnection connection = (HttpURLConnection) new URL(name).openConnection();
connection.setConnectTimeout(TIMEOUT);
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TextTreeRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TextTreeRenderer.java
index c0302207e6..18c1fa1965 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TextTreeRenderer.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TextTreeRenderer.java
@@ -6,7 +6,6 @@ package net.sourceforge.pmd.util.treeexport;
import java.io.IOException;
-import net.sourceforge.pmd.annotation.Experimental;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.properties.AbstractPropertySource;
import net.sourceforge.pmd.properties.PropertyDescriptor;
@@ -43,10 +42,9 @@ import net.sourceforge.pmd.properties.PropertySource;
*
*
*
- * By default just prints the structure, like shown above. You can
+ * By default, just prints the structure, like shown above. You can
* configure it to render nodes differently by overriding {@link #appendNodeInfoLn(Appendable, Node)}.
*/
-@Experimental
public class TextTreeRenderer implements TreeRenderer {
static final TreeRendererDescriptor DESCRIPTOR = new TreeRendererDescriptor() {
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java
index 2f55cb36d4..d36f79aa9c 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java
@@ -5,7 +5,7 @@
package net.sourceforge.pmd.util.treeexport;
import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.util.List;
import java.util.Properties;
import org.slf4j.Logger;
@@ -18,9 +18,7 @@ import net.sourceforge.pmd.util.log.PmdReporter;
import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
public class TreeExportConfiguration extends AbstractConfiguration {
-
private static final Logger LOG = LoggerFactory.getLogger(TreeExportConfiguration.class);
- protected Path reportFile;
private String format = "xml";
private Language language = LanguageRegistry.PMD.getLanguageById("java");
@@ -94,43 +92,18 @@ public class TreeExportConfiguration extends AbstractConfiguration {
this.messageReporter = messageReporter;
}
- /**
- * Get the file to which the report should render.
- *
- * @return The file to which to render.
- * @deprecated Use {@link #getReportFilePath()}
- */
- @Deprecated
- public String getReportFile() {
- return reportFile == null ? null : reportFile.toString();
+ @Override
+ public List getRelativizeRoots() {
+ throw new UnsupportedOperationException();
}
- /**
- * Get the file to which the report should render.
- *
- * @return The file to which to render.
- */
- public Path getReportFilePath() {
- return reportFile;
+ @Override
+ public void addRelativizeRoot(Path path) {
+ throw new UnsupportedOperationException();
}
- /**
- * Set the file to which the report should render.
- *
- * @param reportFile the file to set
- * @deprecated Use {@link #setReportFile(Path)}
- */
- @Deprecated
- public void setReportFile(String reportFile) {
- this.reportFile = reportFile == null ? null : Paths.get(reportFile);
- }
-
- /**
- * Set the file to which the report should render.
- *
- * @param reportFile the file to set
- */
- public void setReportFile(Path reportFile) {
- this.reportFile = reportFile;
+ @Override
+ public void addRelativizeRoots(List paths) {
+ throw new UnsupportedOperationException();
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExporter.java
index 4e08605da9..60a7f7a52f 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExporter.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExporter.java
@@ -12,7 +12,6 @@ import java.util.Collections;
import java.util.Map.Entry;
import java.util.Properties;
-import net.sourceforge.pmd.annotation.Experimental;
import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
import net.sourceforge.pmd.lang.LanguageProcessor;
import net.sourceforge.pmd.lang.LanguageProcessorRegistry;
@@ -30,7 +29,6 @@ import net.sourceforge.pmd.lang.rule.xpath.Attribute;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertySource;
-@Experimental
public class TreeExporter {
private final TreeExportConfiguration configuration;
@@ -63,8 +61,6 @@ public class TreeExporter {
}
private void run(LanguageProcessorRegistry langRegistry, final TreeRenderer renderer) throws IOException {
- printWarning();
-
LanguageVersion langVersion = configuration.getLanguage().getDefaultVersion();
@SuppressWarnings("PMD.CloseResource")
LanguageProcessor processor = langRegistry.getProcessor(configuration.getLanguage());
@@ -95,13 +91,6 @@ public class TreeExporter {
return new BufferedReader(new InputStreamReader(io.stdin));
}
- private void printWarning() {
- io.stderr.println("-------------------------------------------------------------------------------");
- io.stderr.println("This command line utility is experimental. It might change at any time without");
- io.stderr.println("prior notice.");
- io.stderr.println("-------------------------------------------------------------------------------");
- }
-
private T parseProperties(T bundle, Properties properties) {
for (Entry
Note: This class has been called DartTokenizer in PMD 6
.
*/
-public class DartTokenizer extends AntlrTokenizer {
+public class DartCpdLexer extends AntlrCpdLexer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
diff --git a/pmd-dart/src/test/java/net/sourceforge/pmd/lang/dart/cpd/DartTokenizerTest.java b/pmd-dart/src/test/java/net/sourceforge/pmd/lang/dart/cpd/DartCpdLexerTest.java
similarity index 94%
rename from pmd-dart/src/test/java/net/sourceforge/pmd/lang/dart/cpd/DartTokenizerTest.java
rename to pmd-dart/src/test/java/net/sourceforge/pmd/lang/dart/cpd/DartCpdLexerTest.java
index 02106add09..7d85f57be4 100644
--- a/pmd-dart/src/test/java/net/sourceforge/pmd/lang/dart/cpd/DartTokenizerTest.java
+++ b/pmd-dart/src/test/java/net/sourceforge/pmd/lang/dart/cpd/DartCpdLexerTest.java
@@ -8,9 +8,9 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
-class DartTokenizerTest extends CpdTextComparisonTest {
+class DartCpdLexerTest extends CpdTextComparisonTest {
- DartTokenizerTest() {
+ DartCpdLexerTest() {
super("dart", ".dart");
}
diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java
index ebe55f4abd..256e605904 100644
--- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java
+++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java
@@ -17,9 +17,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetLoader;
import net.sourceforge.pmd.internal.util.IOUtil;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
public final class GenerateRuleDocsCmd {
diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java
index 10edb13cc5..425037f749 100644
--- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java
+++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java
@@ -32,15 +32,15 @@ import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetLoadException;
-import net.sourceforge.pmd.RuleSetLoader;
import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.RuleReference;
-import net.sourceforge.pmd.lang.rule.XPathRule;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.RuleSetLoadException;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
+import net.sourceforge.pmd.lang.rule.xpath.XPathRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
public class RuleDocGenerator {
@@ -437,7 +437,6 @@ public class RuleDocGenerator {
properties.remove(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR);
properties.remove(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR);
properties.remove(XPathRule.XPATH_DESCRIPTOR);
- properties.remove(XPathRule.VERSION_DESCRIPTOR);
if (!properties.isEmpty()) {
lines.add("**This rule has the following properties:**");
diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java
index f581ae6776..156946cfbc 100644
--- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java
+++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java
@@ -10,10 +10,10 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.internal.util.IOUtil;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.RuleReference;
+import net.sourceforge.pmd.lang.rule.RuleSet;
public final class RuleSetUtils {
diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/SidebarGenerator.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/SidebarGenerator.java
index 625302fed5..0982f7fb5b 100644
--- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/SidebarGenerator.java
+++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/SidebarGenerator.java
@@ -25,8 +25,8 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.representer.Representer;
-import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.lang.Language;
+import net.sourceforge.pmd.lang.rule.RuleSet;
public class SidebarGenerator {
private static final String SIDEBAR_YML = "docs/_data/sidebars/pmd_sidebar.yml";
diff --git a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java
index 69665c54b5..b593280141 100644
--- a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java
+++ b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java
@@ -19,10 +19,10 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetLoader;
import net.sourceforge.pmd.docs.MockedFileWriter.FileEntry;
import net.sourceforge.pmd.internal.util.IOUtil;
+import net.sourceforge.pmd.lang.rule.RuleSet;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
class RuleDocGeneratorTest {
diff --git a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java
index f5baf81b34..bd3ee01d54 100644
--- a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java
+++ b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java
@@ -13,9 +13,12 @@ import java.nio.file.Path;
import java.util.List;
import org.junit.jupiter.api.Test;
+import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.RuleSetLoader;
+import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.internal.util.IOUtil;
+import net.sourceforge.pmd.lang.rule.RuleSetLoader;
+import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter;
class RuleSetResolverTest {
@@ -33,7 +36,9 @@ class RuleSetResolverTest {
assertFalse(additionalRulesets.isEmpty());
for (String filename : additionalRulesets) {
- new RuleSetLoader().warnDeprecated(false).loadFromResource(filename); // will throw if invalid
+ PMDConfiguration config = new PMDConfiguration();
+ config.setReporter(new SimpleMessageReporter(LoggerFactory.getLogger(RuleSetResolverTest.class)));
+ RuleSetLoader.fromPmdConfig(config).warnDeprecated(false).loadFromResource(filename); // will throw if invalid
}
}
diff --git a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java
index 8fe3a7d5ef..68ce308d5b 100644
--- a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java
+++ b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java
@@ -26,10 +26,10 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.representer.Representer;
-import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.internal.util.IOUtil;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
+import net.sourceforge.pmd.lang.rule.RuleSet;
class SidebarGeneratorTest {
private MockedFileWriter writer = new MockedFileWriter();
diff --git a/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml b/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml
index c6c78e76a8..119a865b0d 100644
--- a/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml
+++ b/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml
@@ -16,7 +16,7 @@ Here might be <script>alert('XSS');</script> as well. And "quotes".
language="java"
since="0.1"
message="Tests that <script>alert('XSS');</script> is properly escaped"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_sample.html#xssindocumentation">
<script>alert('XSS at the beginning');</script> HTML tags might appear at various places.
@@ -57,7 +57,6 @@ Here might be <script>alert('XSS');</script> as well. And "quotes".
3
-
Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
3
-
@@ -206,7 +204,6 @@ RuleTag with full category and without quotes: Use {% rule java/sample/RenamedRu
3
-
Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
3
-
Note: This class has been called GherkinTokenizer in PMD 6
.
*/
-public class GherkinTokenizer extends AntlrTokenizer {
+public class GherkinCpdLexer extends AntlrCpdLexer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
diff --git a/pmd-gherkin/src/test/java/net/sourceforge/pmd/lang/gherkin/cpd/GherkinTokenizerTest.java b/pmd-gherkin/src/test/java/net/sourceforge/pmd/lang/gherkin/cpd/GherkinCpdLexerTest.java
similarity index 83%
rename from pmd-gherkin/src/test/java/net/sourceforge/pmd/lang/gherkin/cpd/GherkinTokenizerTest.java
rename to pmd-gherkin/src/test/java/net/sourceforge/pmd/lang/gherkin/cpd/GherkinCpdLexerTest.java
index 38c4d88595..6fde983b27 100644
--- a/pmd-gherkin/src/test/java/net/sourceforge/pmd/lang/gherkin/cpd/GherkinTokenizerTest.java
+++ b/pmd-gherkin/src/test/java/net/sourceforge/pmd/lang/gherkin/cpd/GherkinCpdLexerTest.java
@@ -8,8 +8,8 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
-class GherkinTokenizerTest extends CpdTextComparisonTest {
- GherkinTokenizerTest() {
+class GherkinCpdLexerTest extends CpdTextComparisonTest {
+ GherkinCpdLexerTest() {
super("gherkin", ".feature");
}
diff --git a/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/GoLanguageModule.java b/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/GoLanguageModule.java
index 966d6300ee..d408688c1f 100644
--- a/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/GoLanguageModule.java
+++ b/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/GoLanguageModule.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.go;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
-import net.sourceforge.pmd.lang.go.cpd.GoTokenizer;
+import net.sourceforge.pmd.lang.go.cpd.GoCpdLexer;
import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase;
public class GoLanguageModule extends CpdOnlyLanguageModuleBase {
@@ -22,7 +22,7 @@ public class GoLanguageModule extends CpdOnlyLanguageModuleBase {
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new GoTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new GoCpdLexer();
}
}
diff --git a/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/cpd/GoTokenizer.java b/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/cpd/GoCpdLexer.java
similarity index 69%
rename from pmd-go/src/main/java/net/sourceforge/pmd/lang/go/cpd/GoTokenizer.java
rename to pmd-go/src/main/java/net/sourceforge/pmd/lang/go/cpd/GoCpdLexer.java
index a4d9526a52..454c8e4daf 100644
--- a/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/cpd/GoTokenizer.java
+++ b/pmd-go/src/main/java/net/sourceforge/pmd/lang/go/cpd/GoCpdLexer.java
@@ -7,10 +7,13 @@ package net.sourceforge.pmd.lang.go.cpd;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
-import net.sourceforge.pmd.cpd.impl.AntlrTokenizer;
+import net.sourceforge.pmd.cpd.impl.AntlrCpdLexer;
import net.sourceforge.pmd.lang.go.ast.GolangLexer;
-public class GoTokenizer extends AntlrTokenizer {
+/**
+ *
Note: This class has been called GoTokenizer in PMD 6
.
+ */
+public class GoCpdLexer extends AntlrCpdLexer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
diff --git a/pmd-go/src/test/java/net/sourceforge/pmd/lang/go/cpd/GoTokenizerTest.java b/pmd-go/src/test/java/net/sourceforge/pmd/lang/go/cpd/GoCpdLexerTest.java
similarity index 88%
rename from pmd-go/src/test/java/net/sourceforge/pmd/lang/go/cpd/GoTokenizerTest.java
rename to pmd-go/src/test/java/net/sourceforge/pmd/lang/go/cpd/GoCpdLexerTest.java
index 6ae9366f0b..e40d2c2b23 100644
--- a/pmd-go/src/test/java/net/sourceforge/pmd/lang/go/cpd/GoTokenizerTest.java
+++ b/pmd-go/src/test/java/net/sourceforge/pmd/lang/go/cpd/GoCpdLexerTest.java
@@ -8,9 +8,9 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
-class GoTokenizerTest extends CpdTextComparisonTest {
+class GoCpdLexerTest extends CpdTextComparisonTest {
- GoTokenizerTest() {
+ GoCpdLexerTest() {
super("go", ".go");
}
diff --git a/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/GroovyLanguageModule.java b/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/GroovyLanguageModule.java
index a740daea45..de46895863 100644
--- a/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/GroovyLanguageModule.java
+++ b/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/GroovyLanguageModule.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.groovy;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
-import net.sourceforge.pmd.lang.groovy.cpd.GroovyTokenizer;
+import net.sourceforge.pmd.lang.groovy.cpd.GroovyCpdLexer;
import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase;
/**
@@ -28,7 +28,7 @@ public class GroovyLanguageModule extends CpdOnlyLanguageModuleBase {
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new GroovyTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new GroovyCpdLexer();
}
}
diff --git a/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/ast/impl/antlr4/GroovyTokenManager.java b/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/ast/impl/antlr4/GroovyTokenManager.java
index 313f386a80..79c3b5d2da 100644
--- a/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/ast/impl/antlr4/GroovyTokenManager.java
+++ b/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/ast/impl/antlr4/GroovyTokenManager.java
@@ -7,7 +7,7 @@ package net.sourceforge.pmd.lang.groovy.ast.impl.antlr4;
import org.apache.groovy.parser.antlr4.GroovyLexer;
import net.sourceforge.pmd.lang.TokenManager;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
+import net.sourceforge.pmd.lang.ast.LexException;
import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrTokenManager;
import net.sourceforge.pmd.lang.document.TextDocument;
@@ -81,7 +81,7 @@ public class GroovyTokenManager implements TokenManager {
final int charPositionInLine,
final String msg,
final RecognitionException ex) {
- throw new TokenMgrError(line, charPositionInLine, textDoc.getFileId(), msg, ex);
+ throw new LexException(line, charPositionInLine, textDoc.getFileId(), msg, ex);
}
}
diff --git a/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyTokenizer.java b/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyCpdLexer.java
similarity index 82%
rename from pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyTokenizer.java
rename to pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyCpdLexer.java
index b180108fed..b27a2d1c44 100644
--- a/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyTokenizer.java
+++ b/pmd-groovy/src/main/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyCpdLexer.java
@@ -8,7 +8,7 @@ import java.io.IOException;
import org.apache.groovy.parser.antlr4.GroovyLexer;
-import net.sourceforge.pmd.cpd.impl.TokenizerBase;
+import net.sourceforge.pmd.cpd.impl.CpdLexerBase;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.document.TextDocument;
import net.sourceforge.pmd.lang.groovy.ast.impl.antlr4.GroovyToken;
@@ -19,8 +19,10 @@ import groovyjarjarantlr4.v4.runtime.CharStreams;
/**
* The Groovy Tokenizer
+ *
+ *
Note: This class has been called GroovyTokenizer in PMD 6
.
*/
-public class GroovyTokenizer extends TokenizerBase {
+public class GroovyCpdLexer extends CpdLexerBase {
@Override
protected final TokenManager makeLexerImpl(TextDocument doc) throws IOException {
diff --git a/pmd-groovy/src/test/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyTokenizerTest.java b/pmd-groovy/src/test/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyCpdLexerTest.java
similarity index 82%
rename from pmd-groovy/src/test/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyTokenizerTest.java
rename to pmd-groovy/src/test/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyCpdLexerTest.java
index 10570f4652..647020c363 100644
--- a/pmd-groovy/src/test/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyTokenizerTest.java
+++ b/pmd-groovy/src/test/java/net/sourceforge/pmd/lang/groovy/cpd/GroovyCpdLexerTest.java
@@ -8,9 +8,9 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
-class GroovyTokenizerTest extends CpdTextComparisonTest {
+class GroovyCpdLexerTest extends CpdTextComparisonTest {
- GroovyTokenizerTest() {
+ GroovyCpdLexerTest() {
super("groovy", ".groovy");
}
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java
index 16b3fbee78..26d02710a9 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.html;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
-import net.sourceforge.pmd.lang.html.ast.HtmlTokenizer;
+import net.sourceforge.pmd.lang.html.ast.HtmlCpdLexer;
import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase;
public final class HtmlLanguageModule extends SimpleLanguageModuleBase {
@@ -27,7 +27,7 @@ public final class HtmlLanguageModule extends SimpleLanguageModuleBase {
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new HtmlTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new HtmlCpdLexer();
}
}
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlComment.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlComment.java
index ae78e81606..5647b5ec5f 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlComment.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlComment.java
@@ -7,12 +7,15 @@ package net.sourceforge.pmd.lang.html.ast;
import org.jsoup.nodes.Comment;
-public final class ASTHtmlComment extends AbstractHtmlNode {
+import net.sourceforge.pmd.lang.rule.xpath.CommentNode;
+
+public final class ASTHtmlComment extends AbstractHtmlNode implements CommentNode {
ASTHtmlComment(Comment node) {
super(node);
}
+ @Override
public String getData() {
return node.getData();
}
@@ -21,4 +24,9 @@ public final class ASTHtmlComment extends AbstractHtmlNode {
protected
R acceptHtmlVisitor(HtmlVisitor super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
+
+ @Override
+ public String getXPathNodeName() {
+ return CommentNode.super.getXPathNodeName();
+ }
}
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlTextNode.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlTextNode.java
index 524a8a931e..a9d2327a97 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlTextNode.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/ASTHtmlTextNode.java
@@ -7,7 +7,7 @@ package net.sourceforge.pmd.lang.html.ast;
import org.jsoup.nodes.TextNode;
-public class ASTHtmlTextNode extends AbstractHtmlNode {
+public class ASTHtmlTextNode extends AbstractHtmlNode implements net.sourceforge.pmd.lang.rule.xpath.TextNode {
ASTHtmlTextNode(TextNode node) {
super(node);
@@ -18,16 +18,17 @@ public class ASTHtmlTextNode extends AbstractHtmlNode {
return visitor.visit(this, data);
}
- public String getNormalizedText() {
- return node.text();
- }
-
- public String getText() {
+ public String getWholeText() {
return node.getWholeText();
}
@Override
- public String getImage() {
- return getNormalizedText();
+ public String getText() {
+ return node.text();
+ }
+
+ @Override
+ public String getXPathNodeName() {
+ return net.sourceforge.pmd.lang.rule.xpath.TextNode.super.getXPathNodeName();
}
}
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/AbstractHtmlNode.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/AbstractHtmlNode.java
index bd45efd915..70f7c0396b 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/AbstractHtmlNode.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/AbstractHtmlNode.java
@@ -27,6 +27,7 @@ abstract class AbstractHtmlNode extends AbstractNodeNote: This class has been called HtmlTokenizer in PMD 6
.
+ */
+public class HtmlCpdLexer implements CpdLexer {
@Override
public void tokenize(TextDocument document, TokenFactory tokens) {
@@ -45,7 +48,7 @@ public class HtmlTokenizer implements Tokenizer {
String image = node.getXPathNodeName();
if (node instanceof ASTHtmlTextNode) {
- image = ((ASTHtmlTextNode) node).getText();
+ image = ((ASTHtmlTextNode) node).getWholeText();
}
tokenEntries.recordToken(image, node.getReportLocation());
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/LineNumbers.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/LineNumbers.java
index d7ae63af8b..423b2772fb 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/LineNumbers.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/LineNumbers.java
@@ -37,7 +37,7 @@ class LineNumbers {
} else if (n instanceof ASTHtmlXmlDeclaration) {
nextIndex = htmlString.indexOf("", nextIndex);
} else if (n instanceof ASTHtmlTextNode) {
- textLength = ((ASTHtmlTextNode) n).getText().length();
+ textLength = ((ASTHtmlTextNode) n).getWholeText().length();
} else if (n instanceof ASTHtmlDocumentType) {
nextIndex = index;
}
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/AbstractHtmlRule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/AbstractHtmlRule.java
index 3740d51245..02765e6119 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/AbstractHtmlRule.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/AbstractHtmlRule.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.html.rule;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.html.ast.HtmlVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
+import net.sourceforge.pmd.reporting.RuleContext;
public abstract class AbstractHtmlRule extends AbstractRule implements HtmlVisitor {
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UnnecessaryTypeAttributeRule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UnnecessaryTypeAttributeRule.java
index b24cadff59..b2b692c19c 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UnnecessaryTypeAttributeRule.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UnnecessaryTypeAttributeRule.java
@@ -4,9 +4,9 @@
package net.sourceforge.pmd.lang.html.rule.bestpractices;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.html.ast.ASTHtmlElement;
import net.sourceforge.pmd.lang.html.rule.AbstractHtmlRule;
+import net.sourceforge.pmd.reporting.RuleContext;
public class UnnecessaryTypeAttributeRule extends AbstractHtmlRule {
diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UseAltAttributeForImagesRule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UseAltAttributeForImagesRule.java
index 3cab721591..a4219abcd4 100644
--- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UseAltAttributeForImagesRule.java
+++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/rule/bestpractices/UseAltAttributeForImagesRule.java
@@ -8,10 +8,10 @@ import java.util.Arrays;
import org.checkerframework.checker.nullness.qual.NonNull;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.html.ast.ASTHtmlElement;
import net.sourceforge.pmd.lang.html.rule.AbstractHtmlRule;
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
+import net.sourceforge.pmd.reporting.RuleContext;
public class UseAltAttributeForImagesRule extends AbstractHtmlRule {
diff --git a/pmd-html/src/main/resources/category/html/bestpractices.xml b/pmd-html/src/main/resources/category/html/bestpractices.xml
index 775e366565..0307f26ed3 100644
--- a/pmd-html/src/main/resources/category/html/bestpractices.xml
+++ b/pmd-html/src/main/resources/category/html/bestpractices.xml
@@ -13,7 +13,7 @@ Rules which enforce generally accepted best practices.
language="html"
since="6.45.0"
message="Avoid inline styles"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_html_bestpractices.html#avoidinlinestyles">
Don't mix content and style. Use separate CSS-files for the style and introduce classes.
@@ -21,7 +21,6 @@ This helps to reuse common styles.
3
-
Note: This class has been called JavaTokenizer in PMD 6
.
+ */
+public class JavaCpdLexer extends JavaccCpdLexer {
private static final String CPD_START = "\"CPD-START\"";
private static final String CPD_END = "\"CPD-END\"";
@@ -32,7 +35,7 @@ public class JavaTokenizer extends JavaCCTokenizer {
private final ConstructorDetector constructorDetector;
- public JavaTokenizer(JavaLanguageProperties properties) {
+ public JavaCpdLexer(JavaLanguageProperties properties) {
ignoreAnnotations = properties.getProperty(CpdLanguageProperties.CPD_IGNORE_METADATA);
ignoreLiterals = properties.getProperty(CpdLanguageProperties.CPD_ANONYMIZE_LITERALS);
ignoreIdentifiers = properties.getProperty(CpdLanguageProperties.CPD_ANONYMIZE_IDENTIFIERS);
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/AnnotationSuppressionUtil.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/AnnotationSuppressionUtil.java
index 4de993d333..0713ee67fb 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/AnnotationSuppressionUtil.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/AnnotationSuppressionUtil.java
@@ -14,11 +14,6 @@ import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-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.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
@@ -32,6 +27,11 @@ import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.Annotatable;
import net.sourceforge.pmd.lang.java.rule.errorprone.ImplicitSwitchFallThroughRule;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
+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;
/**
* Helper methods to suppress violations based on annotations.
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageProcessor.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageProcessor.java
index 020fe79ed0..9fdbfb1f94 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageProcessor.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageProcessor.java
@@ -11,7 +11,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.ViolationSuppressor;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.ast.Parser;
import net.sourceforge.pmd.lang.impl.BatchLanguageProcessor;
@@ -30,6 +29,7 @@ import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger.Ve
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler;
import net.sourceforge.pmd.reporting.ViolationDecorator;
+import net.sourceforge.pmd.reporting.ViolationSuppressor;
import net.sourceforge.pmd.util.designerbindings.DesignerBindings;
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecorator.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecorator.java
index 0346f11e40..0e6a022bc7 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecorator.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecorator.java
@@ -11,7 +11,6 @@ import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTExecutableDeclaration;
@@ -25,6 +24,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.ModifierOwner;
+import net.sourceforge.pmd.reporting.RuleViolation;
import net.sourceforge.pmd.reporting.ViolationDecorator;
import net.sourceforge.pmd.util.IteratorUtil;
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java
index f230d40b2a..df5911239a 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.java.rule;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.JavaParserVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorClassGenerationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorClassGenerationRule.java
index 8eda6abc2d..076a152161 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorClassGenerationRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorClassGenerationRule.java
@@ -7,11 +7,11 @@ package net.sourceforge.pmd.lang.java.rule.bestpractices;
import java.util.HashSet;
import java.util.Set;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorCall;
import net.sourceforge.pmd.lang.java.ast.ASTExplicitConstructorInvocation;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* 1. Note all private constructors. 2. Note all instantiations from outside of
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorMethodGenerationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorMethodGenerationRule.java
index 103e8ab341..0313d95be8 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorMethodGenerationRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AccessorMethodGenerationRule.java
@@ -9,7 +9,6 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTFieldAccess;
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
@@ -21,6 +20,7 @@ import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
import net.sourceforge.pmd.lang.java.symbols.JFieldSymbol;
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
import net.sourceforge.pmd.lang.java.symbols.JVariableSymbol;
+import net.sourceforge.pmd.reporting.RuleContext;
public class AccessorMethodGenerationRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ArrayIsStoredDirectlyRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ArrayIsStoredDirectlyRule.java
index 129b16f31b..91d02008d0 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ArrayIsStoredDirectlyRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ArrayIsStoredDirectlyRule.java
@@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.java.rule.bestpractices;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.AccessType;
@@ -18,6 +17,7 @@ import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* If a method or constructor receives an array as an argument, the array should
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidReassigningLoopVariablesRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidReassigningLoopVariablesRule.java
index 312f0c57b3..7a03e07422 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidReassigningLoopVariablesRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidReassigningLoopVariablesRule.java
@@ -9,7 +9,6 @@ import static net.sourceforge.pmd.properties.PropertyFactory.enumProperty;
import java.util.Set;
import java.util.stream.Collectors;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.NodeStream;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.AccessType;
@@ -32,6 +31,7 @@ import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
import net.sourceforge.pmd.util.StringUtil.CaseConvention;
public class AvoidReassigningLoopVariablesRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidUsingHardCodedIPRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidUsingHardCodedIPRule.java
index 12cee297b9..521ce07289 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidUsingHardCodedIPRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidUsingHardCodedIPRule.java
@@ -14,11 +14,11 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTStringLiteral;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
public class AvoidUsingHardCodedIPRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardLogStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardLogStatementRule.java
index ab032b55b4..1301e2a403 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardLogStatementRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/GuardLogStatementRule.java
@@ -14,7 +14,6 @@ import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
@@ -32,6 +31,7 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.symbols.JVariableSymbol;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* Check that log.debug, log.trace, log.error, etc... statements are guarded by
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/LiteralsFirstInComparisonsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/LiteralsFirstInComparisonsRule.java
index c5de8e0bc5..82d657c985 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/LiteralsFirstInComparisonsRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/LiteralsFirstInComparisonsRule.java
@@ -12,7 +12,6 @@ import java.util.Set;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
@@ -21,6 +20,7 @@ import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.symbols.JFieldSymbol;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
+import net.sourceforge.pmd.reporting.RuleContext;
public class LiteralsFirstInComparisonsRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedAssignmentRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedAssignmentRule.java
index 35356b3077..bf08375a42 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedAssignmentRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedAssignmentRule.java
@@ -12,7 +12,6 @@ import java.util.Set;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.ASTExpressionStatement;
import net.sourceforge.pmd.lang.java.ast.ASTForeachStatement;
@@ -27,6 +26,7 @@ import net.sourceforge.pmd.lang.java.rule.internal.DataflowPass.DataflowResult;
import net.sourceforge.pmd.lang.java.rule.internal.JavaRuleUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
public class UnusedAssignmentRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/CommentDefaultAccessModifierRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/CommentDefaultAccessModifierRule.java
index 516b810b81..dee9921d2d 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/CommentDefaultAccessModifierRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/CommentDefaultAccessModifierRule.java
@@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.rule.codestyle;
import java.util.List;
import java.util.regex.Pattern;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
@@ -24,6 +23,7 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.rule.internal.JavaPropertyUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* Check for Methods, Fields and Nested Classes that have a default access
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LocalVariableCouldBeFinalRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LocalVariableCouldBeFinalRule.java
index bce9bbd470..47bc0b8846 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LocalVariableCouldBeFinalRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/LocalVariableCouldBeFinalRule.java
@@ -6,11 +6,11 @@ package net.sourceforge.pmd.lang.java.rule.codestyle;
import static net.sourceforge.pmd.properties.PropertyFactory.booleanProperty;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTForeachStatement;
import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
public class LocalVariableCouldBeFinalRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/MethodArgumentCouldBeFinalRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/MethodArgumentCouldBeFinalRule.java
index 674dd28f5b..efbb5102a4 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/MethodArgumentCouldBeFinalRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/MethodArgumentCouldBeFinalRule.java
@@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.java.rule.codestyle;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.NodeStream;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.AccessType;
@@ -14,6 +13,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
+import net.sourceforge.pmd.reporting.RuleContext;
public class MethodArgumentCouldBeFinalRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryBoxingRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryBoxingRule.java
index b2f7c9cf9c..f603b9b66c 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryBoxingRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryBoxingRule.java
@@ -10,7 +10,6 @@ import java.util.Set;
import org.apache.commons.lang3.StringUtils;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorCall;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTList;
@@ -23,6 +22,7 @@ import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult;
import net.sourceforge.pmd.lang.java.types.TypePrettyPrint;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
import net.sourceforge.pmd.lang.java.types.ast.ExprContext;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
*
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/DataClassRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/DataClassRule.java
index 54489d5818..a17517fc66 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/DataClassRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/DataClassRule.java
@@ -9,11 +9,11 @@ import static net.sourceforge.pmd.lang.java.metrics.JavaMetrics.NUMBER_OF_PUBLIC
import static net.sourceforge.pmd.lang.java.metrics.JavaMetrics.WEIGHED_METHOD_COUNT;
import static net.sourceforge.pmd.lang.java.metrics.JavaMetrics.WEIGHT_OF_CLASS;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.metrics.MetricsUtil;
+import net.sourceforge.pmd.reporting.RuleContext;
import net.sourceforge.pmd.util.StringUtil;
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java
index 0bb3f96b71..092518fcc8 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java
@@ -21,7 +21,6 @@ import java.util.stream.Stream;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
import net.sourceforge.pmd.lang.java.ast.ASTArrayAccess;
@@ -56,6 +55,7 @@ import net.sourceforge.pmd.lang.java.types.TypeOps;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* This rule can detect possible violations of the Law of Demeter. The Law of
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NPathComplexityRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NPathComplexityRule.java
index a0bc8cbb7c..fa1237ad4e 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NPathComplexityRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NPathComplexityRule.java
@@ -8,7 +8,6 @@ import static net.sourceforge.pmd.properties.NumericConstraints.positive;
import java.math.BigInteger;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTExecutableDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
@@ -18,6 +17,7 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.metrics.MetricsUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssCountRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssCountRule.java
index 832eabb150..acb77e82fb 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssCountRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NcssCountRule.java
@@ -10,7 +10,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTExecutableDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
@@ -23,6 +22,7 @@ import net.sourceforge.pmd.lang.metrics.MetricOptions;
import net.sourceforge.pmd.lang.metrics.MetricsUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
import net.sourceforge.pmd.util.AssertionUtil;
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java
index ae0a84cd17..300fa40cff 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java
@@ -22,7 +22,6 @@ import java.util.Set;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTBlock;
import net.sourceforge.pmd.lang.java.ast.ASTCastExpression;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
@@ -36,6 +35,7 @@ import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.types.JPrimitiveType.PrimitiveTypeKind;
+import net.sourceforge.pmd.reporting.RuleContext;
public class SimplifyBooleanReturnsRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentContentRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentContentRule.java
index 63feecfabc..ec354ee05d 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentContentRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentContentRule.java
@@ -8,13 +8,13 @@ import static net.sourceforge.pmd.properties.PropertyFactory.regexProperty;
import java.util.regex.Pattern;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.document.Chars;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.JavaComment;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* A rule that checks for illegal words in the comment text.
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredRule.java
index 1b92c15afe..00a92e335e 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredRule.java
@@ -12,7 +12,6 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
@@ -28,6 +27,7 @@ import net.sourceforge.pmd.lang.java.rule.internal.JavaRuleUtil;
import net.sourceforge.pmd.properties.PropertyBuilder.GenericPropertyBuilder;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
import net.sourceforge.pmd.util.CollectionUtil;
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java
index ff0d0fe622..d9820a1bf9 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentSizeRule.java
@@ -6,13 +6,13 @@ package net.sourceforge.pmd.lang.java.rule.documentation;
import static net.sourceforge.pmd.properties.NumericConstraints.positive;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.document.Chars;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.JavaComment;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* A rule to manage those who just can't shut up...
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AssignmentInOperandRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AssignmentInOperandRule.java
index 33d2310c08..a638fafc31 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AssignmentInOperandRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AssignmentInOperandRule.java
@@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.java.rule.errorprone;
import static net.sourceforge.pmd.properties.PropertyFactory.booleanProperty;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTAssignmentExpression;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTExpressionStatement;
@@ -19,6 +18,7 @@ import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertySource;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
*
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidDuplicateLiteralsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidDuplicateLiteralsRule.java
index 095d8ef855..6551ac5763 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidDuplicateLiteralsRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidDuplicateLiteralsRule.java
@@ -18,12 +18,12 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
import net.sourceforge.pmd.lang.java.ast.ASTStringLiteral;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
public class AvoidDuplicateLiteralsRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BrokenNullCheckRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BrokenNullCheckRule.java
index 2704a3c352..b344a9d674 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BrokenNullCheckRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BrokenNullCheckRule.java
@@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.java.rule.errorprone;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.NodeStream;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTInfixExpression;
@@ -14,6 +13,7 @@ import net.sourceforge.pmd.lang.java.ast.QualifiableExpression;
import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.rule.internal.StablePathMatcher;
+import net.sourceforge.pmd.reporting.RuleContext;
public class BrokenNullCheckRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java
index aa31c6b978..7a95414dc1 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/CloseResourceRule.java
@@ -15,7 +15,6 @@ import java.util.Set;
import org.checkerframework.checker.nullness.qual.Nullable;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
@@ -54,6 +53,7 @@ import net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol;
import net.sourceforge.pmd.lang.java.types.InvocationMatcher;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* Makes sure you close your database connections. It does this by looking for
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ConstructorCallsOverridableMethodRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ConstructorCallsOverridableMethodRule.java
index 4ef336e6dc..8f5c41369d 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ConstructorCallsOverridableMethodRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ConstructorCallsOverridableMethodRule.java
@@ -18,7 +18,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.pcollections.PVector;
import org.pcollections.TreePVector;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.NodeStream;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
@@ -31,6 +30,7 @@ import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol;
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
import net.sourceforge.pmd.lang.java.types.JMethodSig;
import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonSerializableClassRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonSerializableClassRule.java
index 91067c4ad7..136a68799c 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonSerializableClassRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonSerializableClassRule.java
@@ -16,7 +16,6 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration;
@@ -41,6 +40,7 @@ import net.sourceforge.pmd.lang.java.types.JTypeMirror;
import net.sourceforge.pmd.lang.java.types.JTypeVar;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
// Note: This rule has been formerly known as "BeanMembersShouldSerialize".
public class NonSerializableClassRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/TypeResTestRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/TypeResTestRule.java
index 00908a858b..886dade7b8 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/TypeResTestRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/TypeResTestRule.java
@@ -7,13 +7,13 @@ package net.sourceforge.pmd.lang.java.rule.internal;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.nullness.qual.NonNull;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.TypeNode;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
import net.sourceforge.pmd.lang.java.types.JTypeMirror;
import net.sourceforge.pmd.lang.java.types.TypeSystem;
+import net.sourceforge.pmd.reporting.RuleContext;
import net.sourceforge.pmd.util.StringUtil;
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/NonThreadSafeSingletonRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/NonThreadSafeSingletonRule.java
index 4504e020c5..6ba0fd13a4 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/NonThreadSafeSingletonRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/multithreading/NonThreadSafeSingletonRule.java
@@ -10,7 +10,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.ast.ASTAssignmentExpression;
@@ -25,6 +24,7 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.symbols.JFieldSymbol;
import net.sourceforge.pmd.lang.java.symbols.JVariableSymbol;
import net.sourceforge.pmd.properties.PropertyDescriptor;
+import net.sourceforge.pmd.reporting.RuleContext;
public class NonThreadSafeSingletonRule extends AbstractJavaRulechainRule {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java
index 3fb929529f..281aeec65c 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InefficientStringBufferingRule.java
@@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.java.rule.performance;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorCall;
@@ -14,6 +13,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
import net.sourceforge.pmd.lang.java.rule.internal.JavaRuleUtil;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* How this rule works: find additive expressions: + check that the addition is
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseContextNodeTestFun.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseContextNodeTestFun.java
index 2338c47e3a..3cd1a88f0a 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseContextNodeTestFun.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseContextNodeTestFun.java
@@ -6,19 +6,10 @@ package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import java.util.function.BiPredicate;
-import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.Annotatable;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.TypeNode;
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
-import net.sourceforge.pmd.lang.rule.xpath.internal.AstElementNode;
-
-import net.sf.saxon.expr.XPathContext;
-import net.sf.saxon.lib.ExtensionFunctionCall;
-import net.sf.saxon.om.Sequence;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.value.BooleanValue;
-import net.sf.saxon.value.SequenceType;
/**
* XPath function {@code pmd-java:typeIs(typeName as xs:string) as xs:boolean}
@@ -30,7 +21,7 @@ import net.sf.saxon.value.SequenceType;
*/
public class BaseContextNodeTestFun extends BaseJavaXPathFunction {
- static final SequenceType[] SINGLE_STRING_SEQ = {SequenceType.SINGLE_STRING};
+ static final Type[] SINGLE_STRING_SEQ = {Type.SINGLE_STRING};
private final Class klass;
private final BiPredicate checker;
@@ -45,31 +36,25 @@ public class BaseContextNodeTestFun extends BaseJavaXPathFun
}
@Override
- public SequenceType[] getArgumentTypes() {
+ public Type[] getArgumentTypes() {
return SINGLE_STRING_SEQ;
}
@Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.SINGLE_BOOLEAN;
+ public Type getResultType() {
+ return Type.SINGLE_BOOLEAN;
}
@Override
- public boolean dependsOnFocus() {
+ public boolean dependsOnContext() {
return true;
}
@Override
- public ExtensionFunctionCall makeCallExpression() {
- return new ExtensionFunctionCall() {
- @Override
- public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
- Node contextNode = ((AstElementNode) context.getContextItem()).getUnderlyingNode();
- String fullTypeName = arguments[0].head().getStringValue();
-
-
- return BooleanValue.get(klass.isInstance(contextNode) && checker.test(fullTypeName, (T) contextNode));
- }
+ public FunctionCall makeCallExpression() {
+ return (contextNode, arguments) -> {
+ String fullTypeName = arguments[0].toString();
+ return klass.isInstance(contextNode) && checker.test(fullTypeName, (T) contextNode);
};
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseJavaXPathFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseJavaXPathFunction.java
index 450a33013e..e8927bde54 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseJavaXPathFunction.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseJavaXPathFunction.java
@@ -5,9 +5,9 @@
package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
-import net.sourceforge.pmd.lang.rule.xpath.impl.AbstractXPathFunctionDef;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionDefinition;
-abstract class BaseJavaXPathFunction extends AbstractXPathFunctionDef {
+abstract class BaseJavaXPathFunction extends XPathFunctionDefinition {
protected BaseJavaXPathFunction(String localName) {
super(localName, JavaLanguageModule.getInstance());
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseRewrittenFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseRewrittenFunction.java
index f2f1e4c768..0f81232666 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseRewrittenFunction.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseRewrittenFunction.java
@@ -7,17 +7,7 @@ package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import static net.sourceforge.pmd.lang.java.rule.xpath.internal.BaseContextNodeTestFun.SINGLE_STRING_SEQ;
import net.sourceforge.pmd.lang.ast.Node;
-import net.sourceforge.pmd.lang.rule.xpath.internal.AstElementNode;
-
-import net.sf.saxon.expr.Expression;
-import net.sf.saxon.expr.StaticContext;
-import net.sf.saxon.expr.StringLiteral;
-import net.sf.saxon.expr.XPathContext;
-import net.sf.saxon.lib.ExtensionFunctionCall;
-import net.sf.saxon.om.Sequence;
-import net.sf.saxon.trans.XPathException;
-import net.sf.saxon.value.BooleanValue;
-import net.sf.saxon.value.SequenceType;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionException;
/**
@@ -39,17 +29,17 @@ abstract class BaseRewrittenFunction extends BaseJavaXPathFun
}
@Override
- public SequenceType[] getArgumentTypes() {
+ public Type[] getArgumentTypes() {
return SINGLE_STRING_SEQ;
}
@Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.SINGLE_BOOLEAN;
+ public Type getResultType() {
+ return Type.SINGLE_BOOLEAN;
}
@Override
- public boolean dependsOnFocus() {
+ public boolean dependsOnContext() {
return true;
}
@@ -59,7 +49,7 @@ abstract class BaseRewrittenFunction extends BaseJavaXPathFun
* if the arg is constant, otherwise it's anyway called before {@link #matches(Node, String, Object, boolean)}
* is called.
*/
- protected abstract S parseArgument(String arg) throws XPathException;
+ protected abstract S parseArgument(String arg) throws XPathFunctionException;
/**
* Compute the result of the function.
@@ -71,48 +61,40 @@ abstract class BaseRewrittenFunction extends BaseJavaXPathFun
*
* @return Whether the function matches
*/
- protected abstract boolean matches(N contextNode, String arg, S parsedArg, boolean isConstant) throws XPathException;
+ protected abstract boolean matches(N contextNode, String arg, S parsedArg, boolean isConstant) throws XPathFunctionException;
@Override
- public ExtensionFunctionCall makeCallExpression() {
- return new ExtensionFunctionCall() {
+ public FunctionCall makeCallExpression() {
+ return new FunctionCall() {
private S constantState;
private boolean isConstant;
@Override
- public Expression rewrite(StaticContext context, Expression[] arguments) throws XPathException {
- // If the argument is a string literal then we can preload
- // the class, and check that it's valid at expression build time
+ public void staticInit(Object[] arguments) throws XPathFunctionException {
+ if (arguments[0] instanceof String) {
+ // If the argument was a string literal then we can preload
+ // the class, and check that it's valid at expression build time
- Expression firstArg = arguments[0]; // this expression has been type checked so there is an argument
- if (firstArg instanceof StringLiteral) {
- String name = ((StringLiteral) firstArg).getStringValue();
- try {
- constantState = parseArgument(name);
- } catch (XPathException e) {
- e.setIsStaticError(true);
- throw e;
- }
+ String name = (String) arguments[0]; // this expression has been type checked so there is an argument
+ constantState = parseArgument(name);
isConstant = true;
}
- return null;
}
@Override
- public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
- Node node = ((AstElementNode) context.getContextItem()).getUnderlyingNode();
+ public Boolean call(Node node, Object[] arguments) throws XPathFunctionException {
if (!contextNodeType.isInstance(node)) {
// we could report that as an error
- return BooleanValue.FALSE;
+ return false;
}
- String arg = arguments[0].head().getStringValue();
+ String arg = arguments[0].toString();
S parsedArg = isConstant ? constantState
: parseArgument(arg);
- return BooleanValue.get(matches((N) node, arg, parsedArg, isConstant));
+ return matches((N) node, arg, parsedArg, isConstant);
}
};
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetCommentOnFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetCommentOnFunction.java
index 6a3169fae8..6a45b987ba 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetCommentOnFunction.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetCommentOnFunction.java
@@ -5,19 +5,11 @@
package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import java.util.List;
+import java.util.Optional;
-import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.document.FileLocation;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.JavaComment;
-import net.sourceforge.pmd.lang.rule.xpath.internal.AstElementNode;
-
-import net.sf.saxon.expr.XPathContext;
-import net.sf.saxon.lib.ExtensionFunctionCall;
-import net.sf.saxon.om.EmptyAtomicSequence;
-import net.sf.saxon.om.Sequence;
-import net.sf.saxon.value.SequenceType;
-import net.sf.saxon.value.StringValue;
/**
@@ -37,43 +29,31 @@ public class GetCommentOnFunction extends BaseJavaXPathFunction {
}
@Override
- public SequenceType[] getArgumentTypes() {
- return new SequenceType[0];
+ public Type getResultType() {
+ return Type.OPTIONAL_STRING;
}
@Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.OPTIONAL_STRING;
- }
-
-
- @Override
- public boolean dependsOnFocus() {
+ public boolean dependsOnContext() {
return true;
}
@Override
- public ExtensionFunctionCall makeCallExpression() {
- return new ExtensionFunctionCall() {
- @Override
- public Sequence call(XPathContext context, Sequence[] arguments) {
- Node contextNode = ((AstElementNode) context.getContextItem()).getUnderlyingNode();
+ public FunctionCall makeCallExpression() {
+ return (contextNode, arguments) -> {
+ int codeBeginLine = contextNode.getBeginLine();
+ int codeEndLine = contextNode.getEndLine();
- int codeBeginLine = contextNode.getBeginLine();
- int codeEndLine = contextNode.getEndLine();
-
- List commentList = contextNode.ancestorsOrSelf().filterIs(ASTCompilationUnit.class).first().getComments();
- for (JavaComment comment : commentList) {
- FileLocation location = comment.getReportLocation();
- if (location.getStartLine() == codeBeginLine || location.getEndLine() == codeEndLine) {
- return new StringValue(comment.getText());
- }
+ List commentList = contextNode.ancestorsOrSelf().filterIs(ASTCompilationUnit.class).first().getComments();
+ for (JavaComment comment : commentList) {
+ FileLocation location = comment.getReportLocation();
+ if (location.getStartLine() == codeBeginLine || location.getEndLine() == codeEndLine) {
+ return Optional.of(comment.getText().toString());
}
- return EmptyAtomicSequence.INSTANCE;
}
-
+ return Optional.empty();
};
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFun.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFun.java
index 501427045b..52c32bc3ad 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFun.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFun.java
@@ -4,29 +4,19 @@
package net.sourceforge.pmd.lang.java.rule.xpath.internal;
+import java.util.Collections;
import java.util.Set;
-import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTModifierList;
import net.sourceforge.pmd.lang.java.ast.JModifier;
import net.sourceforge.pmd.lang.java.ast.ModifierOwner;
-import net.sourceforge.pmd.lang.rule.xpath.internal.AstElementNode;
import net.sourceforge.pmd.util.CollectionUtil;
-import net.sf.saxon.expr.XPathContext;
-import net.sf.saxon.lib.ExtensionFunctionCall;
-import net.sf.saxon.om.Sequence;
-import net.sf.saxon.value.EmptySequence;
-import net.sf.saxon.value.SequenceExtent;
-import net.sf.saxon.value.SequenceType;
-import net.sf.saxon.value.StringValue;
-
/**
* The two functions {@code modifiers} and {@code explicitModifiers}.
*/
public final class GetModifiersFun extends BaseJavaXPathFunction {
- private static final SequenceType[] ARGTYPES = {};
private final boolean explicit;
public static final GetModifiersFun GET_EFFECTIVE = new GetModifiersFun("modifiers", false);
@@ -38,36 +28,25 @@ public final class GetModifiersFun extends BaseJavaXPathFunction {
}
@Override
- public SequenceType[] getArgumentTypes() {
- return ARGTYPES;
+ public Type getResultType() {
+ return Type.STRING_SEQUENCE;
}
@Override
- public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
- return SequenceType.STRING_SEQUENCE;
- }
-
- @Override
- public boolean dependsOnFocus() {
+ public boolean dependsOnContext() {
return true;
}
@Override
- public ExtensionFunctionCall makeCallExpression() {
- return new ExtensionFunctionCall() {
- @Override
- public Sequence call(XPathContext context, Sequence[] arguments) {
- Node contextNode = ((AstElementNode) context.getContextItem()).getUnderlyingNode();
-
- if (contextNode instanceof ModifierOwner) {
- ASTModifierList modList = ((ModifierOwner) contextNode).getModifiers();
- Set mods = explicit ? modList.getExplicitModifiers()
- : modList.getEffectiveModifiers();
- return new SequenceExtent(CollectionUtil.map(mods, mod -> new StringValue(mod.getToken())));
- } else {
- return EmptySequence.getInstance();
- }
+ public FunctionCall makeCallExpression() {
+ return (contextNode, arguments) -> {
+ if (contextNode instanceof ModifierOwner) {
+ ASTModifierList modList = ((ModifierOwner) contextNode).getModifiers();
+ Set mods = explicit ? modList.getExplicitModifiers()
+ : modList.getEffectiveModifiers();
+ return CollectionUtil.map(mods, JModifier::getToken);
}
+ return Collections.emptyList();
};
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureFunction.java
index 187d100612..7e74e78026 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureFunction.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureFunction.java
@@ -6,8 +6,7 @@ package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import net.sourceforge.pmd.lang.java.ast.InvocationNode;
import net.sourceforge.pmd.lang.java.types.InvocationMatcher;
-
-import net.sf.saxon.trans.XPathException;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionException;
public final class MatchesSignatureFunction extends BaseRewrittenFunction {
@@ -18,16 +17,16 @@ public final class MatchesSignatureFunction extends BaseRewrittenFunction {
+ String metricKey = arguments[0].toString();
+ return getMetric(contextNode, metricKey);
};
}
@@ -78,16 +63,16 @@ public final class MetricFunction extends BaseJavaXPathFunction {
}
- private static double getMetric(Node n, String metricKeyName) throws XPathException {
+ private static Optional getMetric(Node n, String metricKeyName) throws XPathFunctionException {
LanguageMetricsProvider provider =
n.getAstInfo().getLanguageProcessor().services().getLanguageMetricsProvider();
Metric, ?> metric = provider.getMetricWithName(metricKeyName);
if (metric == null) {
- throw new XPathException(badMetricKeyMessage(metricKeyName));
+ throw new XPathFunctionException(badMetricKeyMessage(metricKeyName));
}
Number computed = Metric.compute(metric, n, MetricOptions.emptyOptions());
- return computed == null ? Double.NaN : computed.doubleValue();
+ return computed == null ? Optional.empty() : Optional.of(computed.doubleValue());
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunction.java
index 0b30a1f0f1..98dce04f8f 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunction.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunction.java
@@ -5,8 +5,7 @@
package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
-
-import net.sf.saxon.trans.XPathException;
+import net.sourceforge.pmd.lang.rule.xpath.impl.XPathFunctionException;
public final class NodeIsFunction extends BaseRewrittenFunction, JavaNode> {
@@ -17,16 +16,16 @@ public final class NodeIsFunction extends BaseRewrittenFunction, JavaNo
}
@Override
- protected Class> parseArgument(String arg) throws XPathException {
+ protected Class> parseArgument(String arg) throws XPathFunctionException {
try {
return Class.forName("net.sourceforge.pmd.lang.java.ast.AST" + arg);
} catch (ClassNotFoundException e) {
- throw new XPathException("No class named AST" + arg);
+ throw new XPathFunctionException("No class named AST" + arg, e);
}
}
@Override
- protected boolean matches(JavaNode contextNode, String arg, Class> parsedArg, boolean isConstant) throws XPathException {
+ protected boolean matches(JavaNode contextNode, String arg, Class> parsedArg, boolean isConstant) {
return parsedArg.isInstance(contextNode);
}
diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml
index 3da6e337ca..03ed6fd517 100644
--- a/pmd-java/src/main/resources/category/java/bestpractices.xml
+++ b/pmd-java/src/main/resources/category/java/bestpractices.xml
@@ -133,7 +133,7 @@ public class Foo {
language="java"
since="6.18.0"
message="You shouldn't declare field of MessageDigest type, because unsynchronized access could cause problems"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#avoidmessagedigestfield">
Declaring a MessageDigest instance as a field make this instance directly available to multiple threads.
@@ -183,7 +183,7 @@ public class AvoidMessageDigestFieldExample {
language="java"
since="3.2"
message="Avoid printStackTrace(); use a logger call instead."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#avoidprintstacktrace">
Avoid printStackTrace(); use a logger call instead.
@@ -336,7 +336,7 @@ public class Hello {
language="java"
since="4.2"
message="StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time)."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#avoidstringbufferfield">
StringBuffers/StringBuilders can grow considerably, and so may become a source of memory leaks
@@ -414,7 +414,7 @@ if (rst.next()) { // result is properly examined and used
language="java"
since="5.5"
message="Using constants in interfaces is a bad practice."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#constantsininterface">
Using constants in interfaces is a bad practice. Interfaces define types, constants are implementation details better placed in classes or enums. If the constants are best viewed as members of an enumerated type, you should export them with an enum type.
@@ -461,7 +461,7 @@ public interface YetAnotherConstantInterface {
language="java"
since="1.5"
message="The default label should be the last label in a switch statement"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#defaultlabelnotlastinswitchstmt">
By convention, the default label should be the last label in a switch statement.
@@ -498,7 +498,7 @@ public class Foo {
language="java"
since="6.16.0"
message="Double-brace initialization should be avoided"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#doublebraceinitialization">
Double brace initialisation is a pattern to initialise eg collections concisely. But it implicitly
@@ -572,7 +572,7 @@ public class MyClass {
language="java"
since="6.11.0"
message="Too many control variables in the 'for' statement"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#forloopvariablecount">
Having a lot of control variables in a 'for' loop makes it harder to see what range of values
@@ -632,7 +632,7 @@ log.debug("log something expensive: {}", () -> calculateExpensiveLoggingText());
language="java"
since="4.0"
message="JUnit 4 indicates test suites via annotations, not the suite method."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit4suitesshouldusesuiteannotation">
In JUnit 3, test suites are indicated by the suite() method. In JUnit 4, suites are indicated
@@ -670,7 +670,7 @@ public class GoodTest {
language="java"
since="4.0"
message="JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit4testshoulduseafterannotation">
In JUnit 3, the tearDown method was used to clean up all data entities required in running tests.
@@ -714,7 +714,7 @@ public class MyTest2 {
language="java"
since="4.0"
message="JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit4testshouldusebeforeannotation">
In JUnit 3, the setUp method was used to set up all data entities required in running tests.
@@ -759,7 +759,7 @@ public class MyTest2 {
language="java"
since="4.0"
message="Unit tests that execute tests should use the @Test annotation. In case of JUnit 5, test methods might use @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest annotations instead."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit4testshouldusetestannotation">
In JUnit 3, the framework executed all methods which started with the word test as a unit test.
@@ -813,7 +813,7 @@ public class MyTest {
language="java"
since="6.35.0"
message="JUnit 5 tests should be package-private."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#junit5testshouldbepackageprivate">
3
-
@@ -1242,7 +1241,7 @@ public class Foo {
language="java"
since="3.4"
message="Consider replacing this Enumeration with the newer java.util.Iterator"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#replaceenumerationwithiterator">
Consider replacing Enumeration usages with the newer java.util.Iterator
@@ -1276,7 +1275,7 @@ public class Foo implements Enumeration {
language="java"
since="3.4"
message="Consider replacing this Hashtable with the newer java.util.Map"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#replacehashtablewithmap">
Consider replacing Hashtable usage with the newer java.util.Map if thread safety is not required.
@@ -1304,7 +1303,7 @@ public class Foo {
language="java"
since="3.4"
message="Consider replacing this Vector with the newer java.util.List"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#replacevectorwithlist">
Consider replacing Vector usages with the newer java.util.ArrayList if expensive thread-safe operations are not required.
@@ -1370,7 +1369,7 @@ class SomeTestClass {
language="java"
since="1.0"
message="Switch statements should be exhaustive, add a default case (or missing enum branches)"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#switchstmtsshouldhavedefault">
Switch statements should be exhaustive, to make their control flow
@@ -1404,7 +1403,7 @@ class Foo {{
language="java"
since="2.1"
message="Usage of System.out/err"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#systemprintln">
References to System.(out|err).print are usually intended for debugging purposes and can remain in
@@ -1697,7 +1696,7 @@ public class Foo {
since="6.34.0"
minimumLanguageVersion="1.7"
message="Please use StandardCharsets constants"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#usestandardcharsets">
Starting with Java 7, StandardCharsets provides constants for common Charset objects, such as UTF-8.
@@ -1786,7 +1785,7 @@ public class TryWithResources {
minimumLanguageVersion="1.5"
since="5.0"
message="Consider using varargs for methods or constructors which take an array the last parameter."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#usevarargs">
Java 5 introduced the varargs parameter declaration for methods and constructors. This syntactic
@@ -1825,7 +1824,7 @@ public class Foo {
-
Avoid using dollar signs in variable/method/class/interface names.
@@ -70,7 +70,7 @@ public class Fo$o { // not a recommended name
language="java"
since="2.1"
message="Avoid protected fields in a final class. Change to private or package access."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#avoidprotectedfieldinfinalclass">
Do not use protected fields in final classes since they cannot be subclassed.
@@ -103,7 +103,7 @@ public final class Bar {
language="java"
since="5.1"
message="Avoid protected methods in a final class that doesn't extend anything other than Object. Change to private or package access."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#avoidprotectedmethodinfinalclassnotextending">
Do not use protected methods in most final classes since they cannot be subclassed. This should
@@ -136,7 +136,7 @@ public final class Foo {
language="java"
since="4.1"
message="The use of native code is not recommended."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#avoidusingnativecode">
Unnecessary reliance on Java Native Interface (JNI) calls directly reduces application portability
@@ -173,7 +173,7 @@ public class SomeJNIClass {
language="java"
since="4.0"
message="A 'getX()' method which returns a boolean should be named 'isX()'"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#booleangetmethodname">
Methods that return boolean results should be named as predicate statements to denote this.
@@ -207,7 +207,7 @@ public boolean getFoo(boolean bar); // ok, unless checkParameterizedMethods=true
language="java"
since="3.0"
message="It is a good practice to call super() in a constructor"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#callsuperinconstructor">
It is a good practice to call super() in a constructor. If super() is not called but
@@ -357,7 +357,7 @@ boolean bar(int x, int y) {
language="java"
since="6.2.0"
message="This statement should have braces"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#controlstatementbraces">
Enforce a policy for braces on control statements. It is recommended to use braces on 'if ... else'
@@ -419,7 +419,7 @@ while (true) { // preferred approach
@@ -509,7 +509,7 @@ class Foo {
language="java"
since="5.0"
message="No need to explicitly extend Object."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#extendsobject">
No need to explicitly extend Object.4
@@ -600,7 +600,7 @@ public class HelloWorldBean {
language="java"
since="6.42.0"
message="Final parameter in abstract method"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
typeResolution="true"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#finalparameterinabstractmethod">
@@ -608,7 +608,6 @@ public class HelloWorldBean {
1
-
Some for loops can be simplified to while loops, this makes them more concise.
@@ -702,7 +701,7 @@ public class Foo {
language="java"
since="4.2.6"
message="Generics names should be a one letter long and upper case."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#genericsnaming">
Names for references to generic values should be limited to a single uppercase letter.
@@ -841,7 +840,7 @@ public class LinguisticNaming {
@@ -873,7 +872,7 @@ public interface MissingProperSuffix extends javax.ejb.EJBLocalHome {} // non-s
@@ -964,7 +963,7 @@ public class Bar {
language="java"
since="0.3"
message="Avoid excessively long variable names like {0}"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#longvariable">
Fields, formal arguments, or local variable names that are too long can make the code difficult to follow.
@@ -998,7 +997,7 @@ public class Something {
@@ -1080,7 +1079,7 @@ public class Foo {
language="java"
since="3.3"
message="All classes, interfaces, enums and annotations must belong to a named package"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#nopackage">
Detects when a class, interface, enum or annotation does not have a package definition.
@@ -1105,7 +1104,7 @@ public class ClassInDefaultPackage {
since="6.10.0"
minimumLanguageVersion="1.7"
message="Number {0} should separate every third digit with an underscore"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#useunderscoresinnumericliterals">
Since Java 1.7, numeric literals can use underscores to separate digits. This rule enforces that
@@ -1180,7 +1179,7 @@ public class OneReturnOnly1 {
language="java"
since="3.3"
message="Package name contains upper case characters"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#packagecase">
Detects when a package definition contains uppercase characters.
@@ -1261,7 +1260,7 @@ public int getLength(String[] strings) {
@@ -1298,7 +1297,7 @@ public interface BadSuffixBean extends javax.ejb.EJBObject {}
@@ -1331,7 +1330,7 @@ public interface MissingProperSuffix extends javax.ejb.EJBHome {} // non-stand
language="java"
since="5.0"
message="Avoid short class names like {0}"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#shortclassname">
Short Classnames with fewer than e.g. five characters are not recommended.
@@ -1359,7 +1358,7 @@ public class Foo {
language="java"
since="0.3"
message="Avoid using short method names"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#shortmethodname">
Method names that are very short are not helpful to the reader.
@@ -1389,7 +1388,7 @@ public class ShortMethod {
language="java"
since="0.3"
message="Avoid variables with short names like {0}"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#shortvariable">
Fields, local variables, enum constant names or parameter names that are very short are not helpful to the reader.
@@ -1434,7 +1433,7 @@ public class Something {
@@ -1471,7 +1470,7 @@ import static Yoko; // Too much !
language="java"
since="6.2.0"
message="Avoid the use of value in annotations when it's the only element"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#unnecessaryannotationvalueelement">
Avoid the use of value in annotations when it's the only element.
@@ -1798,7 +1797,7 @@ public class Foo {
language="java"
since="6.46.0"
message="Unnecessary semicolon"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#unnecessarysemicolon">
Reports unnecessary semicolons (so called "empty statements" and "empty declarations").
@@ -1812,7 +1811,6 @@ public class Foo {
3
-
Java 10 introduced the `var` keyword. This reduces the amount of code written because java can infer the type
@@ -1905,7 +1903,6 @@ See also [Local Variable Type Inference Style Guidelines](https://openjdk.org/pr
-
Reports qualified this usages in the same class.
@@ -2018,7 +2015,7 @@ public class Foo {
language="java"
since="6.15.0"
message="Array initialization can be written shorter"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#useshortarrayinitializer">
@@ -51,7 +51,7 @@ public abstract class Example {
since="4.2.6"
language="java"
message="Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#avoidcatchinggenericexception">
Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block.
@@ -122,7 +122,7 @@ public class Foo {
language="java"
since="3.8"
message="A catch statement that catches an exception only to rethrow it should be avoided."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#avoidrethrowingexception">
Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.
@@ -156,7 +156,7 @@ public void bar() {
since="4.2.5"
language="java"
message="A catch statement that catches an exception only to wrap it in a new instance of the same type of exception and throw it should be avoided"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#avoidthrowingnewinstanceofsameexception">
Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same type only add to
@@ -243,7 +243,7 @@ public class Foo {
language="java"
since="1.8"
message="Avoid throwing raw exception types."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#avoidthrowingrawexceptiontypes">
Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable,
@@ -283,7 +283,7 @@ public class Foo {
since="6.13.0"
language="java"
message="A method or constructor should not explicitly declare unchecked exceptions in its ''throws'' clause"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#avoiduncheckedexceptionsinsignatures">
Reports unchecked exceptions in the `throws` clause of a method or constructor.
@@ -334,7 +334,7 @@ public class Foo { //Should be final
language="java"
since="3.1"
message="This if statement could be combined with its parent"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#collapsibleifstatements">
Errors are system exceptions. Do not extend them.
@@ -796,7 +796,7 @@ public class Foo {
language="java"
since="1.1"
message="This final field could be made static"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#finalfieldcouldbestatic">
If a final field is assigned to a compile-time constant, it could be made static, thus saving overhead
@@ -1013,7 +1013,7 @@ public class Foo {
@@ -1197,7 +1197,7 @@ public void foo() throws Exception {
language="java"
since="5.4.0"
message="This conditional expression can be simplified with || or &&"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#simplifiedternary">
Avoid unnecessary comparisons in boolean expressions, they serve no purpose and impacts readability.
@@ -1401,7 +1401,7 @@ public class Foo {
language="java"
since="3.0"
message="Too many fields"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#toomanyfields">
Classes that have too many fields can become unwieldy and could be redesigned to have fewer fields,
@@ -1444,7 +1444,7 @@ public class Person { // this is more manageable
@@ -1505,7 +1505,7 @@ public Long getId() {
language="java"
since="4.2.6"
message="Rather than using a lot of String arguments, consider using a container object for those values."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#useobjectforclearerapi">
When you write a public method, you should be thinking in terms of an API. If your method is public, it means other class
@@ -1573,7 +1573,7 @@ public class MaybeAUtility {
language="java"
since="6.35.0"
message="Do not use non-final non-private static fields"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#mutablestaticstate">
Non-private static fields should be made constants (or immutable references) by
@@ -1590,7 +1590,6 @@ rule {% rule java/errorprone/AssignmentToNonFinalStatic %}.
3
-
Uncommented Empty Constructor finds instances where a constructor does not
@@ -123,7 +123,7 @@ public Foo() {
language="java"
since="3.4"
message="Document empty method body"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#uncommentedemptymethodbody">
Uncommented Empty Method Body finds instances where a method body does not contain
diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml
index ecd6966822..9bf0ad3cb6 100644
--- a/pmd-java/src/main/resources/category/java/errorprone.xml
+++ b/pmd-java/src/main/resources/category/java/errorprone.xml
@@ -57,7 +57,7 @@ public class StaticField {
language="java"
since="4.1"
message="You should not modify visibility of constructors, methods or fields using setAccessible()"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidaccessibilityalteration">
Methods such as `getDeclaredConstructors()`, `getDeclaredMethods()`, and `getDeclaredFields()` also
@@ -135,7 +135,7 @@ public class Violation {
maximumLanguageVersion="1.3"
since="3.4"
message="Avoid using assert as an identifier; it became a reserved word in JDK 1.4"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidassertasidentifier">
Use of the term `assert` will conflict with newer versions of Java since it is a reserved word.
@@ -196,7 +196,7 @@ for (int i = 0; i < 10; i++) {
language="java"
since="3.0"
message="Avoid calling finalize() explicitly"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidcallingfinalize">
The method Object.finalize() is called by the garbage collector on an object when garbage collection determines
@@ -230,7 +230,7 @@ void foo() {
language="java"
since="1.8"
message="Avoid catching NullPointerException; consider removing the cause of the NPE."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidcatchingnpe">
Code should never throw NullPointerExceptions under normal circumstances. A catch block may hide the
@@ -264,7 +264,7 @@ public class Foo {
language="java"
since="1.2"
message="A catch statement should never catch throwable since it includes errors."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidcatchingthrowable">
Catching Throwable errors is not recommended since its scope is very broad. It includes runtime issues such as
@@ -295,7 +295,7 @@ public void bar() {
language="java"
since="3.4"
message="Avoid creating BigDecimal with a decimal (float/double) literal. Use a String literal"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoiddecimalliteralsinbigdecimalconstructor">
One might assume that the result of "new BigDecimal(0.1)" is exactly equal to 0.1, but it is actually
@@ -357,7 +357,7 @@ private void buz(String x) {}
maximumLanguageVersion="1.4"
since="3.4"
message="Avoid using enum as an identifier; it's a reserved word in JDK 1.5"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidenumasidentifier">
Use of the term `enum` will conflict with newer versions of Java since it is a reserved word.
@@ -387,7 +387,7 @@ public class A {
language="java"
since="3.0"
message="Field {0} has the same name as a method"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidfieldnamematchingmethodname">
It can be confusing to have a field name with the same name as a method. While this is permitted,
@@ -422,7 +422,7 @@ public class Foo {
language="java"
since="3.0"
message="It is somewhat confusing to have a field name matching the declaring class name"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidfieldnamematchingtypename">
It is somewhat confusing to have a field name matching the declaring type name.
@@ -455,7 +455,7 @@ public interface Operation {
language="java"
since="3.0"
message="An instanceof check is being performed on the caught exception. Create a separate catch clause for this exception type."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidinstanceofchecksincatchclause">
Each caught exception type should be handled in its own catch clause.
@@ -495,7 +495,7 @@ try { // Prefer this:
language="java"
since="4.2.6"
message="Avoid using literals in if statements"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidliteralsinifcondition">
Avoid using hard-coded literals in conditional statements. By declaring them as static variables
@@ -576,7 +576,7 @@ public void checkRequests() {
since="4.2.6"
language="java"
message="Avoid statements in a catch block that invoke accessors on the exception without using the information"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#avoidlosingexceptioninformation">
Statements in a catch block that invoke accessors on the exception without using the information
@@ -614,7 +614,7 @@ public void bar() {
@@ -704,7 +704,7 @@ public String bar(String string) {
since="4.2.5"
language="java"
message="super should be called at the start of the method"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#callsuperfirst">
Super should be called at the start of the method3
@@ -747,7 +747,7 @@ public class DummyActivity extends Activity {
since="4.2.5"
language="java"
message="super should be called at the end of the method"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#callsuperlast">
Super should be called at the end of the method
@@ -822,7 +822,7 @@ public class Foo {
language="java"
since="3.4"
message="This usage of the Collection.toArray() method will throw a ClassCastException."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#classcastexceptionwithtoarray">
When deriving an array of a specific class from your Collection, one should provide an array of
@@ -859,7 +859,7 @@ Integer[] b = (Integer [])c.toArray(new Integer[0]);
language="java"
since="5.4.0"
message="clone() method must be public if the class implements Cloneable"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#clonemethodmustbepublic">
The java manual says "By convention, classes that implement this interface should override
@@ -928,7 +928,7 @@ public class MyClass {
minimumLanguageVersion="1.5"
since="5.4.0"
message="The return type of the clone() method must be the class name when implements Cloneable"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#clonemethodreturntypemustmatchclassname">
If a class implements `Cloneable` the return type of the method `clone()` must be the class name. That way, the caller
@@ -1020,7 +1020,7 @@ public class Bar {
language="java"
since="3.2"
message="Use equals() to compare object references."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#compareobjectswithequals">
Use `equals()` to compare object references; avoid comparing them with `==`.
@@ -1035,7 +1035,6 @@ in the `typesThatCompareByReference` property.
3
- java.lang.Enum,java.lang.Class
@@ -1074,7 +1073,7 @@ class Foo {
language="java"
since="6.36.0"
message="Comparisons with NaN always return false"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#comparisonwithnan">
3
-
Calls to `System.gc()`, `Runtime.getRuntime().gc()`, and `System.runFinalization()` are not advised.
@@ -1240,7 +1238,7 @@ public class GCCall {
language="java"
since="6.0.0"
message="Exceptions should not extend java.lang.Throwable"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#donotextendjavalangthrowable">
Extend Exception or RuntimeException instead of Throwable.
@@ -1267,7 +1265,7 @@ public class Foo extends Throwable { }
since="4.2.6"
language="java"
message="Do not hardcode /sdcard."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#donothardcodesdcard">
Use Environment.getExternalStorageDirectory() instead of "/sdcard"
@@ -1295,7 +1293,7 @@ public class MyActivity extends Activity {
language="java"
since="4.1"
message="System.exit() should not be used in J2EE/JEE apps"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#donotterminatevm">
Web applications should not call `System.exit()`, since only the web container or the
@@ -1336,7 +1334,7 @@ public void foo() {
language="java"
since="4.2"
message="A throw statement in a finally block makes the control flow hard to understand."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#donotthrowexceptioninfinally">
Throwing exceptions within a 'finally' block is confusing since they may mask other exceptions
@@ -1371,7 +1369,7 @@ public class Foo {
language="java"
since="1.5"
message="Avoid importing anything from the 'sun.*' packages"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#dontimportsun">
Avoid importing anything from the 'sun.*' packages. These packages are not portable
@@ -1404,7 +1402,7 @@ public class Foo {}
language="java"
since="4.3"
message="Don't use floating point for loop indices. If you must use floating point, use double."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#dontusefloattypeforloopindices">
Don't use floating point for loop indices. If you must use floating point, use double
@@ -1442,7 +1440,7 @@ public class Count {
language="java"
since="0.1"
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_java_errorprone.html#emptycatchblock">
Empty Catch Block finds instances where an exception is caught, but nothing is done.
@@ -1484,7 +1482,7 @@ public void doSomething() {
language="java"
since="1.5"
message="Avoid empty finalize methods"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#emptyfinalizer">
Empty finalize methods serve no purpose and should be removed. Note that Oracle has declared Object.finalize() as deprecated since JDK 9.
@@ -1514,7 +1512,7 @@ public class Foo {
language="java"
since="0.4"
message="Avoid empty finally blocks"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#emptyfinallyblock">
Empty finally blocks serve no purpose and should be removed.
@@ -1552,7 +1550,7 @@ public class Foo {
language="java"
since="0.1"
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_java_errorprone.html#emptyifstmt">
Empty If Statement finds instances where a condition is checked but nothing is done about it.
@@ -1588,7 +1586,7 @@ public class Foo {
language="java"
since="5.0"
message="Empty initializer was found"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#emptyinitializer">
Empty initializers serve no purpose and should be removed.
@@ -1620,7 +1618,7 @@ public class Foo {
language="java"
since="5.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_java_errorprone.html#emptystatementblock">
Empty block statements serve no purpose and should be removed.
@@ -1655,7 +1653,7 @@ public class Foo {
since="1.5"
deprecated="true"
message="An empty statement (semicolon) not part of a loop"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#emptystatementnotinloop">
An empty statement (or a semicolon by itself) that is not used as the sole body of a 'for'
@@ -1699,7 +1697,7 @@ public void doit() {
language="java"
since="1.0"
message="Avoid empty switch statements"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#emptyswitchstatements">
Empty switch statements serve no purpose and should be removed.#
@@ -1731,7 +1729,7 @@ public void bar() {
language="java"
since="1.3"
message="Avoid empty synchronized blocks"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#emptysynchronizedblock">
Empty synchronized blocks serve no purpose and should be removed.
@@ -1763,7 +1761,7 @@ public class Foo {
language="java"
since="0.4"
message="Avoid empty try blocks"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#emptytryblock">
Avoid empty try blocks - what's the point?
@@ -1800,7 +1798,7 @@ public class Foo {
language="java"
since="0.2"
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_java_errorprone.html#emptywhilestmt">
Empty While Statement finds all instances where a while statement does nothing.
@@ -1835,7 +1833,7 @@ void bar(int a, int b) {
language="java"
since="1.9"
message="Avoid using equals() to compare against null"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#equalsnull">
Tests for null should not use the equals() method. The '==' operator should be used instead.
@@ -1869,7 +1867,7 @@ if (x == null) { // preferred
language="java"
since="1.5"
message="Last statement in finalize method should be a call to super.finalize()"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#finalizedoesnotcallsuperfinalize">
If the finalize() is implemented, its last action should be to call super.finalize. Note that Oracle has declared Object.finalize() as deprecated since JDK 9.
@@ -1904,7 +1902,7 @@ protected void finalize() {
language="java"
since="1.5"
message="Finalize should do something besides just calling super.finalize()"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#finalizeonlycallssuperfinalize">
If the finalize() is implemented, it should do something besides just calling super.finalize(). Note that Oracle has declared Object.finalize() as deprecated since JDK 9.
@@ -1933,7 +1931,7 @@ protected void finalize() {
language="java"
since="1.5"
message="Finalize methods should not be overloaded"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#finalizeoverloaded">
Methods named finalize() should not have parameters. It is confusing and most likely an attempt to
@@ -1966,7 +1964,7 @@ public class Foo {
language="java"
since="1.1"
message="If you override finalize(), make it protected"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#finalizeshouldbeprotected">
When overriding the finalize(), the new method should be set as protected. If made public,
@@ -2060,7 +2058,7 @@ public void bar(int status) {
language="java"
since="2.0"
message="Avoid instantiating an object just to call getClass() on it; use the .class public member instead"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#instantiationtogetclass">
Avoid instantiating an object just to call getClass() on it; use the .class public member instead.
@@ -2117,7 +2115,7 @@ LOGGER.error("param {}", "arg1", new IllegalStateException("arg")); //The except
language="java"
since="1.0"
message="Avoid modifying an outer loop incrementer in an inner loop for update expression"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#jumbledincrementer">
Avoid jumbled loop incrementers - it's usually a mistake, and is confusing even if intentional.
@@ -2202,7 +2200,7 @@ public class Foo extends TestCase {
language="java"
since="1.5"
message="A method should not have the same name as its containing class"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#methodwithsamenameasenclosingclass">
A method should not have the same name as its containing class.
@@ -2234,7 +2232,7 @@ public class MyClass {
language="java"
since="3.5"
message="The null check here is misplaced; if the variable ''{0}'' is null there will be a NullPointerException"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#misplacednullcheck">
The null check here is misplaced. If the variable is null a `NullPointerException` will be thrown.
@@ -2304,7 +2302,7 @@ public class Foo {
language="java"
since="3.0"
message="Classes implementing Serializable should set a serialVersionUID"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#missingserialversionuid">
Serializable classes should provide a serialVersionUID field.
@@ -2339,7 +2337,7 @@ public class Foo implements java.io.Serializable {
language="java"
since="3.0"
message="Class cannot be instantiated and does not provide any static methods or fields"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass">
A class that has private constructors and does not have any static methods or fields cannot be used.
@@ -2415,7 +2413,7 @@ public class Foo {
language="java"
since="2.0"
message="Class contains more than one logger."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#morethanonelogger">
Normally only one logger is used in each class. This rule supports slf4j, log4j, Java Util Logging and
@@ -2423,7 +2421,6 @@ log4j2 (since 6.19.0).
2
-
A non-case label (e.g. a named break/continue label) was present in a switch statement.
@@ -2531,7 +2528,7 @@ class Buzz implements java.io.Serializable {
language="java"
since="1.5"
message="Non-static initializers are confusing"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#nonstaticinitializer">
A non-static initializer block will be called any time a constructor is invoked (just prior to
@@ -2540,7 +2537,6 @@ confusing.
3
-
A logger should normally be defined private static final and be associated with the correct class.
@@ -2703,7 +2699,7 @@ public class Foo {
@@ -2715,7 +2711,6 @@ See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays ins
1
-
Avoid returning from a finally block, this can discard exceptions.
@@ -2785,7 +2780,7 @@ public class Bar {
language="java"
since="2.0"
message="When instantiating a SimpleDateFormat object, specify a Locale"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#simpledateformatneedslocale">
Be sure to specify a Locale when creating SimpleDateFormat instances to ensure that locale-appropriate
@@ -2876,7 +2871,7 @@ class Singleton {
language="java"
since="4.1"
message="EJB's shouldn't have non-final static fields"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#staticejbfieldshouldbefinal">
According to the J2EE specification, an EJB should not have any static fields
@@ -2918,7 +2913,7 @@ public class SomeEJB extends EJBObject implements EJBLocalHome {
language="java"
since="3.9"
message="Do not instantiate a StringBuffer or StringBuilder with a char"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#stringbufferinstantiationwithchar">
Individual character values provided as initialization arguments will be converted into integers.
@@ -2967,7 +2962,7 @@ StringBuilder sb4 = new StringBuilder("c");
language="java"
since="2.0"
message="The method name and parameter number are suspiciously close to equals(Object)"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#suspiciousequalsmethodname">
The method name and parameter number are suspiciously close to `Object.equals`, which can denote an
@@ -3022,7 +3017,7 @@ public class Foo {
language="java"
since="1.5"
message="The method name and return type are suspiciously close to hashCode()"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#suspicioushashcodemethodname">
The method name and return type are suspiciously close to hashCode(), which may denote an intention
@@ -3115,7 +3110,7 @@ public class CarTest {
language="java"
since="1.5"
message="Do not use 'if' statements that are always true or always false"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#unconditionalifstatement">
Do not use "if" statements whose conditionals are always true or always false.
@@ -3147,7 +3142,7 @@ public class Foo {
language="java"
since="3.0"
message="assertTrue(true) or similar statements are unnecessary"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#unnecessarybooleanassertion">
A JUnit test assertion with a boolean literal is unnecessary since it always will evaluate to the same thing.
@@ -3215,7 +3210,7 @@ boolean answer2 = buz.toUpperCase().equalsIgnoreCase("BAZ"); // another unnec
language="java"
since="0.1"
message="Avoid unnecessary temporaries when converting primitives to Strings"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#unnecessaryconversiontemporary">
Avoid the use temporary objects when converting primitives to Strings. Use the static conversion methods
@@ -3256,7 +3251,7 @@ public String convert(int x) {
language="java"
since="3.5"
message="Invoke equals() on the object you''ve already ensured is not null"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#unusednullcheckinequals">
After checking an object reference for null, you should invoke equals() on that object rather than passing
@@ -3321,7 +3316,7 @@ public class Test {
language="java"
since="3.2"
message="Use the correct logging statement for logging exceptions"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#usecorrectexceptionlogging">
To make sure the full stacktrace is printed out, use the logging statement with two arguments: a String and a Throwable.
@@ -3361,7 +3356,7 @@ public class Main {
language="java"
since="4.1"
message="Use equals() to compare strings instead of ''=='' or ''!=''"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#useequalstocomparestrings">
Using '==' or '!=' to compare strings is only reliable if the interned string (`String#intern()`)
@@ -3424,7 +3419,7 @@ class Test {
language="java"
since="2.0"
message="When doing a String.toLowerCase()/toUpperCase() call, use a Locale"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#uselocalewithcaseconversions">
When doing `String::toLowerCase()/toUpperCase()` conversions, use an explicit locale argument to specify the case
@@ -3478,7 +3473,7 @@ String z2 = a.toLowerCase(Locale.getDefault());
language="java"
since="3.7"
message="In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#useproperclassloader">
In J2EE, the getClassLoader() method might not work as expected. Use
diff --git a/pmd-java/src/main/resources/category/java/multithreading.xml b/pmd-java/src/main/resources/category/java/multithreading.xml
index 405d884406..88750e9ab0 100644
--- a/pmd-java/src/main/resources/category/java/multithreading.xml
+++ b/pmd-java/src/main/resources/category/java/multithreading.xml
@@ -13,7 +13,7 @@ Rules that flag issues when dealing with multiple threads of execution.
language="java"
since="3.0"
message="Use block level rather than method level synchronization"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidsynchronizedatmethodlevel">
Method-level synchronization can cause problems when new code is added to the method.
@@ -76,7 +76,7 @@ public class Foo {
language="java"
since="3.6"
message="Avoid using java.lang.ThreadGroup; it is not thread safe"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidthreadgroup">
Avoid using java.lang.ThreadGroup; although it is intended to be used in a threaded environment
@@ -110,7 +110,7 @@ public class Bar {
@@ -137,7 +137,7 @@ public class ThrDeux {
@@ -209,7 +209,7 @@ public class UsingExecutors {
language="java"
since="4.3"
message="Don't call Thread.run() explicitly, use Thread.start()"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#dontcallthreadrun">
Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
@@ -339,7 +339,7 @@ public class Foo {
minimumLanguageVersion="1.5"
since="4.2.6"
message="If you run in Java5 or newer and have concurrent access, you should use the ConcurrentHashMap implementation"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#useconcurrenthashmap">
Since Java5 brought a new implementation of the Map designed for multi-threaded access, you can
@@ -374,7 +374,7 @@ public class ConcurrentApp {
language="java"
since="3.0"
message="Call Thread.notifyAll() rather than Thread.notify()"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#usenotifyallinsteadofnotify">
Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only
diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml
index 8d8aca244b..e8a4cfcb80 100644
--- a/pmd-java/src/main/resources/category/java/performance.xml
+++ b/pmd-java/src/main/resources/category/java/performance.xml
@@ -53,7 +53,7 @@ sb.append('a'); // use this instead
language="java"
since="3.5"
message="Arrays.copyOf or System.arraycopy are more efficient"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#avoidarrayloops">
Instead of manually copying data between two arrays, use the more efficient `Arrays.copyOf`
@@ -157,7 +157,7 @@ class Scratch {
since="6.25.0"
language="java"
message="A Calendar is used to get the current time, this is expensive."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
typeResolution="true"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#avoidcalendardatecreation">
@@ -231,7 +231,7 @@ public class DateStuff {
message="Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter"
language="java"
minimumLanguageVersion="1.7"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#avoidfilestream">
The FileInputStream and FileOutputStream classes contains a finalizer method which will cause garbage
@@ -487,7 +487,7 @@ good.append("This is a long string, which is pre-sized");
since="1.8"
minimumLanguageVersion="1.6"
message="This call to Collection.toArray() may be optimizable"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#optimizabletoarraycall">
Calls to a collection's `toArray(E[])` method should specify a target array of zero size. This allows the JVM
@@ -584,7 +584,7 @@ private String bar = new String("bar"); // just do a String bar = "bar";
language="java"
since="1.0"
message="Avoid calling toString() on String objects; this is unnecessary."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#stringtostring">
Avoid calling toString() on objects already known to be string instances; this is unnecessary.
@@ -610,7 +610,7 @@ private String baz() {
@@ -651,7 +651,7 @@ public class Foo {
language="java"
since="3.0"
message="Use ArrayList instead of Vector"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#usearraylistinsteadofvector">
ArrayList is a much better Collection implementation than Vector if thread-safe operation is not required.
@@ -683,7 +683,7 @@ public class SimpleTest extends TestCase {
language="java"
since="3.5"
message="Use asList instead of tight loops"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_performance.html#usearraysaslist">
@@ -786,7 +786,6 @@ and buffering.
3
-
Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals("")
diff --git a/pmd-java/src/main/resources/rulesets/java/android.xml b/pmd-java/src/main/resources/rulesets/java/android.xml
deleted file mode 100644
index 03462bf230..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/android.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-These rules deal with the Android SDK, mostly related to best practices.
-To get better results, make sure that the auxclasspath is defined for type resolution to work.
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/basic.xml b/pmd-java/src/main/resources/rulesets/java/basic.xml
deleted file mode 100644
index c28c9cf770..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/basic.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
-The Basic ruleset contains a collection of good practices which should be followed.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/clone.xml b/pmd-java/src/main/resources/rulesets/java/clone.xml
deleted file mode 100644
index ec7dc50558..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/clone.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-The Clone Implementation ruleset contains a collection of rules that find questionable usages of the clone() method.
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/codesize.xml b/pmd-java/src/main/resources/rulesets/java/codesize.xml
deleted file mode 100644
index a30b20aa4f..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/codesize.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-The Code Size ruleset contains rules that find problems related to code size or complexity.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/comments.xml b/pmd-java/src/main/resources/rulesets/java/comments.xml
deleted file mode 100755
index 0655e2081c..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/comments.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-Rules intended to catch errors related to code comments
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/controversial.xml b/pmd-java/src/main/resources/rulesets/java/controversial.xml
deleted file mode 100644
index 1efb0be7c9..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/controversial.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-The Controversial ruleset contains rules that, for whatever reason, are considered controversial.
-They are held here to allow people to include them as they see fit within their custom rulesets.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/coupling.xml b/pmd-java/src/main/resources/rulesets/java/coupling.xml
deleted file mode 100644
index 43982f3afd..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/coupling.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-Rules which find instances of high or inappropriate coupling between objects and packages.
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pmd-java/src/main/resources/rulesets/java/design.xml b/pmd-java/src/main/resources/rulesets/java/design.xml
deleted file mode 100644
index e2bde4ae93..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/design.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-
-
-
-
-
-The Design ruleset contains rules that flag suboptimal code implementations. Alternate approaches
-are suggested.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/empty.xml b/pmd-java/src/main/resources/rulesets/java/empty.xml
deleted file mode 100644
index 398c70d5b8..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/empty.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-The Empty Code ruleset contains rules that find empty statements of any kind (empty method,
-empty block statement, empty try or catch block,...).
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pmd-java/src/main/resources/rulesets/java/finalizers.xml b/pmd-java/src/main/resources/rulesets/java/finalizers.xml
deleted file mode 100644
index af33d58df0..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/finalizers.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-These rules deal with different problems that can occur with finalizers.
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pmd-java/src/main/resources/rulesets/java/imports.xml b/pmd-java/src/main/resources/rulesets/java/imports.xml
deleted file mode 100644
index 2e3c218016..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/imports.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-These rules deal with different problems that can occur with import statements.
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/j2ee.xml b/pmd-java/src/main/resources/rulesets/java/j2ee.xml
deleted file mode 100644
index 842994c468..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/j2ee.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-Rules specific to the use of J2EE implementations.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/javabeans.xml b/pmd-java/src/main/resources/rulesets/java/javabeans.xml
deleted file mode 100644
index 241bf58d86..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/javabeans.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-The JavaBeans Ruleset catches instances of bean rules not being followed.
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/junit.xml b/pmd-java/src/main/resources/rulesets/java/junit.xml
deleted file mode 100644
index 057cd7f536..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/junit.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-These rules deal with different problems that can occur with JUnit tests.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/logging-jakarta-commons.xml b/pmd-java/src/main/resources/rulesets/java/logging-jakarta-commons.xml
deleted file mode 100644
index 9f23f2dfd0..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/logging-jakarta-commons.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-The Jakarta Commons Logging ruleset contains a collection of rules that find questionable usages of that framework.
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/logging-java.xml b/pmd-java/src/main/resources/rulesets/java/logging-java.xml
deleted file mode 100644
index 65858b65d8..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/logging-java.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-The Java Logging ruleset contains a collection of rules that find questionable usages of the logger.
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/metrics.xml b/pmd-java/src/main/resources/rulesets/java/metrics.xml
deleted file mode 100644
index a19ae5a8e9..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/metrics.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-The Metrics ruleset contains rules that flag large / complex code. These rules are alternative implementations to
-those already existing in the Design ruleset kept apart until the Metrics framework matures.
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/migrating.xml b/pmd-java/src/main/resources/rulesets/java/migrating.xml
deleted file mode 100644
index 9046281651..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/migrating.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-Contains rules about migrating from one JDK version to another. Don't use these rules directly,
-rather, use a wrapper ruleset such as migrating_to_13.xml.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/migrating_to_13.xml b/pmd-java/src/main/resources/rulesets/java/migrating_to_13.xml
deleted file mode 100644
index 8d84773244..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/migrating_to_13.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-Contains rules for migrating to JDK 1.3
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/migrating_to_14.xml b/pmd-java/src/main/resources/rulesets/java/migrating_to_14.xml
deleted file mode 100644
index 8140a032d9..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/migrating_to_14.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-Contains rules for migrating to JDK 1.4
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/migrating_to_15.xml b/pmd-java/src/main/resources/rulesets/java/migrating_to_15.xml
deleted file mode 100644
index a1514ce199..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/migrating_to_15.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-Contains rules for migrating to JDK 1.5
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/migrating_to_junit4.xml b/pmd-java/src/main/resources/rulesets/java/migrating_to_junit4.xml
deleted file mode 100644
index ab9fccf741..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/migrating_to_junit4.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-Contains rules for migrating to JUnit 4
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/naming.xml b/pmd-java/src/main/resources/rulesets/java/naming.xml
deleted file mode 100644
index 667cca11d8..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/naming.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-The Naming Ruleset contains rules regarding preferred usage of names and identifiers.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/optimizations.xml b/pmd-java/src/main/resources/rulesets/java/optimizations.xml
deleted file mode 100644
index ec6d63d4f0..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/optimizations.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-These rules deal with different optimizations that generally apply to best practices.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/rulesets.properties b/pmd-java/src/main/resources/rulesets/java/rulesets.properties
deleted file mode 100644
index cc92c1fe94..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/rulesets.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-#
-# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
-#
-
-rulesets.filenames=\
- category/java/bestpractices.xml,\
- category/java/codestyle.xml,\
- category/java/design.xml,\
- category/java/documentation.xml,\
- category/java/errorprone.xml,\
- category/java/multithreading.xml,\
- category/java/performance.xml
-
-# security doesn't contain any rules yet
-# category/java/security.xml
diff --git a/pmd-java/src/main/resources/rulesets/java/strictexception.xml b/pmd-java/src/main/resources/rulesets/java/strictexception.xml
deleted file mode 100644
index 1610c48b0d..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/strictexception.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-These rules provide some strict guidelines about throwing and catching exceptions.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/strings.xml b/pmd-java/src/main/resources/rulesets/java/strings.xml
deleted file mode 100644
index 75dd092c48..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/strings.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-These rules deal with different issues that can arise with manipulation of the String, StringBuffer, or StringBuilder instances.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/sunsecure.xml b/pmd-java/src/main/resources/rulesets/java/sunsecure.xml
deleted file mode 100644
index e1f452caeb..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/sunsecure.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-These rules check the security guidelines from Sun, published at http://java.sun.com/security/seccodeguide.html#gcg
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/typeresolution.xml b/pmd-java/src/main/resources/rulesets/java/typeresolution.xml
deleted file mode 100644
index 5e84da61b8..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/typeresolution.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-All rules in this ruleset have been moved to other rulesets. Please use the other rules
-directly and don't use this ruleset anymore.
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/unnecessary.xml b/pmd-java/src/main/resources/rulesets/java/unnecessary.xml
deleted file mode 100644
index 6479fadef1..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/unnecessary.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-The Unnecessary Ruleset contains a collection of rules for unnecessary code.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/main/resources/rulesets/java/unusedcode.xml b/pmd-java/src/main/resources/rulesets/java/unusedcode.xml
deleted file mode 100644
index 0b22e86f95..0000000000
--- a/pmd-java/src/main/resources/rulesets/java/unusedcode.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-The Unused Code ruleset contains rules that find unused or ineffective code.
-
-
-
-
-
-
-
-
-
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/ExcludeLinesTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/ExcludeLinesTest.java
index 1c3fe4fbc3..e334d16371 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/ExcludeLinesTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/ExcludeLinesTest.java
@@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.lang.java.BaseParserTest;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.reporting.Report;
class ExcludeLinesTest extends BaseParserTest {
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java
index aa2c5ffa50..f9bb61fdca 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java
@@ -14,6 +14,8 @@ import java.util.regex.Pattern;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.reporting.Report;
class ReportTest {
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/PMD5RulesetTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/PMD5RulesetTest.java
deleted file mode 100644
index 9334683d33..0000000000
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/PMD5RulesetTest.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
- */
-
-package net.sourceforge.pmd.lang.java;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import org.junit.jupiter.api.Test;
-
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetLoader;
-
-class PMD5RulesetTest {
-
- @Test
- void loadRuleset() {
- RuleSet ruleset = new RuleSetLoader().loadFromResource("net/sourceforge/pmd/lang/java/pmd5ruleset.xml");
- assertNotNull(ruleset);
- assertNull(ruleset.getRuleByName("GuardLogStatementJavaUtil"));
- assertNull(ruleset.getRuleByName("GuardLogStatement"));
- }
-}
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/QuickstartRulesetTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/QuickstartRulesetTest.java
index 2b7ffdc9fd..6f3d7e4f37 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/QuickstartRulesetTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/QuickstartRulesetTest.java
@@ -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;
@@ -20,7 +20,7 @@ class QuickstartRulesetTest {
@Test
void noDeprecations() throws Exception {
- RuleSetLoader ruleSetLoader = new RuleSetLoader().enableCompatibility(false);
+ RuleSetLoader ruleSetLoader = new RuleSetLoader();
String errorOutput = SystemLambda.tapSystemErr(() -> {
RuleSet quickstart = ruleSetLoader.loadFromResource(QUICKSTART_RULESET);
assertFalse(quickstart.getRules().isEmpty());
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/RuleSetFactoryTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/RuleSetFactoryTest.java
index d6cafa265a..eac601291e 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/RuleSetFactoryTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/RuleSetFactoryTest.java
@@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.java;
-import net.sourceforge.pmd.AbstractRuleSetFactoryTest;
+import net.sourceforge.pmd.lang.rule.AbstractRuleSetFactoryTest;
/**
* Test java's rulesets
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/SuppressWarningsTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/SuppressWarningsTest.java
index c9f035f80d..3c71089661 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/SuppressWarningsTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/SuppressWarningsTest.java
@@ -10,10 +10,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.FooRule;
-import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.lang.java.ast.ASTClassDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
+import net.sourceforge.pmd.reporting.Report;
class SuppressWarningsTest {
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizerTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaCpdLexerTest.java
similarity index 93%
rename from pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizerTest.java
rename to pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaCpdLexerTest.java
index fd7e56f9f4..f9e871921f 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizerTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaCpdLexerTest.java
@@ -12,18 +12,18 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.CpdLanguageProperties;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
import net.sourceforge.pmd.cpd.test.LanguagePropertyConfig;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
+import net.sourceforge.pmd.lang.ast.LexException;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.TextDocument;
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
// TODO - enable tests
-class JavaTokenizerTest extends CpdTextComparisonTest {
+class JavaCpdLexerTest extends CpdTextComparisonTest {
- JavaTokenizerTest() {
+ JavaCpdLexerTest() {
super(JavaLanguageModule.getInstance(), ".java");
}
@@ -39,9 +39,9 @@ class JavaTokenizerTest extends CpdTextComparisonTest {
@Test
void testLexExceptionLocation() {
- Tokenizer tokenizer = newTokenizer(defaultProperties());
- TokenMgrError lexException = assertThrows(TokenMgrError.class, () ->
- Tokenizer.tokenize(tokenizer,
+ CpdLexer cpdLexer = newCpdLexer(defaultProperties());
+ LexException lexException = assertThrows(LexException.class, () ->
+ CpdLexer.tokenize(cpdLexer,
// note: the source deliberately contains an unbalanced quote, unterminated string literal
TextDocument.readOnlyString("class F {\n String s=\"abc\";\"\n}\n", FileId.UNKNOWN, getLanguage().getDefaultVersion()))
);
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecoratorTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecoratorTest.java
index 2a39b85e0d..4273b38e7d 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecoratorTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/internal/JavaViolationDecoratorTest.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.java.internal;
-import static net.sourceforge.pmd.RuleViolation.CLASS_NAME;
-import static net.sourceforge.pmd.RuleViolation.METHOD_NAME;
-import static net.sourceforge.pmd.RuleViolation.PACKAGE_NAME;
-import static net.sourceforge.pmd.RuleViolation.VARIABLE_NAME;
+import static net.sourceforge.pmd.reporting.RuleViolation.CLASS_NAME;
+import static net.sourceforge.pmd.reporting.RuleViolation.METHOD_NAME;
+import static net.sourceforge.pmd.reporting.RuleViolation.PACKAGE_NAME;
+import static net.sourceforge.pmd.reporting.RuleViolation.VARIABLE_NAME;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/DummyJavaRule.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/DummyJavaRule.java
index 9928712830..7db91ffd38 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/DummyJavaRule.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/DummyJavaRule.java
@@ -4,9 +4,9 @@
package net.sourceforge.pmd.lang.java.rule;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* @author Clément Fournier
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java
index fe24f59474..be877c95c5 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java
@@ -12,22 +12,22 @@ import java.util.List;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.Rule;
-import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.LanguageProcessor;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
-import net.sourceforge.pmd.lang.rule.XPathRule;
+import net.sourceforge.pmd.lang.rule.xpath.XPathRule;
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler;
import net.sourceforge.pmd.lang.rule.xpath.internal.DeprecatedAttrLogger;
import net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
+import net.sourceforge.pmd.reporting.Report;
+import net.sourceforge.pmd.reporting.RuleViolation;
/**
* @author daniels
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredTest.java
index 06c910c7c3..4c026b25c3 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/documentation/CommentRequiredTest.java
@@ -12,7 +12,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.testframework.PmdRuleTst;
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseXPathFunctionTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseXPathFunctionTest.java
index 037cb92c30..d59517e7c3 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseXPathFunctionTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/BaseXPathFunctionTest.java
@@ -13,17 +13,17 @@ import java.util.function.Consumer;
import org.checkerframework.checker.nullness.qual.NonNull;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.lang.LanguageProcessor;
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
import net.sourceforge.pmd.lang.ast.test.TestUtilsKt;
import net.sourceforge.pmd.lang.java.BaseParserTest;
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
-import net.sourceforge.pmd.lang.rule.XPathRule;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException.Phase;
+import net.sourceforge.pmd.lang.rule.xpath.XPathRule;
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
+import net.sourceforge.pmd.reporting.Report;
/**
* @author Clément Fournier
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFunctionsTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFunctionsTest.java
index da6ec72aed..c1dcf336dc 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFunctionsTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/GetModifiersFunctionsTest.java
@@ -10,7 +10,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException.Phase;
/**
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/HasAnnotationXPathTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/HasAnnotationXPathTest.java
index 7d017f68e6..db036ca3b0 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/HasAnnotationXPathTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/HasAnnotationXPathTest.java
@@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
/**
* @author Clément Fournier
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureXPathTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureXPathTest.java
index 62d4610315..584d80fbbd 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureXPathTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/MatchesSignatureXPathTest.java
@@ -9,8 +9,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.lang.LanguageProcessor;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException.Phase;
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunctionTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunctionTest.java
index ea79632da6..8643d4117b 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunctionTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/NodeIsFunctionTest.java
@@ -10,7 +10,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
import net.sourceforge.pmd.lang.rule.xpath.PmdXPathException.Phase;
/**
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/TypeIsFunctionTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/TypeIsFunctionTest.java
index 7011e9d175..4e8977dc64 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/TypeIsFunctionTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/TypeIsFunctionTest.java
@@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.java.rule.xpath.internal;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
/**
* @author Clément Fournier
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/XPathMetricFunctionTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/XPathMetricFunctionTest.java
index f8bbd6d265..0e4584ed9f 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/XPathMetricFunctionTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/xpath/internal/XPathMetricFunctionTest.java
@@ -9,7 +9,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.jupiter.api.Test;
-import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.lang.rule.Rule;
/**
* @author Clément Fournier
diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt
index b6f0c65ff0..791df7c2a3 100644
--- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt
+++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt
@@ -263,7 +263,7 @@ open class ParserTestCtx(testScope: TestScope,
Pair(true, null)
} catch (e: ParseException) {
Pair(false, e)
- } catch (e: TokenMgrError) {
+ } catch (e: LexException) {
Pair(false, e)
}
diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/ant/classpathtest/ruleset.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/ant/classpathtest/ruleset.xml
index bf5fdf9c0c..78e2212101 100644
--- a/pmd-java/src/test/resources/net/sourceforge/pmd/ant/classpathtest/ruleset.xml
+++ b/pmd-java/src/test/resources/net/sourceforge/pmd/ant/classpathtest/ruleset.xml
@@ -12,14 +12,13 @@ The Basic ruleset contains a collection of good practices which should be follow
language="java"
since="1.0"
message="Avoid modifying an outer loop incrementer in an inner loop for update expression"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/java/basic.html#JumbledIncrementer">
Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
3
-
-
-
-
-custom ruleset
-
-
-
-
-
-
-
diff --git a/pmd-javascript/etc/grammar/Ecmascript5.jj b/pmd-javascript/etc/grammar/Ecmascript5.jj
index cc1ada0481..85c9d786c1 100644
--- a/pmd-javascript/etc/grammar/Ecmascript5.jj
+++ b/pmd-javascript/etc/grammar/Ecmascript5.jj
@@ -15,9 +15,6 @@ options {
PARSER_BEGIN(Ecmascript5ParserImpl)
package net.sourceforge.pmd.lang.ecmascript5.ast;
-import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
-
public class Ecmascript5ParserImpl {
}
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java
index 6fd4c2764c..31bc4af4aa 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java
@@ -4,11 +4,11 @@
package net.sourceforge.pmd.lang.ecmascript;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser;
-import net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptTokenizer;
+import net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptCpdLexer;
import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase;
/**
@@ -34,7 +34,7 @@ public class EcmascriptLanguageModule extends SimpleLanguageModuleBase {
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new EcmascriptTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new EcmascriptCpdLexer();
}
}
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTBigIntLiteral.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTBigIntLiteral.java
index 992fd68abd..c2a2ba4a3e 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTBigIntLiteral.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTBigIntLiteral.java
@@ -12,7 +12,6 @@ public final class ASTBigIntLiteral extends AbstractEcmascriptNode {
ASTBreakStatement(BreakStatement breakStatement) {
super(breakStatement);
- super.setImage(breakStatement.getBreakLabel() != null ? breakStatement.getBreakLabel().getIdentifier() : null);
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTContinueStatement.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTContinueStatement.java
index a24c838180..0d58cf2032 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTContinueStatement.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTContinueStatement.java
@@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.ContinueStatement;
public final class ASTContinueStatement extends AbstractEcmascriptNode {
ASTContinueStatement(ContinueStatement continueStatement) {
super(continueStatement);
- super.setImage(continueStatement.getLabel() != null ? continueStatement.getLabel().getIdentifier() : null);
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTErrorNode.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTErrorNode.java
index 16d2adfe8c..43ec7803df 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTErrorNode.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTErrorNode.java
@@ -10,7 +10,6 @@ public final class ASTErrorNode extends AbstractEcmascriptNode {
ASTErrorNode(ErrorNode errorNode) {
super(errorNode);
- super.setImage(errorNode.getMessage());
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNode.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNode.java
index 349358af93..7f9c897e77 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNode.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNode.java
@@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.FunctionNode;
public final class ASTFunctionNode extends AbstractEcmascriptNode {
ASTFunctionNode(FunctionNode functionNode) {
super(functionNode);
- super.setImage(functionNode.getName());
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTKeywordLiteral.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTKeywordLiteral.java
index dd64f99db3..42d52ac848 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTKeywordLiteral.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTKeywordLiteral.java
@@ -12,7 +12,6 @@ import org.mozilla.javascript.ast.KeywordLiteral;
public final class ASTKeywordLiteral extends AbstractEcmascriptNode {
ASTKeywordLiteral(KeywordLiteral keywordLiteral) {
super(keywordLiteral);
- super.setImage(Token.typeToName(keywordLiteral.getType()).toLowerCase(Locale.ROOT));
}
@Override
@@ -20,6 +19,10 @@ public final class ASTKeywordLiteral extends AbstractEcmascriptNode {
ASTLabel(Label label) {
super(label);
- super.setImage(label.getName());
}
@Override
protected
R acceptJsVisitor(EcmascriptVisitor super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
+
+ public String getName() {
+ return node.getName();
+ }
}
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTName.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTName.java
index 4b2d570c50..f9d3dfca7c 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTName.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTName.java
@@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.Name;
public final class ASTName extends AbstractEcmascriptNode {
ASTName(Name name) {
super(name);
- super.setImage(name.getIdentifier());
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java
index c578e2b350..19cc8a7bbc 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java
@@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.NumberLiteral;
public final class ASTNumberLiteral extends AbstractEcmascriptNode {
ASTNumberLiteral(NumberLiteral numberLiteral) {
super(numberLiteral);
- super.setImage(numberLiteral.getValue());
}
@Override
@@ -18,7 +17,7 @@ public final class ASTNumberLiteral extends AbstractEcmascriptNode {
ASTPropertyGet(PropertyGet propertyGet) {
- super(propertyGet, false);
- super.setImage(".");
+ super(propertyGet);
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTRegExpLiteral.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTRegExpLiteral.java
index 9497cc1016..a6e992b0fa 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTRegExpLiteral.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTRegExpLiteral.java
@@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.RegExpLiteral;
public final class ASTRegExpLiteral extends AbstractEcmascriptNode {
ASTRegExpLiteral(RegExpLiteral regExpLiteral) {
super(regExpLiteral);
- super.setImage(regExpLiteral.getValue());
}
@Override
@@ -20,4 +19,8 @@ public final class ASTRegExpLiteral extends AbstractEcmascriptNode {
ASTStringLiteral(StringLiteral stringLiteral) {
super(stringLiteral);
- super.setImage(stringLiteral.getValue());
}
@Override
@@ -28,4 +27,8 @@ public final class ASTStringLiteral extends AbstractEcmascriptNode {
ASTUnaryExpression(UnaryExpression unaryExpression) {
super(unaryExpression);
- super.setImage(AstRoot.operatorToString(unaryExpression.getOperator()));
}
@Override
@@ -30,4 +29,8 @@ public final class ASTUnaryExpression extends AbstractEcmascriptNode {
ASTUpdateExpression(UpdateExpression updateExpression) {
super(updateExpression);
- super.setImage(AstRoot.operatorToString(updateExpression.getOperator()));
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclaration.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclaration.java
index 30cfd70d87..33717690e1 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclaration.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclaration.java
@@ -4,15 +4,11 @@
package net.sourceforge.pmd.lang.ecmascript.ast;
-import java.util.Locale;
-
-import org.mozilla.javascript.Token;
import org.mozilla.javascript.ast.VariableDeclaration;
public final class ASTVariableDeclaration extends AbstractEcmascriptNode {
ASTVariableDeclaration(VariableDeclaration variableDeclaration) {
super(variableDeclaration);
- super.setImage(Token.typeToName(variableDeclaration.getType()).toLowerCase(Locale.ROOT));
}
@Override
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlPropRef.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlPropRef.java
index 62c45d53b3..a2ddfab235 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlPropRef.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlPropRef.java
@@ -4,22 +4,21 @@
package net.sourceforge.pmd.lang.ecmascript.ast;
-import org.mozilla.javascript.ast.Name;
import org.mozilla.javascript.ast.XmlPropRef;
public final class ASTXmlPropRef extends AbstractEcmascriptNode {
ASTXmlPropRef(XmlPropRef xmlPropRef) {
super(xmlPropRef);
-
- Name propName = xmlPropRef.getPropName();
- if (propName != null) {
- super.setImage(propName.getIdentifier());
- }
}
@Override
protected
R acceptJsVisitor(EcmascriptVisitor super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
+
+ public ASTName getPropName() {
+ // first ASTName would be namespace
+ return children(ASTName.class).last();
+ }
}
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlString.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlString.java
index 3db7a9e35a..bdf9d0bac6 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlString.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlString.java
@@ -9,11 +9,14 @@ import org.mozilla.javascript.ast.XmlString;
public final class ASTXmlString extends AbstractEcmascriptNode {
ASTXmlString(XmlString xmlString) {
super(xmlString);
- super.setImage(xmlString.getXml());
}
@Override
protected
R acceptJsVisitor(EcmascriptVisitor super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
+
+ public String getXml() {
+ return node.getXml();
+ }
}
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java
index 90a0f0a51d..68362b7b8d 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java
@@ -13,7 +13,6 @@ import net.sourceforge.pmd.lang.document.TextRegion;
abstract class AbstractEcmascriptNode extends AbstractNode, EcmascriptNode>> implements EcmascriptNode {
protected final T node;
- private String image;
AbstractEcmascriptNode(T node) {
this.node = node;
@@ -24,15 +23,6 @@ abstract class AbstractEcmascriptNode extends AbstractNode extends AbstractEcmascriptNode {
AbstractInfixEcmascriptNode(T infixExpression) {
- this(infixExpression, true);
+ super(infixExpression);
}
- AbstractInfixEcmascriptNode(T infixExpression, boolean setImage) {
- super(infixExpression);
- if (setImage) {
- if (infixExpression.getOperator() == Token.ASSIGN_BITXOR) {
- super.setImage("^=");
- } else if (infixExpression.getOperator() != Token.METHOD) {
- super.setImage(AstRoot.operatorToString(infixExpression.getOperator()));
- }
+ public String getOperator() {
+ int operator = node.getOperator();
+ if (operator == Token.ASSIGN_BITXOR) {
+ return "^=";
+ } else if (operator != Token.METHOD) {
+ return AstRoot.operatorToString(operator);
}
+ return "";
}
public EcmascriptNode> getLeft() {
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptTokenizer.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptCpdLexer.java
similarity index 85%
rename from pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptTokenizer.java
rename to pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptCpdLexer.java
index 34a0d42f30..2f8ddf9c61 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptTokenizer.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptCpdLexer.java
@@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.ecmascript.cpd;
-import net.sourceforge.pmd.cpd.impl.JavaCCTokenizer;
+import net.sourceforge.pmd.cpd.impl.JavaccCpdLexer;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
@@ -13,8 +13,10 @@ import net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5TokenKinds;
/**
* The Ecmascript Tokenizer
+ *
+ *
Note: This class has been called EcmascriptTokenizer in PMD 6
.
*/
-public class EcmascriptTokenizer extends JavaCCTokenizer {
+public class EcmascriptCpdLexer extends JavaccCpdLexer {
@Override
protected TokenManager makeLexerImpl(TextDocument doc) {
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/AbstractEcmascriptRule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/AbstractEcmascriptRule.java
index 90e0f3283a..27dd2dc21e 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/AbstractEcmascriptRule.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/AbstractEcmascriptRule.java
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.ecmascript.rule;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
+import net.sourceforge.pmd.reporting.RuleContext;
public abstract class AbstractEcmascriptRule extends AbstractRule
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/TsLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/TsLanguageModule.java
index 827d42abe8..d2071565c6 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/TsLanguageModule.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/TsLanguageModule.java
@@ -4,11 +4,11 @@
package net.sourceforge.pmd.lang.typescript;
-import net.sourceforge.pmd.cpd.Tokenizer;
+import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase;
-import net.sourceforge.pmd.lang.typescript.cpd.TypeScriptTokenizer;
+import net.sourceforge.pmd.lang.typescript.cpd.TypeScriptCpdLexer;
/**
* @author pguyot@kallisys.net
@@ -27,7 +27,7 @@ public class TsLanguageModule extends CpdOnlyLanguageModuleBase {
}
@Override
- public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
- return new TypeScriptTokenizer();
+ public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
+ return new TypeScriptCpdLexer();
}
}
diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizer.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptCpdLexer.java
similarity index 78%
rename from pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizer.java
rename to pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptCpdLexer.java
index f38c7f9509..aa18c60d5b 100644
--- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizer.java
+++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptCpdLexer.java
@@ -7,10 +7,10 @@ package net.sourceforge.pmd.lang.typescript.cpd;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
-import net.sourceforge.pmd.cpd.impl.AntlrTokenizer;
+import net.sourceforge.pmd.cpd.impl.AntlrCpdLexer;
import net.sourceforge.pmd.lang.typescript.ast.TypeScriptLexer;
-public class TypeScriptTokenizer extends AntlrTokenizer {
+public class TypeScriptCpdLexer extends AntlrCpdLexer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
return new TypeScriptLexer(charStream);
diff --git a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml
index 3e476dacdd..c46cbe920d 100644
--- a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml
+++ b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml
@@ -13,7 +13,7 @@ Rules which enforce generally accepted best practices.
message="Avoid using with - it's bad news"
language="ecmascript"
since="5.0.1"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_bestpractices.html#avoidwithstatement">
Avoid using with - it's bad news1
@@ -72,7 +72,7 @@ function bar() {
message="Avoid using global variables"
language="ecmascript"
since="5.0"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_bestpractices.html#globalvariable">
This rule helps to avoid using accidently global variables by simply missing the "var" declaration.
@@ -105,7 +105,7 @@ function(arg) {
language="ecmascript"
since="5.0"
message="The for-in loop variable ''{0}'' should be explicitly scoped with 'var' to avoid pollution."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_bestpractices.html#scopeforinvariable">
A for-in loop in which the variable name is not explicitly scoped to the enclosing scope with the 'var' keyword can
@@ -161,7 +161,7 @@ function bar() {
message="Always provide a base when using parseInt() functions"
language="ecmascript"
since="5.0.1"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_bestpractices.html#usebasewithparseint">
This rule checks for usages of parseInt. While the second parameter is optional and usually defaults
@@ -176,7 +176,7 @@ See also: [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
Avoid assignments in operands; this can make code more complicated and harder to read. This is sometime
@@ -65,7 +65,7 @@ function getX() {
language="ecmascript"
since="5.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_ecmascript_codestyle.html#forloopsmustusebraces">
Avoid using 'for' statements without using curly braces.
@@ -100,7 +100,7 @@ for (var i = 0; i < 42; i++)
language="ecmascript"
since="5.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_ecmascript_codestyle.html#ifelsestmtsmustusebraces">
Avoid using if..else statements without using curly braces.
@@ -139,7 +139,7 @@ else
language="ecmascript"
since="5.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_ecmascript_codestyle.html#ifstmtsmustusebraces">
Avoid using if statements without using curly braces.
@@ -172,7 +172,7 @@ if (foo)
language="ecmascript"
since="5.5.0"
message="The else block is unnecessary"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_codestyle.html#noelsereturn">
The else block in a if-else-construct is unnecessary if the `if` block contains a return.
@@ -212,7 +212,7 @@ return z;
language="ecmascript"
since="5.0"
message="Unnecessary block."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_codestyle.html#unnecessaryblock">
An unnecessary Block is present. Such Blocks are often used in other languages to
@@ -251,7 +251,7 @@ if (bar) {
language="ecmascript"
since="5.0"
message="Unnecessary parentheses."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_codestyle.html#unnecessaryparentheses">
Unnecessary parentheses should be removed.4
@@ -277,7 +277,7 @@ var z = ((1 + 1)); // Bad
language="ecmascript"
since="5.0"
message="A ''return'', ''break'', ''continue'', or ''throw'' statement should be the last in a block."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_codestyle.html#unreachablecode">
A 'return', 'break', 'continue', or 'throw' statement should be the last in a block. Statements after these
@@ -319,7 +319,7 @@ function bar() {
language="ecmascript"
since="5.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_ecmascript_codestyle.html#whileloopsmustusebraces">
Avoid using 'while' statements without using curly braces.
diff --git a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml
index 4eab35baa8..efe71468b7 100644
--- a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml
+++ b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml
@@ -13,7 +13,7 @@ Rules to detect constructs that are either broken, extremely confusing or prone
message="Avoid trailing commas in object or array literals"
language="ecmascript"
since="5.1"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_errorprone.html#avoidtrailingcomma">
This rule helps improve code portability due to differences in browser treatment of trailing commas in object or array literals.
@@ -49,7 +49,7 @@ function(arg) {
language="ecmascript"
since="5.0"
message="Use '==='/'!==' to compare with true/false or Numbers"
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_errorprone.html#equalcomparison">
Using == in condition may lead to unexpected results, as the variables are automatically casted to be of the
@@ -61,9 +61,9 @@ same type. The === operator avoids the casting.
@@ -95,7 +95,7 @@ if (someVar != 3) {
language="ecmascript"
since="5.0"
message="The numeric literal ''{0}'' will have at different value at runtime."
- class="net.sourceforge.pmd.lang.rule.XPathRule"
+ class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_ecmascript_errorprone.html#innaccuratenumericliteral">
The numeric literal will have a different value at runtime, which can happen if you provide too much
diff --git a/pmd-javascript/src/main/resources/rulesets/ecmascript/basic.xml b/pmd-javascript/src/main/resources/rulesets/ecmascript/basic.xml
deleted file mode 100644
index 2d7f4e5090..0000000000
--- a/pmd-javascript/src/main/resources/rulesets/ecmascript/basic.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
- Rules concerning basic ECMAScript guidelines.
-
-
-
-
- "
-
-
-
-
-
-
-
-
diff --git a/pmd-javascript/src/main/resources/rulesets/ecmascript/braces.xml b/pmd-javascript/src/main/resources/rulesets/ecmascript/braces.xml
deleted file mode 100644
index 623314a0a2..0000000000
--- a/pmd-javascript/src/main/resources/rulesets/ecmascript/braces.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-The Braces Ruleset contains a collection of braces rules.
-
-
-
-
-
-
-
-
diff --git a/pmd-javascript/src/main/resources/rulesets/ecmascript/controversial.xml b/pmd-javascript/src/main/resources/rulesets/ecmascript/controversial.xml
deleted file mode 100644
index d7af94c258..0000000000
--- a/pmd-javascript/src/main/resources/rulesets/ecmascript/controversial.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-The Controversial ruleset contains rules that, for whatever reason, are considered controversial.
-They are held here to allow people to include them as they see fit within their custom rulesets.
-
-
-
-
-
diff --git a/pmd-javascript/src/main/resources/rulesets/ecmascript/rulesets.properties b/pmd-javascript/src/main/resources/rulesets/ecmascript/rulesets.properties
deleted file mode 100644
index d8a50e2fe7..0000000000
--- a/pmd-javascript/src/main/resources/rulesets/ecmascript/rulesets.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
-#
-
-rulesets.filenames=\
- category/ecmascript/bestpractices.xml,\
- category/ecmascript/codestyle.xml,\
- category/ecmascript/errorprone.xml
-
-#
-#empty categories:
-#
-#category/ecmascript/design.xml,
-#category/ecmascript/documentation.xml,
-#category/ecmascript/multithreading.xml,
-#category/ecmascript/performance.xml,
-#category/ecmascript/security.xml,
diff --git a/pmd-javascript/src/main/resources/rulesets/ecmascript/unnecessary.xml b/pmd-javascript/src/main/resources/rulesets/ecmascript/unnecessary.xml
deleted file mode 100644
index e6ca60db73..0000000000
--- a/pmd-javascript/src/main/resources/rulesets/ecmascript/unnecessary.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-The Unnecessary Ruleset contains a collection of rules for unnecessary code.
-
-
-
-
-
-
-
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java
index fbd6235d53..292986f722 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java
@@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParserTestBase;
import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule;
+import net.sourceforge.pmd.lang.rule.Rule;
+import net.sourceforge.pmd.reporting.Report;
class ReportTest extends EcmascriptParserTestBase {
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/DummyJsRule.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/DummyJsRule.java
index 97ddeaa608..4a86a86808 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/DummyJsRule.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/DummyJsRule.java
@@ -4,9 +4,9 @@
package net.sourceforge.pmd.lang.ecmascript;
-import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule;
+import net.sourceforge.pmd.reporting.RuleContext;
/**
* @author Clément Fournier
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/RuleSetFactoryTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/RuleSetFactoryTest.java
index 551b583deb..32b1211d9d 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/RuleSetFactoryTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/RuleSetFactoryTest.java
@@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.ecmascript;
-import net.sourceforge.pmd.AbstractRuleSetFactoryTest;
+import net.sourceforge.pmd.lang.rule.AbstractRuleSetFactoryTest;
/**
* Test javascript's rulesets
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclarationTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclarationTest.java
index e622098b92..083bedc72b 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclarationTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclarationTest.java
@@ -20,7 +20,7 @@ class ASTVariableDeclarationTest extends EcmascriptParserTestBase {
ASTVariableInitializer varInit = (ASTVariableInitializer) varDecl.getChild(0);
ASTName name = (ASTName) varInit.getChild(0);
- assertEquals("x", name.getImage());
+ assertEquals("x", name.getIdentifier());
}
}
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java
index 10b775349c..34556caa54 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java
@@ -16,9 +16,9 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mozilla.javascript.ast.AstRoot;
-import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule;
+import net.sourceforge.pmd.reporting.Report;
class EcmascriptParserTest extends EcmascriptParserTestBase {
@@ -84,10 +84,10 @@ class EcmascriptParserTest extends EcmascriptParserTestBase {
void testArrayAccess() {
EcmascriptNode node = js.parse("function a() { b['a'] = 1; c[1] = 2; }");
List arrays = node.descendants(ASTElementGet.class).toList();
- assertEquals("b", arrays.get(0).getTarget().getImage());
- assertEquals("a", arrays.get(0).getElement().getImage());
- assertEquals("c", arrays.get(1).getTarget().getImage());
- assertEquals("1", arrays.get(1).getElement().getImage());
+ assertEquals("b", ((ASTName) arrays.get(0).getTarget()).getIdentifier());
+ assertEquals("a", ((ASTStringLiteral) arrays.get(0).getElement()).getValue());
+ assertEquals("c", ((ASTName) arrays.get(1).getTarget()).getIdentifier());
+ assertEquals("1", ((ASTNumberLiteral) arrays.get(1).getElement()).getValue());
}
/**
@@ -165,7 +165,7 @@ class EcmascriptParserTest extends EcmascriptParserTestBase {
+ " return (matchFn)?(matcharray = eval(matchFn+\"('\"+fieldval+\"','\"+n.id+\"')\")):void(0);\n"
+ "}\n");
ASTUnaryExpression unary = rootNode.descendants(ASTUnaryExpression.class).first();
- assertEquals("void", unary.getImage());
+ assertEquals("void", unary.getOperator());
}
/**
@@ -177,7 +177,7 @@ class EcmascriptParserTest extends EcmascriptParserTestBase {
+ "x &&= true; x ||= false; x *= 2; x /= 2; x %= 2; x += 2; x -= 2; "
+ "x <<= 2; x >>= 2; x >>>= 2; }");
ASTAssignment infix = rootNode.descendants(ASTAssignment.class).first();
- assertEquals("^=", infix.getImage());
+ assertEquals("^=", infix.getOperator());
}
@Test
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/AnyTokenizerForTypescriptTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/AnyCpdLexerForTypescriptTest.java
similarity index 83%
rename from pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/AnyTokenizerForTypescriptTest.java
rename to pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/AnyCpdLexerForTypescriptTest.java
index 4f5ecf87f8..c159efd6e9 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/AnyTokenizerForTypescriptTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/AnyCpdLexerForTypescriptTest.java
@@ -12,9 +12,9 @@ import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
/**
*
*/
-class AnyTokenizerForTypescriptTest extends CpdTextComparisonTest {
+class AnyCpdLexerForTypescriptTest extends CpdTextComparisonTest {
- AnyTokenizerForTypescriptTest() {
+ AnyCpdLexerForTypescriptTest() {
super(EcmascriptLanguageModule.getInstance(), ".ts");
}
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptTokenizerTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptCpdLexerTest.java
similarity index 92%
rename from pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptTokenizerTest.java
rename to pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptCpdLexerTest.java
index 32c5c769c0..16b176bf43 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptTokenizerTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/cpd/EcmascriptCpdLexerTest.java
@@ -11,9 +11,9 @@ import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
-class EcmascriptTokenizerTest extends CpdTextComparisonTest {
+class EcmascriptCpdLexerTest extends CpdTextComparisonTest {
- EcmascriptTokenizerTest() {
+ EcmascriptCpdLexerTest() {
super(EcmascriptLanguageModule.getInstance(), ".js");
}
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptCpdLexerTest.java
similarity index 84%
rename from pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java
rename to pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptCpdLexerTest.java
index 27ada122a6..aa2d7f84df 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptCpdLexerTest.java
@@ -9,9 +9,9 @@ import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
import net.sourceforge.pmd.lang.typescript.TsLanguageModule;
-class TypeScriptTokenizerTest extends CpdTextComparisonTest {
+class TypeScriptCpdLexerTest extends CpdTextComparisonTest {
- TypeScriptTokenizerTest() {
+ TypeScriptCpdLexerTest() {
super(TsLanguageModule.getInstance(), ".ts");
}
diff --git a/pmd-javascript/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml b/pmd-javascript/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml
index 6c8e1a07b0..529d3cb514 100644
--- a/pmd-javascript/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml
+++ b/pmd-javascript/src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml
@@ -6,13 +6,11 @@
-
+
-
-
diff --git a/pmd-javascript/src/test/resources/net/sourceforge/pmd/ant/xml/ruleset.xml b/pmd-javascript/src/test/resources/net/sourceforge/pmd/ant/xml/ruleset.xml
new file mode 100644
index 0000000000..42c64898a8
--- /dev/null
+++ b/pmd-javascript/src/test/resources/net/sourceforge/pmd/ant/xml/ruleset.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ JavaScript Test Ruleset
+
+
+
+
+
diff --git a/pmd-jsp/etc/grammar/Jsp.jjt b/pmd-jsp/etc/grammar/Jsp.jjt
index 9e4483a441..1f74b3dcf7 100644
--- a/pmd-jsp/etc/grammar/Jsp.jjt
+++ b/pmd-jsp/etc/grammar/Jsp.jjt
@@ -30,10 +30,6 @@ options {
PARSER_BEGIN(JspParserImpl)
package net.sourceforge.pmd.lang.jsp.ast;
-import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
-import net.sourceforge.pmd.lang.ast.TokenMgrError;
-import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
-
/**
* JSP Parser for PMD.
* @author Pieter, Application Engineers NV/SA, http://www.ae.be
@@ -395,7 +391,7 @@ void JspScriptlet() :
{ Token t; }
{
- t = { jjtThis.setImage(t.image.trim()); }
+ t = { jjtThis.setContent(t.image.trim()); }
}
@@ -403,7 +399,7 @@ void JspExpression() :
{ Token t; }
{
- t = { jjtThis.setImage(t.image.trim()); }
+ t = { jjtThis.setContent(t.image.trim()); }
}
@@ -411,7 +407,7 @@ void JspDeclaration() :
{ Token t; }
{
- t = { jjtThis.setImage(t.image.trim()); }
+ t = { jjtThis.setContent(t.image.trim()); }
}
@@ -419,7 +415,7 @@ void JspComment() :
{ Token t; }
{
- t = { jjtThis.setImage(t.image.trim()); }
+ t = { jjtThis.setContent(t.image.trim()); }