Merge branch '7.0.x' into pmd7-token-kinds-internal

This commit is contained in:
Clément Fournier 2022-09-11 01:44:39 +02:00
commit 072a932f27
No known key found for this signature in database
GPG Key ID: 4D8D42402E4F47E2
251 changed files with 4118 additions and 1951 deletions

View File

@ -1053,7 +1053,8 @@
"avatar_url": "https://avatars.githubusercontent.com/u/86377278?v=4",
"profile": "https://github.com/aaronhurst-google",
"contributions": [
"bug"
"bug",
"code"
]
},
{
@ -5917,7 +5918,8 @@
"avatar_url": "https://avatars.githubusercontent.com/u/35368290?v=4",
"profile": "https://github.com/tprouvot",
"contributions": [
"bug"
"bug",
"code"
]
},
{
@ -6768,6 +6770,42 @@
"code",
"financial"
]
},
{
"login": "abyss638",
"name": "Simon Abykov",
"avatar_url": "https://avatars.githubusercontent.com/u/90252673?v=4",
"profile": "https://github.com/abyss638",
"contributions": [
"code"
]
},
{
"login": "eklimo",
"name": "Edward Klimoshenko",
"avatar_url": "https://avatars.githubusercontent.com/u/39220927?v=4",
"profile": "https://github.com/eklimo",
"contributions": [
"bug",
"code"
]
},
{
"login": "nvuillam",
"name": "Nicolas Vuillamy",
"avatar_url": "https://avatars.githubusercontent.com/u/17500430?v=4",
"profile": "https://github.com/nvuillam",
"contributions": [
"doc"
]
},{
"login": "pacvz",
"name": "pacvz",
"avatar_url": "https://avatars.githubusercontent.com/u/35453365?v=4",
"profile": "https://github.com/pacvz",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,

View File

@ -28,6 +28,15 @@ function build() {
pmd_ci_utils_determine_build_env pmd/pmd
echo
if ! pmd_ci_utils_is_fork_or_pull_request; then
if [ "${PMD_CI_BRANCH}" = "experimental-apex-parser" ]; then
pmd_ci_log_group_start "Build with mvnw"
./mvnw clean install --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}"
pmd_ci_log_group_end
exit 0
fi
fi
if pmd_ci_utils_is_fork_or_pull_request; then
pmd_ci_log_group_start "Build with mvnw"
./mvnw clean install --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}"

View File

@ -6,6 +6,7 @@ on:
- main
- master
- pmd/7.0.x
- experimental-apex-parser
tags:
- '**'
pull_request:

10
SPONSORS.md Normal file
View File

@ -0,0 +1,10 @@
# PMD's sponsors
Many thanks to all our sponsors:
* [Matt Hargett](https://github.com/matthargett) (@matthargett)
If you also want to sponsor PMD, you have two options:
* [Sponsor @pmd on GitHub Sponsors](https://github.com/sponsors/pmd)
* [PMD - Open Collective](https://opencollective.com/pmd)

View File

@ -2,7 +2,7 @@ repository: pmd/pmd
pmd:
version: 7.0.0-SNAPSHOT
previous_version: 6.47.0
previous_version: 6.49.0
date: ??-?????-2022
release_type: major

View File

@ -246,6 +246,76 @@ the breaking API changes will be performed in 7.0.0.
an API is tagged as `@Deprecated` or not in the latest minor release. During the development of 7.0.0,
we may decide to remove some APIs that were not tagged as deprecated, though we'll try to avoid it." %}
#### 6.49.0
##### Deprecated API
* In order to reduce the dependency on Apex Jorje classes, the following methods have been deprecated.
These methods all leaked internal Jorje enums. These enums have been replaced now by enums the
PMD's AST package.
* {% jdoc !!apex::lang.apex.ast.ASTAssignmentExpression#getOperator() %}
* {% jdoc !!apex::lang.apex.ast.ASTBinaryExpression#getOperator() %}
* {% jdoc !!apex::lang.apex.ast.ASTBooleanExpression#getOperator() %}
* {% jdoc !!apex::lang.apex.ast.ASTPostfixExpression#getOperator() %}
* {% jdoc !!apex::lang.apex.ast.ASTPrefixExpression#getOperator() %}
All these classes have now a new `getOp()` method. Existing code should be refactored to use this method instead.
It returns the new enums, like {% jdoc apex::lang.apex.ast.AssignmentOperator %}, and avoids
the dependency to Jorje.
#### 6.48.0
##### CPD CLI
* CPD has a new CLI option `--debug`. This option has the same behavior as in PMD. It enables more verbose
logging output.
##### Rule Test Framework
* The module "pmd-test", which contains support classes to write rule tests, now **requires Java 8**. If you depend on
this module for testing your own custom rules, you'll need to make sure to use at least Java 8.
* The new module "pmd-test-schema" contains now the XSD schema and the code to parse the rule test XML files. The
schema has been extracted in order to easily share it with other tools like the Rule Designer or IDE plugins.
* Test schema changes:
* The attribute `isRegressionTest` of `test-code` is deprecated. The new
attribute `disabled` should be used instead for defining whether a rule test should be skipped or not.
* The attributes `reinitializeRule` and `useAuxClasspath` of `test-code` are deprecated and assumed true.
They will not be replaced.
* The new attribute `focused` of `test-code` allows disabling all tests except the focused one temporarily.
* More information about the rule test framework can be found in the documentation:
[Testing your rules](pmd_userdocs_extending_testing.html)
##### Deprecated API
* The experimental Java AST class {% jdoc java::lang.java.ast.ASTGuardedPattern %} has been deprecated and
will be removed. It was introduced for Java 17 and Java 18 Preview as part of pattern matching for switch,
but it is no longer supported with Java 19 Preview.
* The interface {% jdoc core::cpd.renderer.CPDRenderer %} is deprecated. For custom CPD renderers
the new interface {% jdoc core::cpd.renderer.CPDReportRenderer %} should be used.
* The class {% jdoc test::testframework.TestDescriptor %} is deprecated, replaced with {% jdoc test-schema::test.schema.RuleTestDescriptor %}.
* Many methods of {% jdoc test::testframework.RuleTst %} have been deprecated as internal API.
##### Experimental APIs
* To support the Java preview language features "Pattern Matching for Switch" and "Record Patterns", the following
AST nodes have been introduced as experimental:
* {% jdoc java::lang.java.ast.ASTSwitchGuard %}
* {% jdoc java::lang.java.ast.ASTRecordPattern %}
* {% jdoc java::lang.java.ast.ASTComponentPatternList %}
##### Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning.
* {%jdoc !!core::cpd.CPDConfiguration#setRenderer(net.sourceforge.pmd.cpd.Renderer) %}
* {%jdoc !!core::cpd.CPDConfiguration#setCPDRenderer(net.sourceforge.pmd.cpd.renderer.CPDRenderer) %}
* {%jdoc !!core::cpd.CPDConfiguration#getRenderer() %}
* {%jdoc !!core::cpd.CPDConfiguration#getCPDRenderer() %}
* {%jdoc !!core::cpd.CPDConfiguration#getRendererFromString(java.lang.String,java.lang.String) %}
* {%jdoc !!core::cpd.CPDConfiguration#getCPDRendererFromString(java.lang.String,java.lang.String) %}
* {%jdoc core::cpd.renderer.CPDRendererAdapter %}
#### 6.47.0
No changes.

File diff suppressed because it is too large Load Diff

View File

@ -73,6 +73,9 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt
description="Sources code language."
default="java"
%}
{% include custom/cli_option_row.html options="--debug,--verbose"
description="Debug mode. Prints more log output."
%}
{% include custom/cli_option_row.html options="--encoding"
description="Character encoding to use when processing files. If not specified, CPD uses the system default encoding."
%}

View File

@ -104,9 +104,9 @@ Example:
<file path="/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/RuleReferenceTest.java" totalNumberOfTokens="523"/>
<file path="/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java" totalNumberOfTokens="120"/>
<duplication lines="33" tokens="239">
<file column="29" endcolumn="75" endline="64" line="32"
<file column="29" endcolumn="75" endline="64" line="32" begintoken="2356" endtoken="2594"
path="/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/RuleReferenceTest.java"/>
<file column="37" endcolumn="75" endline="100" line="68"
<file column="37" endcolumn="75" endline="100" line="68" begintoken="5700" endtoken="5938"
path="/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/RuleReferenceTest.java"/>
<codefragment><![CDATA[ public void testOverride() {
final StringProperty PROPERTY1_DESCRIPTOR = new StringProperty("property1", "Test property", null, 0f);
@ -143,11 +143,11 @@ Example:
validateOverriddenValues(PROPERTY1_DESCRIPTOR, PROPERTY2_DESCRIPTOR, ruleReference);]]></codefragment>
</duplication>
<duplication lines="16" tokens="110">
<file column="9" endcolumn="28" endline="81" line="66"
<file column="9" endcolumn="28" endline="81" line="66" begintoken="3000" endtoken="3109"
path="/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java"/>
<file column="9" endcolumn="28" endline="103" line="88"
<file column="9" endcolumn="28" endline="103" line="88" begintoken="3200" endtoken="3309"
path="/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java"/>
<file column="9" endcolumn="28" endline="125" line="110"
<file column="9" endcolumn="28" endline="125" line="110" begintoken="3400" endtoken="3509"
path="/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java"/>
<codefragment><![CDATA[ JaxenXPathRuleQuery query = createQuery(xpath);
List<String> ruleChainVisits = query.getRuleChainVisits();

View File

@ -28,4 +28,10 @@ result of the PMD maven plugin.
See [Other Tools / Integrations](pmd_userdocs_tools.html#github-actions)
## MegaLinter
[🦙 Mega-Linter](https://oxsecurity.github.io/megalinter/latest/) analyzes 50 languages, 22 formats, 21 tooling formats, excessive copy-pastes, spelling mistakes and security issues in your repository sources with a GitHub Action, other CI tools or locally.
It [natively embeds PMD](https://oxsecurity.github.io/megalinter/latest/descriptors/java_pmd/).
<!-- TODO: Find out about other plugins ? -->

View File

@ -19,112 +19,11 @@ This is a {{ site.pmd.release_type }} release.
### New and noteworthy
#### Java 19 Support
This release of PMD brings support for Java 19. There are no new standard language features.
PMD supports [JEP 427: Pattern Matching for switch (Third Preview)](https://openjdk.org/jeps/427) and
[JEP 405: Record Patterns (Preview)](https://openjdk.org/jeps/405) as preview language features.
In order to analyze a project with PMD that uses these language features,
you'll need to enable it via the environment variable `PMD_JAVA_OPTS` and select the new language
version `19-preview`:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 19-preview ...
Note: Support for Java 17 preview language features have been removed. The version "17-preview" is no longer available.
#### Gherkin support
Thanks to the contribution from [Anne Brouwers](https://github.com/ASBrouwers) PMD now has CPD support
for the [Gherkin](https://cucumber.io/docs/gherkin/) language. It is used to defined test cases for the
[Cucumber](https://cucumber.io/) testing tool for behavior-driven development.
Being based on a proper Antlr grammar, CPD can:
* ignore comments
* honor [comment-based suppressions](pmd_userdocs_cpd.html#suppression)
### Fixed Issues
* apex
* [#4056](https://github.com/pmd/pmd/pull/4056): \[apex] ApexSOQLInjection: Add support count query
* core
* [#4021](https://github.com/pmd/pmd/pull/4021): \[core] CPD: Add total number of tokens to XML reports
* [#4031](https://github.com/pmd/pmd/issues/4031): \[core] If report is written to stdout, stdout should not be closed
* [#4053](https://github.com/pmd/pmd/pull/4053): \[core] Allow building PMD under Java 18+
* java
* [#4015](https://github.com/pmd/pmd/issues/4015): \[java] Support JDK 19
* java-bestpractices
* [#3455](https://github.com/pmd/pmd/issues/3455): \[java] WhileLoopWithLiteralBoolean - false negative with complex expressions
* java-design
* [#3729](https://github.com/pmd/pmd/issues/3729): \[java] TooManyMethods ignores "real" methods which are named like getters or setters
* [#3949](https://github.com/pmd/pmd/issues/3949): \[java] FinalFieldCouldBeStatic - false negative with unnecessary parenthesis
* java-performance
* [#3625](https://github.com/pmd/pmd/issues/3625): \[java] AddEmptyString - false negative with empty var
* lua
* [#4061](https://github.com/pmd/pmd/pull/4061): \[lua] Fix several related Lua parsing issues found when using CPD
* test
* [#3302](https://github.com/pmd/pmd/pull/3302): \[test] Improve xml test schema
* [#3758](https://github.com/pmd/pmd/issues/3758): \[test] Move pmd-test to java 8
* [#3976](https://github.com/pmd/pmd/pull/3976): \[test] Extract xml schema module
### API Changes
#### Rule Test Framework
* The module "pmd-test", which contains support classes to write rule tests, now **requires Java 8**. If you depend on
this module for testing your own custom rules, you'll need to make sure to use at least Java 8.
* The new module "pmd-test-schema" contains now the XSD schema and the code to parse the rule test XML files. The
schema has been extracted in order to easily share it with other tools like the Rule Designer or IDE plugins.
* Test schema changes:
* The attribute `isRegressionTest` of `test-code` is deprecated. The new
attribute `disabled` should be used instead for defining whether a rule test should be skipped or not.
* The attributes `reinitializeRule` and `useAuxClasspath` of `test-code` are deprecated and assumed true.
They will not be replaced.
* The new attribute `focused` of `test-code` allows disabling all tests except the focused one temporarily.
* More information about the rule test framework can be found in the documentation:
[Testing your rules](pmd_userdocs_extending_testing.html)
#### Deprecated API
* The experimental Java AST class {% jdoc java::lang.java.ast.ASTGuardedPattern %} has been deprecated and
will be removed. It was introduced for Java 17 and Java 18 Preview as part of pattern matching for switch,
but it is no longer supported with Java 19 Preview.
* The interface {% jdoc core::cpd.renderer.CPDRenderer %} is deprecated. For custom CPD renderers
the new interface {% jdoc core::cpd.renderer.CPDReportRenderer %} should be used.
* The class {% jdoc test::testframework.TestDescriptor %} is deprecated, replaced with {% jdoc test-schema::testframework.RuleTestDescriptor %}.
* Many methods of {% jdoc test::testframework.RuleTst %} have been deprecated as internal API.
#### Experimental APIs
* To support the Java preview language features "Pattern Matching for Switch" and "Record Patterns", the following
AST nodes have been introduced as experimental:
* {% jdoc java::lang.java.ast.ASTSwitchGuard %}
* {% jdoc java::lang.java.ast.ASTRecordPattern %}
* {% jdoc java::lang.java.ast.ASTComponentPatternList %}
#### Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning.
* {%jdoc !!core::cpd.CPDConfiguration#setRenderer(net.sourceforge.pmd.cpd.Renderer) %}
* {%jdoc !!core::cpd.CPDConfiguration#setCPDRenderer(net.sourceforge.pmd.cpd.renderer.CPDRenderer) %}
* {%jdoc !!core::cpd.CPDConfiguration#getRenderer() %}
* {%jdoc !!core::cpd.CPDConfiguration#getCPDRenderer() %}
* {%jdoc !!core::cpd.CPDConfiguration#getRendererFromString(java.lang.String,java.lang.String) %}
* {%jdoc !!core::cpd.CPDConfiguration#getCPDRendererFromString(java.lang.String,java.lang.String) %}
* {%jdoc core::cpd.renderer.CPDRendererAdapter %}
### External Contributions
* [#3984](https://github.com/pmd/pmd/pull/3984): \[java] Fix AddEmptyString false-negative issue - [@LiGaOg](https://github.com/LiGaOg)
* [#3988](https://github.com/pmd/pmd/pull/3988): \[java] Modify WhileLoopWithLiteralBoolean to meet the missing case #3455 - [@VoidxHoshi](https://github.com/VoidxHoshi)
* [#3992](https://github.com/pmd/pmd/pull/3992): \[java] FinalFieldCouldBeStatic - fix false negative with unnecessary parenthesis - [@dalizi007](https://github.com/dalizi007)
* [#3994](https://github.com/pmd/pmd/pull/3994): \[java] TooManyMethods - improve getter/setter detection (#3729) - [@341816041](https://github.com/341816041)
* [#4017](https://github.com/pmd/pmd/pull/4017): Add Gherkin support to CPD - [@ASBrouwers](https://github.com/ASBrouwers)
* [#4021](https://github.com/pmd/pmd/pull/4021): \[core] CPD: Add total number of tokens to XML reports - [@maikelsteneker](https://github.com/maikelsteneker)
* [#4056](https://github.com/pmd/pmd/pull/4056): \[apex] ApexSOQLInjection: Add support count query - [@gwilymatgearset](https://github.com/gwilymatgearset)
* [#4061](https://github.com/pmd/pmd/pull/4061): \[lua] Fix several related Lua parsing issues found when using CPD - [@matthargett](https://github.com/matthargett)
{% endtocmaker %}

View File

@ -5,6 +5,218 @@ permalink: pmd_release_notes_old.html
Previous versions of PMD can be downloaded here: https://github.com/pmd/pmd/releases
## 31-August-2022 - 6.49.0
The PMD team is pleased to announce PMD 6.49.0.
This is a minor release.
### Table Of Contents
* [New and noteworthy](#new-and-noteworthy)
* [Updated PMD Designer](#updated-pmd-designer)
* [Fixed Issues](#fixed-issues)
* [API Changes](#api-changes)
* [Deprecated API](#deprecated-api)
* [External Contributions](#external-contributions)
* [Stats](#stats)
### New and noteworthy
#### 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/6.49.0).
### Fixed Issues
* apex
* [#4096](https://github.com/pmd/pmd/issues/4096): \[apex] ApexAssertionsShouldIncludeMessage and ApexUnitTestClassShouldHaveAsserts: support new Assert class (introduced with Apex v56.0)
* core
* [#3970](https://github.com/pmd/pmd/issues/3970): \[core] FileCollector.addFile ignores language parameter
* java-codestyle
* [#4082](https://github.com/pmd/pmd/issues/4082): \[java] UnnecessaryImport false positive for on-demand imports of nested classes
### API Changes
#### Deprecated API
* In order to reduce the dependency on Apex Jorje classes, the following methods have been deprecated.
These methods all leaked internal Jorje enums. These enums have been replaced now by enums the
PMD's AST package.
* <a href="https://docs.pmd-code.org/apidocs/pmd-apex/6.49.0/net/sourceforge/pmd/lang/apex/ast/ASTAssignmentExpression.html#getOperator()"><code>ASTAssignmentExpression#getOperator</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-apex/6.49.0/net/sourceforge/pmd/lang/apex/ast/ASTBinaryExpression.html#getOperator()"><code>ASTBinaryExpression#getOperator</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-apex/6.49.0/net/sourceforge/pmd/lang/apex/ast/ASTBooleanExpression.html#getOperator()"><code>ASTBooleanExpression#getOperator</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-apex/6.49.0/net/sourceforge/pmd/lang/apex/ast/ASTPostfixExpression.html#getOperator()"><code>ASTPostfixExpression#getOperator</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-apex/6.49.0/net/sourceforge/pmd/lang/apex/ast/ASTPrefixExpression.html#getOperator()"><code>ASTPrefixExpression#getOperator</code></a>
All these classes have now a new `getOp()` method. Existing code should be refactored to use this method instead.
It returns the new enums, like <a href="https://docs.pmd-code.org/apidocs/pmd-apex/6.49.0/net/sourceforge/pmd/lang/apex/ast/AssignmentOperator.html#"><code>AssignmentOperator</code></a>, and avoids
the dependency to Jorje.
### External Contributions
* [#4081](https://github.com/pmd/pmd/pull/4081): \[apex] Remove Jorje leaks outside `ast` package - [@eklimo](https://github.com/eklimo)
* [#4083](https://github.com/pmd/pmd/pull/4083): \[java] UnnecessaryImport false positive for on-demand imports of nested classes (fix for #4082) - [@abyss638](https://github.com/abyss638)
* [#4092](https://github.com/pmd/pmd/pull/4092): \[apex] Implement ApexQualifiableNode for ASTUserEnum - [@aaronhurst-google](https://github.com/aaronhurst-google)
* [#4095](https://github.com/pmd/pmd/pull/4095): \[core] CPD: Added begin and end token to XML reports - [@pacvz](https://github.com/pacvz)
* [#4097](https://github.com/pmd/pmd/pull/4097): \[apex] ApexUnitTestClassShouldHaveAssertsRule: Support new Assert class (Apex v56.0) - [@tprouvot](https://github.com/tprouvot)
* [#4104](https://github.com/pmd/pmd/pull/4104): \[doc] Add MegaLinter in the list of integrations - [@nvuillam](https://github.com/nvuillam)
### Stats
* 49 commits
* 10 closed tickets & PRs
* Days since last release: 32
## 30-July-2022 - 6.48.0
The PMD team is pleased to announce PMD 6.48.0.
This is a minor release.
### Table Of Contents
* [New and noteworthy](#new-and-noteworthy)
* [Java 19 Support](#java-19-support)
* [Gherkin support](#gherkin-support)
* [Fixed Issues](#fixed-issues)
* [API Changes](#api-changes)
* [CPD CLI](#cpd-cli)
* [Rule Test Framework](#rule-test-framework)
* [Deprecated API](#deprecated-api)
* [Experimental APIs](#experimental-apis)
* [Internal API](#internal-api)
* [Financial Contributions](#financial-contributions)
* [External Contributions](#external-contributions)
* [Stats](#stats)
### New and noteworthy
#### Java 19 Support
This release of PMD brings support for Java 19. There are no new standard language features.
PMD supports [JEP 427: Pattern Matching for switch (Third Preview)](https://openjdk.org/jeps/427) and
[JEP 405: Record Patterns (Preview)](https://openjdk.org/jeps/405) as preview language features.
In order to analyze a project with PMD that uses these language features,
you'll need to enable it via the environment variable `PMD_JAVA_OPTS` and select the new language
version `19-preview`:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 19-preview ...
Note: Support for Java 17 preview language features have been removed. The version "17-preview" is no longer available.
#### Gherkin support
Thanks to the contribution from [Anne Brouwers](https://github.com/ASBrouwers) PMD now has CPD support
for the [Gherkin](https://cucumber.io/docs/gherkin/) language. It is used to defined test cases for the
[Cucumber](https://cucumber.io/) testing tool for behavior-driven development.
Being based on a proper Antlr grammar, CPD can:
* ignore comments
* honor [comment-based suppressions](pmd_userdocs_cpd.html#suppression)
### Fixed Issues
* apex
* [#4056](https://github.com/pmd/pmd/pull/4056): \[apex] ApexSOQLInjection: Add support count query
* core
* [#3796](https://github.com/pmd/pmd/issues/3796): \[core] CPD should also provide a `--debug` flag
* [#4021](https://github.com/pmd/pmd/pull/4021): \[core] CPD: Add total number of tokens to XML reports
* [#4031](https://github.com/pmd/pmd/issues/4031): \[core] If report is written to stdout, stdout should not be closed
* [#4051](https://github.com/pmd/pmd/issues/4051): \[doc] Additional rulesets are not listed in documentation
* [#4053](https://github.com/pmd/pmd/pull/4053): \[core] Allow building PMD under Java 18+
* java
* [#4015](https://github.com/pmd/pmd/issues/4015): \[java] Support JDK 19
* java-bestpractices
* [#3455](https://github.com/pmd/pmd/issues/3455): \[java] WhileLoopWithLiteralBoolean - false negative with complex expressions
* java-design
* [#3729](https://github.com/pmd/pmd/issues/3729): \[java] TooManyMethods ignores "real" methods which are named like getters or setters
* [#3949](https://github.com/pmd/pmd/issues/3949): \[java] FinalFieldCouldBeStatic - false negative with unnecessary parenthesis
* java-performance
* [#3625](https://github.com/pmd/pmd/issues/3625): \[java] AddEmptyString - false negative with empty var
* lua
* [#4061](https://github.com/pmd/pmd/pull/4061): \[lua] Fix several related Lua parsing issues found when using CPD
* test
* [#3302](https://github.com/pmd/pmd/pull/3302): \[test] Improve xml test schema
* [#3758](https://github.com/pmd/pmd/issues/3758): \[test] Move pmd-test to java 8
* [#3976](https://github.com/pmd/pmd/pull/3976): \[test] Extract xml schema module
### API Changes
#### CPD CLI
* CPD has a new CLI option `--debug`. This option has the same behavior as in PMD. It enables more verbose
logging output.
#### Rule Test Framework
* The module "pmd-test", which contains support classes to write rule tests, now **requires Java 8**. If you depend on
this module for testing your own custom rules, you'll need to make sure to use at least Java 8.
* The new module "pmd-test-schema" contains now the XSD schema and the code to parse the rule test XML files. The
schema has been extracted in order to easily share it with other tools like the Rule Designer or IDE plugins.
* Test schema changes:
* The attribute `isRegressionTest` of `test-code` is deprecated. The new
attribute `disabled` should be used instead for defining whether a rule test should be skipped or not.
* The attributes `reinitializeRule` and `useAuxClasspath` of `test-code` are deprecated and assumed true.
They will not be replaced.
* The new attribute `focused` of `test-code` allows disabling all tests except the focused one temporarily.
* More information about the rule test framework can be found in the documentation:
[Testing your rules](pmd_userdocs_extending_testing.html)
#### Deprecated API
* The experimental Java AST class <a href="https://docs.pmd-code.org/apidocs/pmd-java/6.48.0/net/sourceforge/pmd/lang/java/ast/ASTGuardedPattern.html#"><code>ASTGuardedPattern</code></a> has been deprecated and
will be removed. It was introduced for Java 17 and Java 18 Preview as part of pattern matching for switch,
but it is no longer supported with Java 19 Preview.
* The interface <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/renderer/CPDRenderer.html#"><code>CPDRenderer</code></a> is deprecated. For custom CPD renderers
the new interface <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/renderer/CPDReportRenderer.html#"><code>CPDReportRenderer</code></a> should be used.
* The class <a href="https://docs.pmd-code.org/apidocs/pmd-test/6.48.0/net/sourceforge/pmd/testframework/TestDescriptor.html#"><code>TestDescriptor</code></a> is deprecated, replaced with <a href="https://docs.pmd-code.org/apidocs/pmd-test-schema/6.48.0/net/sourceforge/pmd/test/schema/RuleTestDescriptor.html#"><code>RuleTestDescriptor</code></a>.
* Many methods of <a href="https://docs.pmd-code.org/apidocs/pmd-test/6.48.0/net/sourceforge/pmd/testframework/RuleTst.html#"><code>RuleTst</code></a> have been deprecated as internal API.
#### Experimental APIs
* To support the Java preview language features "Pattern Matching for Switch" and "Record Patterns", the following
AST nodes have been introduced as experimental:
* <a href="https://docs.pmd-code.org/apidocs/pmd-java/6.48.0/net/sourceforge/pmd/lang/java/ast/ASTSwitchGuard.html#"><code>ASTSwitchGuard</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-java/6.48.0/net/sourceforge/pmd/lang/java/ast/ASTRecordPattern.html#"><code>ASTRecordPattern</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-java/6.48.0/net/sourceforge/pmd/lang/java/ast/ASTComponentPatternList.html#"><code>ASTComponentPatternList</code></a>
#### Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning.
* <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/CPDConfiguration.html#setRenderer(net.sourceforge.pmd.cpd.Renderer)"><code>CPDConfiguration#setRenderer</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/CPDConfiguration.html#setCPDRenderer(net.sourceforge.pmd.cpd.renderer.CPDRenderer)"><code>CPDConfiguration#setCPDRenderer</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/CPDConfiguration.html#getRenderer()"><code>CPDConfiguration#getRenderer</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/CPDConfiguration.html#getCPDRenderer()"><code>CPDConfiguration#getCPDRenderer</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/CPDConfiguration.html#getRendererFromString(java.lang.String,java.lang.String)"><code>CPDConfiguration#getRendererFromString</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/CPDConfiguration.html#getCPDRendererFromString(java.lang.String,java.lang.String)"><code>CPDConfiguration#getCPDRendererFromString</code></a>
* <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.48.0/net/sourceforge/pmd/cpd/renderer/CPDRendererAdapter.html#"><code>CPDRendererAdapter</code></a>
### Financial Contributions
Many thanks to our sponsors:
* [Matt Hargett](https://github.com/matthargett) (@matthargett)
### External Contributions
* [#3984](https://github.com/pmd/pmd/pull/3984): \[java] Fix AddEmptyString false-negative issue - [@LiGaOg](https://github.com/LiGaOg)
* [#3988](https://github.com/pmd/pmd/pull/3988): \[java] Modify WhileLoopWithLiteralBoolean to meet the missing case #3455 - [@VoidxHoshi](https://github.com/VoidxHoshi)
* [#3992](https://github.com/pmd/pmd/pull/3992): \[java] FinalFieldCouldBeStatic - fix false negative with unnecessary parenthesis - [@dalizi007](https://github.com/dalizi007)
* [#3994](https://github.com/pmd/pmd/pull/3994): \[java] TooManyMethods - improve getter/setter detection (#3729) - [@341816041](https://github.com/341816041)
* [#4017](https://github.com/pmd/pmd/pull/4017): Add Gherkin support to CPD - [@ASBrouwers](https://github.com/ASBrouwers)
* [#4021](https://github.com/pmd/pmd/pull/4021): \[core] CPD: Add total number of tokens to XML reports - [@maikelsteneker](https://github.com/maikelsteneker)
* [#4056](https://github.com/pmd/pmd/pull/4056): \[apex] ApexSOQLInjection: Add support count query - [@gwilymatgearset](https://github.com/gwilymatgearset)
* [#4061](https://github.com/pmd/pmd/pull/4061): \[lua] Fix several related Lua parsing issues found when using CPD - [@matthargett](https://github.com/matthargett)
### Stats
* 102 commits
* 26 closed tickets & PRs
* Days since last release: 35
## 25-June-2022 - 6.47.0
The PMD team is pleased to announce PMD 6.47.0.

View File

@ -59,8 +59,8 @@
<property name="base-class-name" value="Abstract${lang-name}Node" />
<!-- This will be moved to impl package when all language modules have been ported -->
<property name="base-tokenmgr" value="${ast-api-package}.AbstractTokenManager"/>
<property name="charstream-itf" value="${ast-api-package}.CharStream"/>
<property name="base-tokenmgr" value="${ast-impl-package}.AbstractTokenManager"/>
<property name="charstream-itf" value="${ast-impl-package}.CharStream"/>
<property name="tokenmgr-name" value="${parser-name}TokenManager" />
@ -284,6 +284,25 @@
<substitution expression="protected Token jjFillToken() {return input_stream.getTokenDocument().createToken(jjmatchedKind, input_stream, jjstrLiteralImages[jjmatchedKind]);}" />
</replaceregexp>
<!-- Renamed CharStream methods -->
<replaceregexp flags="g">
<file name="${tokenmgr-file}" />
<regexp pattern="image.append\(input_stream.GetSuffix\(" />
<substitution expression="input_stream.appendSuffix(image,(" />
</replaceregexp>
<replaceregexp flags="g">
<file name="${tokenmgr-file}" />
<regexp pattern="input_stream.GetImage" />
<substitution expression="input_stream.getTokenImage" />
</replaceregexp>
<replaceregexp flags="g">
<file name="${tokenmgr-file}" />
<regexp pattern="input_stream.BeginToken" />
<substitution expression="input_stream.markTokenStart" />
</replaceregexp>
<!-- This is used to allow for tokens to be immutable. The lexical actions
return the new token instead of mutating it. -->
<replaceregexp flags="sg">
@ -397,7 +416,7 @@ public final class ${token-constants-name} \{${line.separator}
* be used as a basis for a CPD Tokenizer.
*/
@net.sourceforge.pmd.annotation.InternalApi
public static net.sourceforge.pmd.lang.TokenManager<%%%API_PACK%%%.impl.javacc.JavaccToken> newTokenManager(%%%API_PACK%%%.CharStream cs) {
public static net.sourceforge.pmd.lang.TokenManager<%%%API_PACK%%%.impl.javacc.JavaccToken> newTokenManager(%%%API_PACK%%%.impl.javacc.CharStream cs) {
return new %%%TOKEN_MGR_NAME%%%(cs);
}
@ -406,6 +425,17 @@ public final class ${token-constants-name} \{${line.separator}
<fileset file="${token-constants-file}" />
</replace>
<replace>
<replacetoken>};</replacetoken>
<replacevalue><![CDATA[
};
/** Nams of the tokens, each index corresponds to a kind. See also {@link #describe(int)}. */
public static final java.util.List<String> TOKEN_NAMES = java.util.Collections.unmodifiableList(java.util.Arrays.asList(tokenImage));
]]> </replacevalue>
<fileset file="${token-constants-file}" />
</replace>
<replaceregexp>
<regexp pattern="%%%TOKEN_MGR_NAME%%%" />
<substitution expression="${tokenmgr-name}" />

View File

@ -4,21 +4,25 @@
package net.sourceforge.pmd.lang.apex;
import static net.sourceforge.pmd.util.CollectionUtil.listOf;
import net.sourceforge.pmd.lang.BaseLanguageModule;
import net.sourceforge.pmd.util.CollectionUtil;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
import apex.jorje.services.Version;
public class ApexLanguageModule extends BaseLanguageModule {
private static final String FIRST_EXTENSION = "cls";
private static final String[] REMAINING_EXTENSIONS = {"trigger"};
public static final String NAME = "Apex";
public static final String TERSE_NAME = "apex";
public static final String[] EXTENSIONS = CollectionUtil.listOf(FIRST_EXTENSION, REMAINING_EXTENSIONS).toArray(new String[0]);
public ApexLanguageModule() {
super(NAME, null, TERSE_NAME, FIRST_EXTENSION, REMAINING_EXTENSIONS);
super(NAME, null, TERSE_NAME, listOf("cls", "trigger"));
addVersion(String.valueOf((int) Version.CURRENT.getExternal()), new ApexHandler(), true);
}
public static Language getInstance() {
return LanguageRegistry.PMD.getLanguageByFullName(NAME);
}
}

View File

@ -19,7 +19,15 @@ public final class ASTAssignmentExpression extends AbstractApexNode<AssignmentEx
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public AssignmentOp getOperator() {
return node.getOp();
}
public AssignmentOperator getOp() {
return AssignmentOperator.valueOf(node.getOp());
}
}

View File

@ -19,7 +19,15 @@ public final class ASTBinaryExpression extends AbstractApexNode<BinaryExpression
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public BinaryOp getOperator() {
return node.getOp();
}
public BinaryOperator getOp() {
return BinaryOperator.valueOf(node.getOp());
}
}

View File

@ -21,9 +21,15 @@ public final class ASTBooleanExpression extends AbstractApexNode<BooleanExpressi
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public BooleanOp getOperator() {
return this.node.getOp();
}
public BooleanOperator getOp() {
return BooleanOperator.valueOf(this.node.getOp());
}
}

View File

@ -21,8 +21,15 @@ public final class ASTPostfixExpression extends AbstractApexNode<PostfixExpressi
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public PostfixOp getOperator() {
return node.getOp();
}
public PostfixOperator getOp() {
return PostfixOperator.valueOf(node.getOp());
}
}

View File

@ -19,8 +19,15 @@ public final class ASTPrefixExpression extends AbstractApexNode<PrefixExpression
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public PrefixOp getOperator() {
return node.getOp();
}
public PrefixOperator getOp() {
return PrefixOperator.valueOf(node.getOp());
}
}

View File

@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.semantic.ast.compilation.UserEnum;
public final class ASTUserEnum extends BaseApexClass<UserEnum> {
private ApexQualifiedName qname;
ASTUserEnum(UserEnum userEnum) {
super(userEnum);
@ -17,4 +18,19 @@ public final class ASTUserEnum extends BaseApexClass<UserEnum> {
return visitor.visit(this, data);
}
@Override
public ApexQualifiedName getQualifiedName() {
if (qname == null) {
ASTUserClass parent = this.getFirstParentOfType(ASTUserClass.class);
if (parent != null) {
qname = ApexQualifiedName.ofNestedEnum(parent.getQualifiedName(), this);
} else {
qname = ApexQualifiedName.ofOuterEnum(this);
}
}
return qname;
}
}

View File

@ -37,9 +37,7 @@ public final class ApexParser implements Parser {
final Compilation astRoot = CompilerService.INSTANCE.parseApex(task.getTextDocument());
if (astRoot == null) {
throw new ParseException("Couldn't parse the source - there is not root node - Syntax Error??");
}
assert astRoot != null : "Normally replaced by Compilation.INVALID";
String property = task.getProperties().getProperty(MULTIFILE_DIRECTORY);
ApexMultifileAnalysis analysisHandler = ApexMultifileAnalysis.getAnalysisInstance(property);
@ -48,7 +46,7 @@ public final class ApexParser implements Parser {
final ApexTreeBuilder treeBuilder = new ApexTreeBuilder(task);
return treeBuilder.buildTree(astRoot, analysisHandler);
} catch (apex.jorje.services.exception.ParseException e) {
throw new ParseException(e);
throw new ParseException(e).setFileName(task.getFileDisplayName());
}
}
}

View File

@ -159,6 +159,20 @@ public final class ApexQualifiedName {
}
static ApexQualifiedName ofOuterEnum(ASTUserEnum astUserEnum) {
String ns = astUserEnum.getNamespace();
String[] classes = {astUserEnum.getImage()};
return new ApexQualifiedName(StringUtils.isEmpty(ns) ? "c" : ns, classes, null);
}
static ApexQualifiedName ofNestedEnum(ApexQualifiedName parent, ASTUserEnum astUserEnum) {
String[] classes = Arrays.copyOf(parent.classes, parent.classes.length + 1);
classes[classes.length - 1] = astUserEnum.getImage();
return new ApexQualifiedName(parent.nameSpace, classes, null);
}
private static String getOperationString(ASTMethod node) {
StringBuilder sb = new StringBuilder();
sb.append(node.getImage()).append('(');
@ -182,6 +196,14 @@ public final class ApexQualifiedName {
static ApexQualifiedName ofMethod(ASTMethod node) {
// Check first, as enum must be innermost potential parent
ASTUserEnum enumParent = node.ancestors(ASTUserEnum.class).first();
if (enumParent != null) {
ApexQualifiedName baseName = enumParent.getQualifiedName();
return new ApexQualifiedName(baseName.nameSpace, baseName.classes, getOperationString(node));
}
ASTUserClassOrInterface<?> parent = node.ancestors(ASTUserClassOrInterface.class).firstOrThrow();
if (parent instanceof ASTUserTrigger) {
ASTUserTrigger trigger = (ASTUserTrigger) parent;

View File

@ -0,0 +1,67 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.AssignmentOp;
/**
* Apex assignment operator
*/
public enum AssignmentOperator {
EQUALS("="),
ADDITION_EQUALS("+="),
SUBTRACTION_EQUALS("-="),
MULTIPLICATION_EQUALS("*="),
DIVISION_EQUALS("/="),
LEFT_SHIFT_EQUALS("<<="),
RIGHT_SHIFT_SIGNED_EQUALS(">>="),
RIGHT_SHIFT_UNSIGNED_EQUALS(">>>="),
BITWISE_AND_EQUALS("&="),
BITWISE_OR_EQUALS("|="),
BITWISE_XOR_EQUALS("^=");
private final String symbol;
AssignmentOperator(String symbol) {
this.symbol = symbol;
}
@Override
public String toString() {
return this.symbol;
}
/**
* Returns a {@link AssignmentOperator} corresponding to the given {@link AssignmentOp}.
*/
public static AssignmentOperator valueOf(AssignmentOp op) {
switch (op) {
case EQUALS:
return EQUALS;
case ADDITION_EQUALS:
return ADDITION_EQUALS;
case SUBTRACTION_EQUALS:
return SUBTRACTION_EQUALS;
case MULTIPLICATION_EQUALS:
return MULTIPLICATION_EQUALS;
case DIVISION_EQUALS:
return DIVISION_EQUALS;
case LEFT_SHIFT_EQUALS:
return LEFT_SHIFT_EQUALS;
case RIGHT_SHIFT_EQUALS:
return RIGHT_SHIFT_SIGNED_EQUALS;
case UNSIGNED_RIGHT_SHIFT_EQUALS:
return RIGHT_SHIFT_UNSIGNED_EQUALS;
case AND_EQUALS:
return BITWISE_AND_EQUALS;
case OR_EQUALS:
return BITWISE_OR_EQUALS;
case XOR_EQUALS:
return BITWISE_XOR_EQUALS;
default:
throw new IllegalArgumentException("Invalid assignment operator " + op);
}
}
}

View File

@ -0,0 +1,64 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.BinaryOp;
/**
* Apex binary operator
*/
public enum BinaryOperator {
ADDITION("+"),
SUBTRACTION("-"),
MULTIPLICATION("*"),
DIVISION("/"),
LEFT_SHIFT("<<"),
RIGHT_SHIFT_SIGNED(">>"),
RIGHT_SHIFT_UNSIGNED(">>>"),
BITWISE_AND("&"),
BITWISE_OR("|"),
BITWISE_XOR("^");
private final String symbol;
BinaryOperator(String symbol) {
this.symbol = symbol;
}
@Override
public String toString() {
return this.symbol;
}
/**
* Returns a {@link BinaryOperator} corresponding to the given {@link BinaryOp}.
*/
public static BinaryOperator valueOf(BinaryOp op) {
switch (op) {
case ADDITION:
return ADDITION;
case SUBTRACTION:
return SUBTRACTION;
case MULTIPLICATION:
return MULTIPLICATION;
case DIVISION:
return DIVISION;
case LEFT_SHIFT:
return LEFT_SHIFT;
case RIGHT_SHIFT:
return RIGHT_SHIFT_SIGNED;
case UNSIGNED_RIGHT_SHIFT:
return RIGHT_SHIFT_UNSIGNED;
case AND:
return BITWISE_AND;
case OR:
return BITWISE_OR;
case XOR:
return BITWISE_XOR;
default:
throw new IllegalArgumentException("Invalid binary operator " + op);
}
}
}

View File

@ -0,0 +1,67 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.BooleanOp;
/**
* Apex boolean operator
*/
public enum BooleanOperator {
EQUAL("=="),
NOT_EQUAL("!="),
ALT_NOT_EQUAL("<>"),
EXACTLY_EQUAL("==="),
EXACTLY_NOT_EQUAL("!=="),
LESS_THAN("<"),
GREATER_THAN(">"),
LESS_THAN_OR_EQUAL("<="),
GREATER_THAN_OR_EQUAL(">="),
LOGICAL_AND("&&"),
LOGICAL_OR("||");
private final String symbol;
BooleanOperator(String symbol) {
this.symbol = symbol;
}
@Override
public String toString() {
return this.symbol;
}
/**
* Returns a {@link BooleanOperator} corresponding to the given {@link BooleanOp}.
*/
public static BooleanOperator valueOf(BooleanOp op) {
switch (op) {
case DOUBLE_EQUAL:
return EQUAL;
case NOT_EQUAL:
return NOT_EQUAL;
case ALT_NOT_EQUAL:
return ALT_NOT_EQUAL;
case TRIPLE_EQUAL:
return EXACTLY_EQUAL;
case NOT_TRIPLE_EQUAL:
return EXACTLY_NOT_EQUAL;
case LESS_THAN:
return LESS_THAN;
case GREATER_THAN:
return GREATER_THAN;
case LESS_THAN_EQUAL:
return LESS_THAN_OR_EQUAL;
case GREATER_THAN_EQUAL:
return GREATER_THAN_OR_EQUAL;
case AND:
return LOGICAL_AND;
case OR:
return LOGICAL_OR;
default:
throw new IllegalArgumentException("Invalid boolean operator " + op);
}
}
}

View File

@ -0,0 +1,40 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.PostfixOp;
/**
* Apex postfix operator
*/
public enum PostfixOperator {
INCREMENT("++"),
DECREMENT("--");
private final String symbol;
PostfixOperator(String symbol) {
this.symbol = symbol;
}
@Override
public String toString() {
return this.symbol;
}
/**
* Returns a {@link PostfixOperator} corresponding to the given {@link PostfixOp}.
*/
public static PostfixOperator valueOf(PostfixOp op) {
switch (op) {
case INC:
return INCREMENT;
case DEC:
return DECREMENT;
default:
throw new IllegalArgumentException("Invalid postfix operator " + op);
}
}
}

View File

@ -0,0 +1,52 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.PrefixOp;
/**
* Apex prefix operator
*/
public enum PrefixOperator {
POSITIVE("+"),
NEGATIVE("-"),
LOGICAL_NOT("!"),
BITWISE_NOT("~"),
INCREMENT("++"),
DECREMENT("--");
private final String symbol;
PrefixOperator(String symbol) {
this.symbol = symbol;
}
@Override
public String toString() {
return this.symbol;
}
/**
* Returns a {@link PrefixOperator} corresponding to the given {@link PrefixOp}.
*/
public static PrefixOperator valueOf(PrefixOp op) {
switch (op) {
case POSITIVE:
return POSITIVE;
case NEGATIVE:
return NEGATIVE;
case NOT:
return LOGICAL_NOT;
case BITWISE_COMPLEMENT:
return BITWISE_NOT;
case INC:
return INCREMENT;
case DEC:
return DECREMENT;
default:
throw new IllegalArgumentException("Invalid prefix operator " + op);
}
}
}

View File

@ -9,8 +9,7 @@ import java.util.Set;
import net.sourceforge.pmd.lang.apex.ast.ASTBooleanExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTStandardCondition;
import apex.jorje.data.ast.BooleanOp;
import net.sourceforge.pmd.lang.apex.ast.BooleanOperator;
/**
*
@ -34,8 +33,8 @@ public final class ApexMetricsHelper {
int complexity = 0;
for (ASTBooleanExpression sub : subs) {
BooleanOp op = sub.getOperator();
if (op != null && (op == BooleanOp.AND || op == BooleanOp.OR)) {
BooleanOperator op = sub.getOp();
if (op == BooleanOperator.LOGICAL_AND || op == BooleanOperator.LOGICAL_OR) {
complexity++;
}
}

View File

@ -19,11 +19,10 @@ import net.sourceforge.pmd.lang.apex.ast.ASTTernaryExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement;
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.apex.ast.ApexVisitorBase;
import net.sourceforge.pmd.lang.apex.ast.BooleanOperator;
import net.sourceforge.pmd.lang.apex.ast.PrefixOperator;
import net.sourceforge.pmd.lang.apex.metrics.internal.CognitiveComplexityVisitor.State;
import apex.jorje.data.ast.BooleanOp;
import apex.jorje.data.ast.PrefixOp;
/**
* @author Gwilym Kuiper
*/
@ -36,7 +35,7 @@ public class CognitiveComplexityVisitor extends ApexVisitorBase<State, Void> {
private int complexity = 0;
private int nestingLevel = 0;
private BooleanOp currentBooleanOperation = null;
private BooleanOperator currentBooleanOperation = null;
private String methodName = null;
public int getComplexity() {
@ -58,7 +57,7 @@ public class CognitiveComplexityVisitor extends ApexVisitorBase<State, Void> {
complexity++;
}
void booleanOperation(BooleanOp op) {
void booleanOperation(BooleanOperator op) {
if (currentBooleanOperation != op) {
if (op != null) {
fundamentalComplexity();
@ -171,8 +170,8 @@ public class CognitiveComplexityVisitor extends ApexVisitorBase<State, Void> {
@Override
public Void visit(ASTBooleanExpression node, State state) {
BooleanOp op = node.getOperator();
if (op == BooleanOp.AND || op == BooleanOp.OR) {
BooleanOperator op = node.getOp();
if (op == BooleanOperator.LOGICAL_AND || op == BooleanOperator.LOGICAL_OR) {
state.booleanOperation(op);
}
@ -182,8 +181,8 @@ public class CognitiveComplexityVisitor extends ApexVisitorBase<State, Void> {
@Override
public Void visit(ASTPrefixExpression node, State state) {
PrefixOp op = node.getOperator();
if (op == PrefixOp.NOT) {
PrefixOperator op = node.getOp();
if (op == PrefixOperator.LOGICAL_NOT) {
state.booleanOperation(null);
}

View File

@ -5,8 +5,6 @@
package net.sourceforge.pmd.lang.apex.rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitor;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.AbstractRule;
@ -14,10 +12,6 @@ import net.sourceforge.pmd.lang.rule.AbstractRule;
public abstract class AbstractApexRule extends AbstractRule
implements ApexParserVisitor {
public AbstractApexRule() {
super.setLanguage(LanguageRegistry.getLanguage(ApexLanguageModule.NAME));
}
@Override
public void apply(Node target, RuleContext ctx) {
target.acceptVisitor(this, ctx);

Some files were not shown because too many files have changed in this diff Show More