"
+ );
+ checkPitestReport "${ignoredItems[@]}"
+ ;;
+
# pitesttyle-gui)
-# mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
+# mvn -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
# # post validation is skipped, we do not test gui throughly
# ;;
diff --git a/.ci/travis.sh b/.ci/travis.sh
index 06258a13424..d57bad4f3d2 100755
--- a/.ci/travis.sh
+++ b/.ci/travis.sh
@@ -40,6 +40,13 @@ install-custom-mvn)
fi
;;
+remove-custom-mvn)
+ if [[ -n "${CUSTOM_MVN_VERSION}" ]]; then
+ rm apache-maven-${CUSTOM_MVN_VERSION}-bin.zip
+ rm -rf apache-maven-${CUSTOM_MVN_VERSION}
+ fi
+ ;;
+
run-command)
if [[ $RUN_JOB == 1 ]]; then
echo "eval of CMD is starting";
diff --git a/.ci/validation.sh b/.ci/validation.sh
index 5e78a6ecaa9..3a3f26a941e 100755
--- a/.ci/validation.sh
+++ b/.ci/validation.sh
@@ -85,16 +85,6 @@ eclipse-static-analysis)
mvn -e --no-transfer-progress clean compile exec:exec -Peclipse-compiler
;;
-eclipse-static-analysis-java11)
- # Ensure that project sources can be compiled by eclipse with Java11 language features.
- mvn -e --no-transfer-progress clean compile exec:exec -Peclipse-compiler -D java.version=11
- ;;
-
-java11-verify)
- # Ensure that project sources can be compiled by jdk with Java11 language features.
- mvn -e --no-transfer-progress clean verify -D java.version=11
- ;;
-
nondex)
# Below we exclude test that fails due to picocli library usage
mvn -e --no-transfer-progress --fail-never clean nondex:nondex -DargLine='-Xms1024m -Xmx2048m' \
@@ -479,7 +469,7 @@ check-since-version)
fi
;;
-javac8)
+javac11)
# InputCustomImportOrderNoPackage2 - nothing is required in front of first import
# InputIllegalTypePackageClassName - bad import for testing
# InputVisibilityModifierPackageClassName - bad import for testing
@@ -496,20 +486,6 @@ javac8)
done
;;
-javac9)
- files=($(grep -Rl --include='*.java' ': Compilable with Java9' \
- src/test/resources-noncompilable || true))
- if [[ ${#files[@]} -eq 0 ]]; then
- echo "No Java9 files to process"
- else
- mkdir -p target
- for file in "${files[@]}"
- do
- javac --release 9 -d target "${file}"
- done
- fi
- ;;
-
javac14)
files=($(grep -Rl --include='*.java' ': Compilable with Java14' \
src/test/resources-noncompilable || true))
@@ -610,7 +586,7 @@ no-error-pgjdbc)
checkout_from https://github.com/pgjdbc/pgjdbc.git
cd .ci-temp/pgjdbc
# pgjdbc easily damage build, we should use stable versions
- git checkout "3a2bb""d77969903f8a4ce721d45905c72bd1688d6"
+ git checkout "417c9a2354ad""c3d2c80f84b0a5059ce""ad92e7c2b"
./gradlew --no-parallel --no-daemon checkstyleAll \
-PenableMavenLocal -Pcheckstyle.version=${CS_POM_VERSION}
cd ../
@@ -632,7 +608,7 @@ no-error-orekit)
# no CI is enforced in project, so to make our build stable we should
# checkout to latest release/development (annotated tag or hash) or sha that have fix we need
# git checkout $(git describe --abbrev=0 --tags)
- git checkout "76760bf""bf""b847e227490cd5d3662f""ca087f1a324"
+ git checkout "851de782c6""d16d""f725fa""bb4646ff0dd086723415"
mvn -e --no-transfer-progress compile checkstyle:check \
-Dorekit.checkstyle.version=${CS_POM_VERSION}
cd ..
@@ -645,10 +621,12 @@ no-error-hibernate-search)
echo CS_version: ${CS_POM_VERSION}
checkout_from https://github.com/hibernate/hibernate-search.git
cd .ci-temp/hibernate-search
- mvn -e --no-transfer-progress clean install -DskipTests=true -Dtest.elasticsearch.run.skip=true \
+ mvn -e --no-transfer-progress clean install -pl build/config -am \
+ -DskipTests=true -Dmaven.compiler.failOnWarning=false \
-Dcheckstyle.skip=true -Dforbiddenapis.skip=true \
- -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}
- mvn -e --no-transfer-progress checkstyle:check -Dpuppycrawl.checkstyle.version=${CS_POM_VERSION}
+ -Dversion.com.puppycrawl.tools.checkstyle=${CS_POM_VERSION}
+ mvn -e --no-transfer-progress checkstyle:check \
+ -Dversion.com.puppycrawl.tools.checkstyle=${CS_POM_VERSION}
cd ../
removeFolderWithProtectedFiles hibernate-search
;;
@@ -724,7 +702,8 @@ no-error-equalsverifier)
echo CS_version: ${CS_POM_VERSION}
checkout_from https://github.com/jqno/equalsverifier.git
cd .ci-temp/equalsverifier
- mvn -e --no-transfer-progress compile checkstyle:check -Dcheckstyle.version=${CS_POM_VERSION}
+ mvn -e --no-transfer-progress -Pstatic-analysis-checkstyle compile \
+ checkstyle:check -Dversion.checkstyle=${CS_POM_VERSION}
cd ../
removeFolderWithProtectedFiles equalsverifier
;;
diff --git a/.circleci/config.yml b/.circleci/config.yml
index c02379d8c6b..4171c9aae29 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -3,7 +3,7 @@ jobs:
no-exception-lucene-and-others-javadoc:
docker:
- - image: checkstyle/jdk-8-groovy-git-mvn:1.8.0_282-3.0.8-2.25.1-3.6.3
+ - image: &default-image checkstyle/jdk-11-groovy-git-mvn:11.0.13__3.0.9__2.25.1__3.6.3
steps:
- checkout
- run:
@@ -11,7 +11,7 @@ jobs:
./.ci/no-exception-test.sh no-exception-lucene-and-others-javadoc
no-exception-cassandra-storm-tapestry-javadoc:
docker:
- - image: checkstyle/jdk-8-groovy-git-mvn:1.8.0_282-3.0.8-2.25.1-3.6.3
+ - image: *default-image
steps:
- checkout
- run:
@@ -19,7 +19,7 @@ jobs:
./.ci/no-exception-test.sh no-exception-cassandra-storm-tapestry-javadoc
no-exception-hadoop-apache-groovy-scouter-javadoc:
docker:
- - image: checkstyle/jdk-8-groovy-git-mvn:1.8.0_282-3.0.8-2.25.1-3.6.3
+ - image: *default-image
steps:
- checkout
- run:
@@ -27,7 +27,7 @@ jobs:
./.ci/no-exception-test.sh no-exception-hadoop-apache-groovy-scouter-javadoc
no-exception-only-javadoc:
docker:
- - image: checkstyle/jdk-8-groovy-git-mvn:1.8.0_282-3.0.8-2.25.1-3.6.3
+ - image: *default-image
steps:
- checkout
- run:
@@ -35,7 +35,7 @@ jobs:
./.ci/no-exception-test.sh no-exception-only-javadoc
no-error-xwiki:
docker:
- - image: checkstyle/jdk-11-groovy-git-mvn:11.0.13__3.0.9__2.25.1__3.6.3
+ - image: *default-image
steps:
- checkout
- run:
diff --git a/.drone.yml b/.drone.yml
index dc46d6fcd12..04a46d4770c 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -8,7 +8,7 @@ volumes:
steps:
- name: restore-cache
- image: maven:3.6.3-adoptopenjdk-8
+ image: &default-image maven:3.8.4-openjdk-11
failure: ignore
volumes:
- name: m2-cache
@@ -17,7 +17,7 @@ steps:
- ./.ci/drone-io.sh restore-maven-cache
- name: checkstyle-and-sevntu
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
environment:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
volumes:
@@ -27,7 +27,7 @@ steps:
- ./.ci/validation.sh checkstyle-and-sevntu
- name: spotbugs-and-pmd
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
environment:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
volumes:
@@ -46,7 +46,7 @@ volumes:
steps:
- name: restore-cache
- image: maven:3.6.3-adoptopenjdk-8
+ image: &default-image maven:3.8.4-openjdk-11
failure: ignore
volumes:
- name: m2-cache
@@ -55,7 +55,7 @@ steps:
- ./.ci/drone-io.sh restore-maven-cache
- name: site
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
environment:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
volumes:
@@ -75,7 +75,7 @@ volumes:
steps:
- name: restore-cache
- image: maven:3.6.3-adoptopenjdk-8
+ image: &default-image maven:3.8.4-openjdk-11
failure: ignore
volumes:
- name: m2-cache
@@ -84,7 +84,7 @@ steps:
- ./.ci/drone-io.sh restore-maven-cache
- name: release-dry-run
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
environment:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
volumes:
@@ -94,7 +94,7 @@ steps:
- ./.ci/validation.sh release-dry-run
- name: assembly-run-all-jar
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
environment:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
volumes:
@@ -113,7 +113,7 @@ volumes:
steps:
- name: restore-cache
- image: maven:3.6.3-adoptopenjdk-8
+ image: &default-image maven:3.8.4-openjdk-11
failure: ignore
volumes:
- name: m2-cache
@@ -122,7 +122,7 @@ steps:
- ./.ci/drone-io.sh restore-maven-cache
- name: releasenotes-gen
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
environment:
READ_ONLY_TOKEN:
from_secret: READ_ONLY_TOKEN
@@ -139,25 +139,19 @@ name: non-mvn_javac
steps:
- name: check-chmod
- image: maven:3.6.3-adoptopenjdk-8
+ image: &default-image maven:3.8.4-openjdk-11
commands:
- ./.ci/checkchmod.sh
- name: check-since-version
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
commands:
- ./.ci/validation.sh check-since-version
-- name: javac8
- image: maven:3.6.3-adoptopenjdk-8
+- name: javac11
+ image: *default-image
commands:
- - ./.ci/validation.sh javac8
-
-
-- name: javac9
- image: maven:3.6.3-jdk-11
- commands:
- - ./.ci/validation.sh javac9
+ - ./.ci/validation.sh javac11
- name: javac14
image: maven:3.6.3-adoptopenjdk-14
@@ -189,7 +183,7 @@ volumes:
steps:
- name: restore-cache
- image: maven:3.6.3-adoptopenjdk-8
+ image: &default-image maven:3.8.4-openjdk-11
failure: ignore
volumes:
- name: m2-cache
@@ -208,7 +202,7 @@ steps:
- ./.ci/validation.sh jdk14-assembly-site
- name: assembly/site with OpenJDK11
- image: maven:3.6.3-adoptopenjdk-11
+ image: *default-image
environment:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
volumes:
@@ -219,7 +213,7 @@ steps:
mvn -e --no-transfer-progress site -Dlinkcheck.skip=true"
- name: no-error-test-sbe
- image: maven:3.6.3-adoptopenjdk-8
+ image: *default-image
environment:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2"
volumes:
diff --git a/.github/workflows/no-exception-workflow.yml b/.github/workflows/no-exception-workflow.yml
index 754dfae9e47..7781a90a184 100644
--- a/.github/workflows/no-exception-workflow.yml
+++ b/.github/workflows/no-exception-workflow.yml
@@ -9,10 +9,10 @@ jobs:
no-exception-openjdk17:
runs-on: ubuntu-latest
steps:
- - name: Set up JDK 8
+ - name: Set up JDK 11
uses: actions/setup-java@v1
with:
- java-version: 8
+ java-version: 11
- name: Install dependencies
run: sudo apt install groovy
diff --git a/.github/workflows/pitest.yml b/.github/workflows/pitest.yml
index c0c71ecfcb9..3b0f989a66c 100644
--- a/.github/workflows/pitest.yml
+++ b/.github/workflows/pitest.yml
@@ -335,10 +335,10 @@ jobs:
pitest-main:
runs-on: ubuntu-latest
steps:
- - name: Set up JDK 8
+ - name: Set up JDK 11
uses: actions/setup-java@v1
with:
- java-version: 8
+ java-version: 11
- name: Setup local maven cache
uses: actions/cache@v2
with:
@@ -642,10 +642,10 @@ jobs:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- - name: Set up JDK 8
+ - name: Set up JDK 11
uses: actions/setup-java@v1
with:
- java-version: 8
+ java-version: 11
- name: Generate pitest report
run: ./.ci/pitest.sh pitest-java-ast-visitor
diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml
index de06658d38d..f613cdb69b0 100644
--- a/.semaphore/semaphore.yml
+++ b/.semaphore/semaphore.yml
@@ -3,7 +3,7 @@ name: "Checkstyle CI pipeline on Semaphore"
agent:
machine:
type: e1-standard-2
- os_image: ubuntu1804
+ os_image: ubuntu2004
auto_cancel:
running:
when: "branch != 'master'"
@@ -27,20 +27,21 @@ blocks:
cache store m2 $HOME/.m2
fi
jobs:
- - name: NonDex (openjdk8)
- priority:
- - value: 90
- when: true
- matrix:
- - env_var: CMD
- values:
- - .ci/validation.sh nondex
- commands:
- - sem-version java 8 # NonDex only supports Java 8
- - echo "eval of CMD is starting";
- - echo "CMD=$CMD";
- - eval $CMD;
- - echo "eval of CMD is completed";
+ # NonDex supports only Java 8 till https://github.com/TestingResearchIllinois/NonDex/pull/155
+ # - name: NonDex (openjdk11)
+ # priority:
+ # - value: 90
+ # when: true
+ # matrix:
+ # - env_var: CMD
+ # values:
+ # - .ci/validation.sh nondex
+ # commands:
+ # - sem-version java 11
+ # - echo "eval of CMD is starting";
+ # - echo "CMD=$CMD";
+ # - eval $CMD;
+ # - echo "eval of CMD is completed";
- name: Validation (openjdk11, fast pool)
matrix:
@@ -49,13 +50,9 @@ blocks:
- .ci/validation.sh all-sevntu-checks
- .ci/validation.sh check-missing-pitests
- .ci/validation.sh eclipse-static-analysis
- - .ci/validation.sh eclipse-static-analysis-java11
- - .ci/validation.sh java11-verify
- .ci/validation.sh verify-regexp-id
- - mvn -e --no-transfer-progress clean install -Pno-validations
- && .ci/no-exception-test.sh guava-with-google-checks
- - mvn -e --no-transfer-progress clean install -Pno-validations
- && .ci/no-exception-test.sh guava-with-sun-checks
+ - .ci/no-exception-test.sh guava-with-google-checks
+ - .ci/no-exception-test.sh guava-with-sun-checks
# until https://github.com/checkstyle/checkstyle/issues/9807
# - mvn -e --no-transfer-progress clean package -Passembly
# && .ci/validation.sh no-violation-test-josm
diff --git a/.travis.yml b/.travis.yml
index 9f3f94fbcb1..f0c6277fc4a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,8 +26,8 @@ jobs:
include:
# this job do deploy maven repository
- # unit tests (openjdk8)
- - jdk: openjdk8
+ # unit tests (openjdk11)
+ - jdk: openjdk11
env:
- DESC="tests and deploy"
- CMD="mvn -e --no-transfer-progress clean integration-test failsafe:verify
@@ -43,7 +43,7 @@ jobs:
# - CMD2="./.ci/validation.sh verify-no-exception-configs"
# - CMD="$CMD1 && $CMD2"
- - jdk: openjdk8
+ - jdk: openjdk11
env:
- DESC="NoErrorTest - Postgresql JDBC Driver"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
@@ -51,7 +51,7 @@ jobs:
- CMD="$CMD1 && $CMD2"
- USE_MAVEN_REPO="true"
- - jdk: openjdk8
+ - jdk: openjdk11
env:
- DESC="NoErrorTest - Orekit"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
@@ -62,7 +62,7 @@ jobs:
- jdk: openjdk11
env:
- DESC="NoErrorTest - Hibernate Search"
- - CUSTOM_MVN_VERSION="3.8.1"
+ - CUSTOM_MVN_VERSION="3.8.4"
- M2_HOME="$PWD/apache-maven-${CUSTOM_MVN_VERSION}"
- PATH="$M2_HOME/bin:$PATH"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
@@ -70,7 +70,7 @@ jobs:
- CMD="$CMD1 && $CMD2"
- USE_MAVEN_REPO="true"
- - jdk: openjdk8
+ - jdk: openjdk11
env:
- DESC="NoErrorTest - checkstyle's sevntu"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
@@ -78,7 +78,7 @@ jobs:
- CMD="$CMD1 && $CMD2"
- USE_MAVEN_REPO="true"
- - jdk: openjdk8
+ - jdk: openjdk11
env:
- DESC="NoErrorTest - sevntu-checks"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
@@ -86,7 +86,7 @@ jobs:
- CMD="$CMD1 && $CMD2"
- USE_MAVEN_REPO="true"
- - jdk: openjdk8
+ - jdk: openjdk11
env:
- DESC="NoErrorTest - contribution"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
@@ -94,7 +94,7 @@ jobs:
- CMD="$CMD1 && $CMD2"
- USE_MAVEN_REPO="true"
- - jdk: openjdk8
+ - jdk: openjdk11
env:
- DESC="NoErrorTest - methods distance"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
@@ -102,28 +102,29 @@ jobs:
- CMD="$CMD1 && $CMD2"
- USE_MAVEN_REPO="true"
- - jdk: openjdk8
+ - jdk: openjdk11
env:
- DESC="NoErrorTest - Spring Cloud GCP"
- CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
- CMD2="./.ci/validation.sh no-error-spring-cloud-gcp"
- CMD="$CMD1 && $CMD2"
- USE_MAVEN_REPO="true"
- # until https://github.com/jqno/equalsverifier/issues/586
- # - jdk: openjdk8
- # env:
- # - DESC="NoErrorTest - EqualsVerifier"
- # - CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
- # - CMD2="./.ci/validation.sh no-error-equalsverifier"
- # - CMD="$CMD1 && $CMD2"
- # - USE_MAVEN_REPO="true"
+
+ - jdk: openjdk11
+ env:
+ - DESC="NoErrorTest - EqualsVerifier"
+ - CMD1="mvn -e --no-transfer-progress clean install -Pno-validations"
+ - CMD2="./.ci/validation.sh no-error-equalsverifier"
+ - CMD="$CMD1 && $CMD2"
+ - USE_MAVEN_REPO="true"
script:
- ./.ci/travis.sh init-m2-repo
- ./.ci/travis.sh run-command "$CMD"
+ - ./.ci/travis.sh remove-custom-mvn
+ - ./.ci/travis.sh git-diff
+ - ./.ci/travis.sh ci-temp-check
after_success:
- ./.ci/travis.sh run-command-after-success
- ./.ci/travis.sh deploy-snapshot
- - ./.ci/travis.sh git-diff
- - ./.ci/travis.sh ci-temp-check
diff --git a/appveyor.yml b/appveyor.yml
index 524237042a6..ced9cb79325 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -11,21 +11,21 @@ branches:
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
- if (!(Test-Path -Path "C:\maven\apache-maven-3.8.1" )) {
+ if (!(Test-Path -Path "C:\maven\apache-maven-3.8.4" )) {
(new-object System.Net.WebClient).DownloadFile(
- 'https://downloads.apache.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.zip',
+ 'https://downloads.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.zip',
'C:\maven-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
- - cmd: SET M2_HOME=C:\maven\apache-maven-3.8.1
+ - cmd: SET M2_HOME=C:\maven\apache-maven-3.8.4
- cmd: SET PATH=%M2_HOME%\bin;%JAVA_HOME%\bin;%PATH%
- cmd: git config core.autocrlf
- cmd: mvn --version
- cmd: java -version
cache:
- - C:\maven\apache-maven-3.8.1
+ - C:\maven\apache-maven-3.8.4
- C:\Users\appveyor\.m2
matrix:
@@ -39,26 +39,14 @@ environment:
# We do matrix as AppVeyor could fail to finish simple "mvn -e verify"
# if he loose maven cache (happens from time to time)
matrix:
- # checkstyle and sevntu.checkstyle (JDK8)
- - JAVA_HOME: C:\Program Files\Java\jdk1.8.0
- DESC: "checkstyle and sevntu.checkstyle (JDK8)"
- CMD: "./.ci/validation.cmd sevntu"
# checkstyle and sevntu.checkstyle (JDK11)
- JAVA_HOME: C:\Program Files\Java\jdk11
DESC: "checkstyle and sevntu.checkstyle (JDK11)"
CMD: "./.ci/validation.cmd sevntu"
- # verify without checkstyle (JDK8)
- - JAVA_HOME: C:\Program Files\Java\jdk1.8.0
- DESC: "verify without checkstyle (JDK8)"
- CMD: "./.ci/validation.cmd verify_without_checkstyle"
# verify without checkstyle (JDK11)
- JAVA_HOME: C:\Program Files\Java\jdk11
DESC: "verify without checkstyle (JDK11)"
CMD: "./.ci/validation.cmd verify_without_checkstyle"
- # site, without verify (JDK8)
- - JAVA_HOME: C:\Program Files\Java\jdk1.8.0
- DESC: "site, without verify (JDK8)"
- CMD: "./.ci/validation.cmd site_without_verify"
# site, without verify (JDK11)
- JAVA_HOME: C:\Program Files\Java\jdk11
DESC: "site, without verify (JDK11)"
@@ -79,5 +67,5 @@ build_script:
Write-Host "build is skipped ..."
}
- ps: echo "Size of caches (bytes):"
- - ps: Get-ChildItem -Recurse 'C:\maven\apache-maven-3.8.1' | Measure-Object -Property Length -Sum
+ - ps: Get-ChildItem -Recurse 'C:\maven\apache-maven-3.8.4' | Measure-Object -Property Length -Sum
- ps: Get-ChildItem -Recurse 'C:\Users\appveyor\.m2' | Measure-Object -Property Length -Sum
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index df295c49e18..d1478e46aac 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -30,47 +30,47 @@ strategy:
cmd: "./.ci/test-spelling-unknown-words.sh"
skipCache: true
- # unit tests (openjdk8)
+ # unit tests (openjdk11)
'test':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test"
- # unit tests in German locale (openjdk8)
+ # unit tests in German locale (openjdk11)
'test-de':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-de"
- # unit tests in Spanish locale (openjdk8)
+ # unit tests in Spanish locale (openjdk11)
'test-es':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-es"
- # unit tests in Finnish locale (openjdk8)
+ # unit tests in Finnish locale (openjdk11)
'test-fi':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-fi"
- # unit tests in French locale (openjdk8)
+ # unit tests in French locale (openjdk11)
'test-fr':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-fr"
- # unit tests in Chinese locale (openjdk8)
+ # unit tests in Chinese locale (openjdk11)
'test-zh':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-zh"
- # unit tests in Japanese locale (openjdk8)
+ # unit tests in Japanese locale (openjdk11)
'test-ja':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-ja"
- # unit tests in Portuguese locale (openjdk8)
+ # unit tests in Portuguese locale (openjdk11)
'test-pt':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-pt"
- # unit tests in Turkish locale (openjdk8)
+ # unit tests in Turkish locale (openjdk11)
'test-tr':
image: 'ubuntu-20.04'
cmd: "./.ci/validation.sh test-tr"
@@ -80,25 +80,15 @@ strategy:
image: 'ubuntu-20.04'
cmd: "mvn -e --no-transfer-progress verify"
- # MacOS JDK8 verify
- 'MacOS JDK8 verify':
- image: 'macOS-10.15'
- cmd: "export JAVA_HOME=$JAVA_HOME_8_X64 && mvn -e --no-transfer-progress verify"
-
# MacOS JDK11 verify
'MacOS JDK11 verify':
image: 'macOS-10.15'
- cmd: "export JAVA_HOME=$JAVA_HOME_11_X64 && mvn -e --no-transfer-progress verify"
-
- # MacOS JDK13 verify
- 'MacOS JDK13 verify':
- image: 'macOS-10.15'
- cmd: "export JAVA_HOME=$JAVA_HOME_13_X64 && mvn -e --no-transfer-progress verify"
+ cmd: "JAVA_HOME=$JAVA_HOME_11_X64 mvn -e --no-transfer-progress verify"
- # MacOS JDK14 verify
+ # MacOS JDK17 verify
'MacOS JDK14 verify':
- image: 'macOS-10.15'
- cmd: "export JAVA_HOME=$JAVA_HOME_14_X64 && mvn -e --no-transfer-progress verify"
+ image: 'macOS-11'
+ cmd: "JAVA_HOME=$JAVA_HOME_17_X64 mvn -e --no-transfer-progress verify"
# moved back to Travis till we find a way to keep secrets in azure
# ensure that all modules are used in no exception configs
@@ -126,7 +116,7 @@ pool:
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
- MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
+ MAVEN_OPTS: '--show-version -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
SKIP_CACHE: $(skipCache)
IMAGE: $(image)
ON_CRON_ONLY: $(onCronOnly)
@@ -147,6 +137,12 @@ steps:
gem install mdl
condition: eq(variables.NEED_MDL, 'true')
+- task: JavaToolInstaller@0
+ inputs:
+ versionSpec: 11
+ jdkArchitectureOption: 'X64'
+ jdkSourceOption: 'PreInstalled'
+
- task: Cache@2
inputs:
key: 'maven | "$(Agent.OS)" | **/pom.xml'
diff --git a/config/checkstyle_checks.xml b/config/checkstyle_checks.xml
index 05c56d16b2e..49039b3aaea 100644
--- a/config/checkstyle_checks.xml
+++ b/config/checkstyle_checks.xml
@@ -462,6 +462,14 @@
+
+
+
+
+
-
+
diff --git a/config/version-number-rules.xml b/config/version-number-rules.xml
index 507c4c39eef..1c984ebb1d1 100644
--- a/config/version-number-rules.xml
+++ b/config/version-number-rules.xml
@@ -26,12 +26,6 @@
.*
-
-
-
- .*
-
-
diff --git a/pom.xml b/pom.xml
index 1edd855e2e4..4711850e513 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
com.puppycrawl.toolscheckstyle
- 9.3
+ 10.0jarcheckstyle
@@ -200,10 +200,10 @@
${project.version}4.9.3
- 3.10.0
+ 3.11.04.2.3
- 3.15.0
- 6.41.0
+ 3.16.0
+ 6.42.00.8.74.3.110.6
@@ -213,8 +213,8 @@
9.1
2.9.0
- 1.8
- 1.7.3
+ 11
+ 1.7.410500004
@@ -229,13 +229,13 @@
com.tngtech.archunitarchunit-junit5
- 0.22.0
+ 0.23.0testinfo.picoclipicocli
- 4.6.2
+ 4.6.3org.antlr
@@ -280,13 +280,13 @@
org.itsallcodejunit5-system-extensions
- 1.1.0
+ 1.2.0testorg.junit-pioneerjunit-pioneer
- 1.5.0
+ 1.6.1test
@@ -298,7 +298,7 @@
nl.jqno.equalsverifierequalsverifier
- 3.8.3
+ 3.9test
@@ -322,7 +322,7 @@
org.slf4jslf4j-simple
- 1.7.35
+ 1.7.36test
@@ -394,7 +394,7 @@
org.codehaus.mojosonar-maven-plugin
- 3.9.0.2155
+ 3.9.1.2184org.apache.maven.plugins
@@ -416,7 +416,7 @@
org.apache.maven.pluginsmaven-javadoc-plugin
- 3.3.1
+ 3.3.2
@@ -1097,7 +1097,7 @@
org.sonatype.pluginsnexus-staging-maven-plugin
- 1.6.8
+ 1.6.12true**/XpathFileGeneratorAuditListenerTest.class
-
- **/AllChecksTest.class
- **/XdocsPagesTest.class**/DefaultConfigurationTest.class
@@ -1629,7 +1625,7 @@
maven-project-info-reports-plugin
- 3.1.2
+ 3.2.2
@@ -1872,6 +1868,7 @@
http://maven.apache.org/plugins/maven-linkcheck-plugin/https://www.ej-technologies.com/*
+ https://travis-ci.com/
@@ -2040,7 +2037,6 @@
pitest-misc
- truetrue
@@ -2132,7 +2128,6 @@
pitest-annotation
- truetrue
@@ -2177,7 +2172,6 @@
pitest-blocks
- truetrue
@@ -2222,7 +2216,6 @@
pitest-coding
- truetrue
@@ -2240,8 +2233,7 @@
INVERT_NEGSMATHNEGATE_CONDITIONALS
-
-
+ REMOVE_CONDITIONALSRETURN_VALSTRUE_RETURNSVOID_METHOD_CALLS
@@ -2256,7 +2248,7 @@
*.Input*
100
- 100
+ 99${pitest.plugin.timeout.factor}${pitest.plugin.timeout.constant}${pitest.plugin.threads}
@@ -2268,7 +2260,6 @@
pitest-design
- truetrue
@@ -2313,7 +2304,6 @@
pitest-header
- truetrue
@@ -2358,7 +2348,6 @@
pitest-imports
- truetrue
@@ -2403,7 +2392,6 @@
pitest-indentation
- truetrue
@@ -2449,7 +2437,6 @@
pitest-javadoc
- truetrue
@@ -2504,7 +2491,6 @@
pitest-metrics
- truetrue
@@ -2549,7 +2535,6 @@
pitest-modifier
- truetrue
@@ -2594,7 +2579,6 @@
pitest-naming
- truetrue
@@ -2639,7 +2623,6 @@
pitest-regexp
- truetrue
@@ -2684,7 +2667,6 @@
pitest-sizes
- truetrue
@@ -2729,7 +2711,6 @@
pitest-whitespace
- truetrue
@@ -2775,7 +2756,6 @@
pitest-ant
- truetrue
@@ -2820,7 +2800,6 @@
pitest-packagenamesloader
- truetrue
@@ -2862,7 +2841,6 @@
pitest-common
- truetrue
@@ -2944,7 +2922,6 @@
pitest-common-2
- truetrue
@@ -3007,7 +2984,6 @@
pitest-main
- truetrue
@@ -3049,7 +3025,6 @@
pitest-tree-walker
- truetrue
@@ -3143,7 +3118,6 @@
pitest-api
- truetrue
@@ -3199,7 +3173,6 @@
pitest-filters
- truetrue
@@ -3246,7 +3219,6 @@
pitest-utils
- truetrue
@@ -3336,7 +3308,6 @@
pitest-gui
- truetrue
@@ -3407,7 +3378,6 @@
pitest-xpath
- truetrue
@@ -3456,7 +3426,6 @@
pitest-java-ast-visitor
- truetrue
diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java
index 0bde24a5317..eb03d79e4f9 100644
--- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java
+++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java
@@ -53,6 +53,9 @@ public void testWhitespaceAfterBad() throws Exception {
"14:9: " + getCheckMessage(clazz, message, "if"),
"14:18: " + getCheckMessage(clazz, message, "typecast"),
"17:9: " + getCheckMessage(clazz, message, "else"),
+ "22:28: " + getCheckMessage(clazz, message, "..."),
+ "23:26: " + getCheckMessage(clazz, message, "->"),
+ "24:9: " + getCheckMessage(clazz, message, "switch"),
};
final Configuration checkConfig = getModuleConfig("WhitespaceAfter");
final String filePath = getPath("InputWhitespaceAfterBad.java");
diff --git a/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionRedundantImportTest.java b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionRedundantImportTest.java
new file mode 100644
index 00000000000..7d64edf66c2
--- /dev/null
+++ b/src/it/java/org/checkstyle/suppressionxpathfilter/XpathRegressionRedundantImportTest.java
@@ -0,0 +1,92 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2022 the original author or authors.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+
+package org.checkstyle.suppressionxpathfilter;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck;
+
+public class XpathRegressionRedundantImportTest extends AbstractXpathTestSupport {
+
+ private final String checkName = RedundantImportCheck.class.getSimpleName();
+
+ @Override
+ protected String getCheckName() {
+ return checkName;
+ }
+
+ @Test
+ public void testOne() throws Exception {
+ final File fileToProcess =
+ new File(getPath("SuppressionXpathRegressionRedundantImport1.java"));
+ final DefaultConfiguration moduleConfig =
+ createModuleConfig(RedundantImportCheck.class);
+ final String[] expectedViolation = {
+ "3:1: " + getCheckMessage(RedundantImportCheck.class,
+ RedundantImportCheck.MSG_SAME, "org.checkstyle.suppressionxpathfilter"
+ + ".redundantimport.SuppressionXpathRegressionRedundantImport1"),
+ };
+ final List expectedXpathQueries = Collections.singletonList(
+ "/COMPILATION_UNIT/IMPORT");
+
+ runVerifications(moduleConfig, fileToProcess, expectedViolation,
+ expectedXpathQueries);
+ }
+
+ @Test
+ public void testTwo() throws Exception {
+ final File fileToProcess =
+ new File(getPath("SuppressionXpathRegressionRedundantImport2.java"));
+ final DefaultConfiguration moduleConfig =
+ createModuleConfig(RedundantImportCheck.class);
+ final String[] expectedViolation = {
+ "3:1: " + getCheckMessage(RedundantImportCheck.class,
+ RedundantImportCheck.MSG_LANG, "java.lang.String"),
+ };
+ final List expectedXpathQueries = Collections.singletonList(
+ "/COMPILATION_UNIT/IMPORT");
+
+ runVerifications(moduleConfig, fileToProcess, expectedViolation,
+ expectedXpathQueries);
+ }
+
+ @Test
+ public void testThree() throws Exception {
+ final File fileToProcess =
+ new File(getPath("SuppressionXpathRegressionRedundantImport3.java"));
+ final DefaultConfiguration moduleConfig =
+ createModuleConfig(RedundantImportCheck.class);
+ final String[] expectedViolation = {
+ "4:1: " + getCheckMessage(RedundantImportCheck.class,
+ RedundantImportCheck.MSG_DUPLICATE, 3, "java.util.Scanner"),
+ };
+ final List expectedXpathQueries = Collections.singletonList(
+ "/COMPILATION_UNIT/IMPORT[./DOT/IDENT[@text='Scanner']]");
+
+ runVerifications(moduleConfig, fileToProcess, expectedViolation,
+ expectedXpathQueries);
+ }
+
+}
diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java
index dcd6abea3a8..cdacb817b15 100644
--- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java
+++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java
@@ -18,4 +18,12 @@ public void check2(final int a,final int b){ // warn
System.out.println("false");
}
}
+
+ public void check3 (int...a) { // warn
+ Runnable r2 = () ->String.valueOf("Hello world two!"); // warn
+ switch(a[0]) { // warn
+ default:
+ break;
+ }
+ }
}
diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java
index a889ea97884..dd20afb6e0e 100644
--- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java
+++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java
@@ -18,4 +18,12 @@ public void check2(final int a, final int b){
System.out.println("false");
}
}
+
+ public void check3(int... a) {
+ Runnable r2 = () -> String.valueOf("Hello world two!");
+ switch (a[0]) {
+ default:
+ break;
+ }
+ }
}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport1.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport1.java
new file mode 100644
index 00000000000..93be31e0b69
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport1.java
@@ -0,0 +1,6 @@
+package org.checkstyle.suppressionxpathfilter.redundantimport;
+
+import org.checkstyle.suppressionxpathfilter.redundantimport.SuppressionXpathRegressionRedundantImport1; // warn
+
+public class SuppressionXpathRegressionRedundantImport1 {
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport2.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport2.java
new file mode 100644
index 00000000000..9f5d2b69629
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport2.java
@@ -0,0 +1,6 @@
+package org.checkstyle.suppressionxpathfilter.redundantimport;
+
+import java.lang.String; // warn
+
+public class SuppressionXpathRegressionRedundantImport2 {
+}
diff --git a/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport3.java b/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport3.java
new file mode 100644
index 00000000000..6438f4286b2
--- /dev/null
+++ b/src/it/resources/org/checkstyle/suppressionxpathfilter/redundantimport/SuppressionXpathRegressionRedundantImport3.java
@@ -0,0 +1,7 @@
+package org.checkstyle.suppressionxpathfilter.redundantimport;
+
+import java.util.Scanner;
+import java.util.Scanner; // warn
+
+public class SuppressionXpathRegressionRedundantImport3 {
+}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java b/src/main/java/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java
index d29df50e29b..eab0cece793 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java
@@ -140,7 +140,7 @@ public void removeChild(final Configuration configuration) {
* @deprecated This shall be removed in future releases. Please use
* {@code addProperty(String propertyName, String value)} instead.
*/
- @Deprecated
+ @Deprecated(since = "8.45")
public void addAttribute(String attributeName, String value) {
addProperty(attributeName, value);
}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/Definitions.java b/src/main/java/com/puppycrawl/tools/checkstyle/Definitions.java
index cb2e6770cdd..732deded94b 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/Definitions.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/Definitions.java
@@ -19,8 +19,6 @@
package com.puppycrawl.tools.checkstyle;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
/**
@@ -33,10 +31,8 @@ public final class Definitions {
"com.puppycrawl.tools.checkstyle.messages";
/** Name of modules which are not checks, but are internal modules. */
- public static final Set INTERNAL_MODULES = Collections.unmodifiableSet(
- new HashSet<>(Collections.singletonList(
- "com.puppycrawl.tools.checkstyle.meta.JavadocMetadataScraper"
- )));
+ public static final Set INTERNAL_MODULES = Set.of(
+ "com.puppycrawl.tools.checkstyle.meta.JavadocMetadataScraper");
/**
* Do no allow {@code Definitions} instances to be created.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/JavadocPropertiesGenerator.java b/src/main/java/com/puppycrawl/tools/checkstyle/JavadocPropertiesGenerator.java
index c27b067b668..1df1a4a4d5c 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/JavadocPropertiesGenerator.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/JavadocPropertiesGenerator.java
@@ -100,8 +100,7 @@ public static void main(String... args) throws CheckstyleException {
* @throws CheckstyleException if a javadoc comment can not be parsed
*/
private static void writePropertiesFile(CliOptions options) throws CheckstyleException {
- try (PrintWriter writer = new PrintWriter(options.outputFile,
- StandardCharsets.UTF_8.name())) {
+ try (PrintWriter writer = new PrintWriter(options.outputFile, StandardCharsets.UTF_8)) {
final DetailAST top = JavaParser.parseFile(options.inputFile,
JavaParser.Options.WITH_COMMENTS).getFirstChild();
final DetailAST objBlock = getClassBody(top);
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/SarifLogger.java b/src/main/java/com/puppycrawl/tools/checkstyle/SarifLogger.java
index f3a767c56d1..8521c81d981 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/SarifLogger.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/SarifLogger.java
@@ -137,12 +137,6 @@ public void auditStarted(AuditEvent event) {
// No code by default
}
- /**
- * {@inheritDoc}
- * Following idea suppressions are false positives
- *
- * @noinspection DynamicRegexReplaceableByCompiledPattern
- */
@Override
public void auditFinished(AuditEvent event) {
final String version = SarifLogger.class.getPackage().getImplementationVersion();
@@ -158,12 +152,6 @@ public void auditFinished(AuditEvent event) {
}
}
- /**
- * {@inheritDoc}
- * Following idea suppressions are false positives
- *
- * @noinspection DynamicRegexReplaceableByCompiledPattern
- */
@Override
public void addError(AuditEvent event) {
if (event.getColumn() > 0) {
@@ -187,12 +175,6 @@ public void addError(AuditEvent event) {
}
}
- /**
- * {@inheritDoc}
- * Following idea suppressions are false positives
- *
- * @noinspection DynamicRegexReplaceableByCompiledPattern
- */
@Override
public void addException(AuditEvent event, Throwable throwable) {
final StringWriter stringWriter = new StringWriter();
@@ -305,14 +287,10 @@ public static String escape(String value) {
* @return the escaped string.
*/
private static String escapeUnicode1F(char chr) {
- final StringBuilder stringBuilder = new StringBuilder(UNICODE_LENGTH + 1);
- stringBuilder.append("\\u");
final String hexString = Integer.toHexString(chr);
- for (int i = 0; i < UNICODE_LENGTH - hexString.length(); i++) {
- stringBuilder.append('0');
- }
- stringBuilder.append(hexString.toUpperCase(Locale.US));
- return stringBuilder.toString();
+ return "\\u"
+ + "0".repeat(UNICODE_LENGTH - hexString.length())
+ + hexString.toUpperCase(Locale.US);
}
/**
@@ -334,7 +312,7 @@ public static String readResource(String name) throws IOException {
result.write(buffer, 0, length);
length = inputStream.read(buffer);
}
- return result.toString(StandardCharsets.UTF_8.name());
+ return result.toString(StandardCharsets.UTF_8);
}
}
}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractCheck.java
index 270fe0f4fef..abf88f71dc9 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/AbstractCheck.java
@@ -192,7 +192,7 @@ public final void setFileContents(FileContents contents) {
* Please use AST based methods instead.
* @noinspection WeakerAccess
*/
- @Deprecated
+ @Deprecated(since = "9.3")
public final FileContents getFileContents() {
return context.get().fileContents;
}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java
index 95c0e875d5b..656a793ff55 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/Configuration.java
@@ -36,7 +36,7 @@ public interface Configuration extends Serializable {
* @deprecated This shall be removed in future releases. Please use
* {@code getPropertyNames()} instead.
*/
- @Deprecated
+ @Deprecated(since = "8.45")
String[] getAttributeNames();
/**
@@ -48,7 +48,7 @@ public interface Configuration extends Serializable {
* @deprecated This shall be removed in future releases. Please use
* {@code getProperty(String name)} instead.
*/
- @Deprecated
+ @Deprecated(since = "8.45")
String getAttribute(String name) throws CheckstyleException;
/**
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/DetailAST.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/DetailAST.java
index 45f8f4940da..77aeb26ac02 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/api/DetailAST.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/DetailAST.java
@@ -98,7 +98,7 @@ public interface DetailAST {
* traversal of subtrees to be written per the needs of each check
* to avoid unintended side effects.
*/
- @Deprecated
+ @Deprecated(since = "8.43")
boolean branchContains(int type);
/**
@@ -137,7 +137,7 @@ public interface DetailAST {
* @deprecated This method will be removed in a future release.
* Use {@link #getChildCount()} instead.
*/
- @Deprecated
+ @Deprecated(since = "8.30")
int getNumberOfChildren();
/**
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java
index 3b24b8b4521..a9f34199038 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java
@@ -5054,8 +5054,8 @@ public final class TokenTypes {
* `--RCURLY -> }
*
*
- * @see
- * JSR14
+ * @see
+ * Generic Classes and Type Parameters
* @see #GENERIC_START
* @see #GENERIC_END
* @see #TYPE_PARAMETER
@@ -5096,8 +5096,8 @@ public final class TokenTypes {
* `--RCURLY -> }
*
*
- * @see
- * JSR14
+ * @see
+ * Generic Classes and Type Parameters
* @see #IDENT
* @see #WILDCARD_TYPE
* @see #TYPE_UPPER_BOUNDS
@@ -5165,8 +5165,8 @@ public final class TokenTypes {
* `--SEMI -> ;
*
*
- * @see
- * JSR14
+ * @see
+ * Generic Classes and Type Parameters
* @see #WILDCARD_TYPE
* @see #TYPE_UPPER_BOUNDS
* @see #TYPE_LOWER_BOUNDS
@@ -5196,8 +5196,8 @@ public final class TokenTypes {
* |--SEMI -> ;
*
*
- * @see
- * JSR14
+ * @see
+ * Generic Classes and Type Parameters
* @see #TYPE_ARGUMENT
* @see #TYPE_UPPER_BOUNDS
* @see #TYPE_LOWER_BOUNDS
@@ -5229,8 +5229,8 @@ public final class TokenTypes {
* `--SEMI -> ;
*
*
- * @see
- * JSR14
+ * @see
+ * Generic Classes and Type Parameters
* @see #TYPE_PARAMETER
* @see #TYPE_ARGUMENT
* @see #WILDCARD_TYPE
@@ -5262,8 +5262,8 @@ public final class TokenTypes {
* `--SEMI -> ;
*
*
- * @see
- * JSR14
+ * @see
+ * Generic Classes and Type Parameters
* @see #TYPE_ARGUMENT
* @see #WILDCARD_TYPE
*/
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java
index 064ee25e3d9..1e7f77619c6 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java
@@ -68,6 +68,19 @@
* <module name="FinalParameters"/>
*
*
+ * Example:
+ *
+ *
+ * public class Point {
+ * public Point() { } // ok
+ * public Point(final int m) { } // ok
+ * public Point(final int m,int n) { } // violation, n should be final
+ * public void methodOne(final int x) { } // ok
+ * public void methodTwo(int x) { } // violation, x should be final
+ * public static void main(String[] args) { } // violation, args should be final
+ * }
+ *
+ *
* To configure the check to enforce final parameters only for constructors:
*
*
@@ -76,6 +89,19 @@
* </module>
*
*
+ * Example:
+ *
+ *
+ * public class Point {
+ * public Point() { } // ok
+ * public Point(final int m) { } // ok
+ * public Point(final int m,int n) { } // violation, n should be final
+ * public void methodOne(final int x) { } // ok
+ * public void methodTwo(int x) { } // ok
+ * public static void main(String[] args) { } // ok
+ * }
+ *
+ *
* To configure the check to allow ignoring
*
* primitive datatypes as parameters:
@@ -86,6 +112,19 @@
* </module>
*
*
+ * Example:
+ *
+ *
+ * public class Point {
+ * public Point() { } // ok
+ * public Point(final int m) { } // ok
+ * public Point(final int m,int n) { } // ok
+ * public void methodOne(final int x) { } // ok
+ * public void methodTwo(int x) { } // ok
+ * public static void main(String[] args) { } // violation, args should be final
+ * }
+ *
+ *
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
*
+ * public class MyClass {
+ * public int sign(int x) {
+ * if (x < 0)
+ * return -1;
+ * if (x == 0)
+ * return 1;
+ * return 0;
+ * } // OK
+ * public int badSign(int x) {
+ * if (x < -2)
+ * return -2;
+ * if (x == 0)
+ * return 0;
+ * if (x > 2)
+ * return 2;
+ * return 1;
+ * } // violation, more than three return statements
+ * }
+ *
+ *
* To configure the check so that it doesn't allow any return statements per void method:
*
*
@@ -98,6 +121,19 @@
* </module>
*
*
+ * Example:
+ *
+ *
+ * public class MyClass {
+ * public void firstMethod(int x) {
+ * } // OK
+ *
+ * public void badMethod(int x) {
+ * return;
+ * } // violation, return statements per void method
+ * }
+ *
+ *
* To configure the check so that it doesn't allow more than 2 return statements per method
* (ignoring the {@code equals()} method) and more than 1 return statements per void method:
*
@@ -108,6 +144,39 @@
* </module>
*
*
+ * Example:
+ *
+ *
+ * public class MyClass {
+ * public void firstMethod() {
+ * } // OK
+ *
+ * public void secondMethod() {
+ * return;
+ * } // OK
+ *
+ * public void badMethod(int x) {
+ * if (x == 0)
+ * return;
+ * return;
+ * } // violation, more than one return statements
+ *
+ * public int sign(int x) {
+ * if (x < 0)
+ * return -1;
+ * return 0;
+ * } // OK
+ *
+ * public int badSign(int x) {
+ * if (x < 0)
+ * return -1;
+ * if (x == 0)
+ * return 1;
+ * return 0;
+ * } // violation, more than two return statements in methods
+ * }
+ *
+ *
* To configure the check so that it doesn't allow more than three
* return statements per method for all methods:
*
@@ -118,13 +187,37 @@
* </module>
*
*
+ * Example:
+ *
+ *
+ * public class MyClass {
+ * public int sign(int x) {
+ * if (x < 0)
+ * return -1;
+ * if (x == 0)
+ * return 1;
+ * return 0;
+ * } // OK
+ *
+ * public int badSign(int x) {
+ * if (x < -2)
+ * return -2;
+ * if (x == 0)
+ * return 0;
+ * if (x > 2)
+ * return 2;
+ * return 1;
+ * } // violation, more than three return statements per method
+ * }
+ *
+ *
* To configure the check so that it doesn't allow any return statements in constructors,
* more than one return statement in all lambda expressions and more than two return
* statements in methods:
*
+ * import java.util.function.Predicate;
+ *
+ * public class Test {
+ * public Test() {
+ * } // OK
+ *
+ * public Test(int i) {
+ * return; // violation, max allowed for constructors is 0
+ * }
+ *
+ * final Predicate<Integer> p = i -> {
+ * if (i > 5) {
+ * return true;
+ * }
+ * return false;
+ * }; // violation, max allowed for lambdas is 1
+ *
+ * final Predicate<Integer> q = i -> {
+ * return i > 5;
+ * }; // OK
+ *
+ * public int sign(int x) {
+ * if (x > 0)
+ * return -1;
+ * return 0;
+ * } // OK
+ *
+ * public int badSign(int x) {
+ * if (x < 0)
+ * return -1;
+ * if (x == 0)
+ * return 1;
+ * return 0;
+ * } // violation, more than two return statements in methods
+ * }
+ *
+ *
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
*
*
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
index 97f493b0e57..956465e00ac 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
@@ -287,9 +287,6 @@ public int[] getRequiredTokens() {
@Override
public void beginTree(DetailAST root) {
- // No need to set blockContainingLocalAnonInnerClass to null, if
- // its value gets changed during the check then it is changed back to null
- // inside the check only.
variables.clear();
typeDeclarations.clear();
typeDeclAstToTypeDeclDesc.clear();
@@ -832,12 +829,12 @@ public static boolean shouldCheckIdentWithMethodRefParent(DetailAST identAst) {
*/
public static boolean shouldCheckIdentTokenNestedUnderDot(DetailAST dotAst) {
- return !TokenUtil.findFirstTokenByPredicate(dotAst,
+ return TokenUtil.findFirstTokenByPredicate(dotAst,
childAst -> {
return TokenUtil.isOfType(childAst,
UNACCEPTABLE_CHILD_OF_DOT);
})
- .isPresent();
+ .isEmpty();
}
/**
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
index 16245832d40..22afc18e2d5 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -659,12 +660,8 @@ private static Entry calculateDistanceBetweenScopes(
exprWithVariableUsage = blockWithVariableUsage.getFirstChild();
}
currentScopeAst = exprWithVariableUsage;
- if (exprWithVariableUsage == null) {
- variableUsageAst = blockWithVariableUsage;
- }
- else {
- variableUsageAst = exprWithVariableUsage;
- }
+ variableUsageAst =
+ Objects.requireNonNullElse(exprWithVariableUsage, blockWithVariableUsage);
}
// If there's no any variable usage, then distance = 0.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/FinalClassCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/FinalClassCheck.java
index b8d5ff5c323..bac412b0f9d 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/FinalClassCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/FinalClassCheck.java
@@ -21,6 +21,9 @@
import java.util.ArrayDeque;
import java.util.Deque;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
import com.puppycrawl.tools.checkstyle.FileStatefulCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
@@ -28,12 +31,12 @@
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.ScopeUtil;
+import com.puppycrawl.tools.checkstyle.utils.TokenUtil;
/**
*
- * Checks that a class which has only private constructors
- * is declared as final. Doesn't check for classes nested in interfaces
- * or annotations, as they are always {@code final} there.
+ * Checks that a class that has only private constructors and has no descendant
+ * classes is declared as final.
*
*
* To configure the check:
@@ -66,21 +69,6 @@
* }
* }
*
- * interface CheckInterface
- * {
- * class MyClass { // OK, nested class in interface is always final
- * private MyClass() {}
- * }
- * }
- *
- * public @interface Test {
- * public boolean enabled()
- * default true;
- * class MyClass { // OK, class nested in an annotation is always final
- * private MyClass() { }
- * }
- * }
- *
* class TestAnonymousInnerClasses { // OK, class has an anonymous inner class.
* public static final TestAnonymousInnerClasses ONE = new TestAnonymousInnerClasses() {
*
@@ -119,6 +107,9 @@ public class FinalClassCheck
*/
private static final String PACKAGE_SEPARATOR = ".";
+ /** Keeps ClassDesc objects for all inner classes. */
+ private Map innerClasses;
+
/** Keeps ClassDesc objects for stack of declared classes. */
private Deque classes;
@@ -138,7 +129,11 @@ public int[] getAcceptableTokens() {
@Override
public int[] getRequiredTokens() {
return new int[] {
+ TokenTypes.ANNOTATION_DEF,
TokenTypes.CLASS_DEF,
+ TokenTypes.ENUM_DEF,
+ TokenTypes.INTERFACE_DEF,
+ TokenTypes.RECORD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.PACKAGE_DEF,
TokenTypes.LITERAL_NEW,
@@ -148,38 +143,29 @@ public int[] getRequiredTokens() {
@Override
public void beginTree(DetailAST rootAST) {
classes = new ArrayDeque<>();
+ innerClasses = new HashMap<>();
packageName = "";
}
@Override
public void visitToken(DetailAST ast) {
- final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
-
switch (ast.getType()) {
case TokenTypes.PACKAGE_DEF:
packageName = extractQualifiedName(ast.getFirstChild().getNextSibling());
break;
- case TokenTypes.CLASS_DEF:
- registerNestedSubclassToOuterSuperClasses(ast);
-
- final boolean isFinal = modifiers.findFirstToken(TokenTypes.FINAL) != null;
- final boolean isAbstract = modifiers.findFirstToken(TokenTypes.ABSTRACT) != null;
+ case TokenTypes.ANNOTATION_DEF:
+ case TokenTypes.ENUM_DEF:
+ case TokenTypes.INTERFACE_DEF:
+ case TokenTypes.RECORD_DEF:
+ break;
- final String qualifiedClassName = getQualifiedClassName(ast);
- classes.push(new ClassDesc(qualifiedClassName, isFinal, isAbstract));
+ case TokenTypes.CLASS_DEF:
+ visitClass(ast);
break;
case TokenTypes.CTOR_DEF:
- if (!ScopeUtil.isInEnumBlock(ast) && !ScopeUtil.isInRecordBlock(ast)) {
- final ClassDesc desc = classes.peek();
- if (modifiers.findFirstToken(TokenTypes.LITERAL_PRIVATE) == null) {
- desc.registerNonPrivateCtor();
- }
- else {
- desc.registerPrivateCtor();
- }
- }
+ visitCtor(ast);
break;
case TokenTypes.LITERAL_NEW:
@@ -198,22 +184,67 @@ public void visitToken(DetailAST ast) {
}
}
+ /**
+ * Called to process a type definition.
+ *
+ * @param ast the token to process
+ */
+ private void visitClass(DetailAST ast) {
+ final String qualifiedClassName = getQualifiedClassName(ast);
+ final ClassDesc currClass = new ClassDesc(qualifiedClassName, classes.size(), ast);
+ classes.push(currClass);
+ innerClasses.put(qualifiedClassName, currClass);
+ }
+
+ /**
+ * Called to process a constructor definition.
+ *
+ * @param ast the token to process
+ */
+ private void visitCtor(DetailAST ast) {
+ if (!ScopeUtil.isInEnumBlock(ast) && !ScopeUtil.isInRecordBlock(ast)) {
+ final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
+ final ClassDesc desc = classes.getFirst();
+ if (modifiers.findFirstToken(TokenTypes.LITERAL_PRIVATE) == null) {
+ desc.registerNonPrivateCtor();
+ }
+ else {
+ desc.registerPrivateCtor();
+ }
+ }
+ }
+
@Override
public void leaveToken(DetailAST ast) {
if (ast.getType() == TokenTypes.CLASS_DEF) {
- final ClassDesc desc = classes.pop();
- if (desc.isWithPrivateCtor()
+ classes.pop();
+ }
+ if (TokenUtil.isRootNode(ast.getParent())) {
+ // First pass: mark all classes that have derived inner classes
+ innerClasses.forEach(this::registerNestedSubclassToOuterSuperClasses);
+ // Second pass: report violation for all classes that should be declared as final
+ innerClasses.forEach((qualifiedClassName, classDesc) -> {
+ if (shouldBeDeclaredAsFinal(classDesc)) {
+ final String className = getClassNameFromQualifiedName(qualifiedClassName);
+ log(classDesc.getClassAst(), MSG_KEY, className);
+ }
+ });
+ }
+ }
+
+ /**
+ * Checks whether a class should be declared as final or not.
+ *
+ * @param desc description of the class
+ * @return true if given class should be declared as final otherwise false
+ */
+ private static boolean shouldBeDeclaredAsFinal(ClassDesc desc) {
+ return desc.isWithPrivateCtor()
&& !(desc.isDeclaredAsAbstract()
|| desc.isWithAnonymousInnerClass())
&& !desc.isDeclaredAsFinal()
&& !desc.isWithNonPrivateCtor()
- && !desc.isWithNestedSubclass()
- && !ScopeUtil.isInInterfaceOrAnnotationBlock(ast)) {
- final String qualifiedName = desc.getQualifiedName();
- final String className = getClassNameFromQualifiedName(qualifiedName);
- log(ast, MSG_KEY, className);
- }
- }
+ && !desc.isWithNestedSubclass();
}
/**
@@ -227,25 +258,80 @@ private static String extractQualifiedName(DetailAST ast) {
}
/**
- * Register to outer super classes of given classAst that
+ * Register to outer super class of given classAst that
* given classAst is extending them.
*
- * @param classAst class which outer super classes will be
- * informed about nesting subclass
+ * @param qualifiedClassName qualifies class name(with package) of the current class
+ * @param currentClass class which outer super class will be informed about nesting subclass
*/
- private void registerNestedSubclassToOuterSuperClasses(DetailAST classAst) {
- final String currentAstSuperClassName = getSuperClassName(classAst);
- if (currentAstSuperClassName != null) {
- for (ClassDesc classDesc : classes) {
- final String classDescQualifiedName = classDesc.getQualifiedName();
- if (doesNameInExtendMatchSuperClassName(classDescQualifiedName,
- currentAstSuperClassName)) {
- classDesc.registerNestedSubclass();
- }
+ private void registerNestedSubclassToOuterSuperClasses(String qualifiedClassName,
+ ClassDesc currentClass) {
+ final String superClassName = getSuperClassName(currentClass.getClassAst());
+ if (superClassName != null) {
+ final ClassDesc nearest =
+ getNearestClassWithSameName(superClassName, qualifiedClassName);
+ if (nearest == null) {
+ Optional.ofNullable(innerClasses.get(superClassName))
+ .ifPresent(ClassDesc::registerNestedSubclass);
+ }
+ else {
+ nearest.registerNestedSubclass();
}
}
}
+ /**
+ * Checks if there is a class with same name.
+ *
+ * @param className name of the class
+ * @param superClassName name of the super class
+ * @return true if there is another class with same name.
+ * @noinspection CallToStringConcatCanBeReplacedByOperator
+ */
+ private ClassDesc getNearestClassWithSameName(String className, String superClassName) {
+ final String dotAndClassName = PACKAGE_SEPARATOR.concat(className);
+ return innerClasses.entrySet().stream()
+ .filter(entry -> entry.getKey().endsWith(dotAndClassName))
+ .map(Map.Entry::getValue)
+ .min((first, second) -> {
+ int diff = Integer.compare(
+ classNameMatchingCount(superClassName, second.getQualifiedName()),
+ classNameMatchingCount(superClassName, first.getQualifiedName()));
+ if (diff == 0) {
+ diff = Integer.compare(first.getDepth(), second.getDepth());
+ }
+ return diff;
+ })
+ .orElse(null);
+ }
+
+ /**
+ * Calculates and returns the class name matching count.
+ *
+ *
+ * Suppose our pattern class is {@code foo.a.b} and class to be matched is
+ * {@code foo.a.ball} then classNameMatchingCount would be calculated by comparing every
+ * character, and updating main counter when we hit "."
+ * to prevent matching "a.b" with "a.ball". In this case classNameMatchingCount would
+ * be equal to 6 and not 7 (b of ball is not counted).
+ *
+ *
+ * @param patternClass class against which the given class has to be matched
+ * @param classToBeMatched class to be matched
+ * @return class name matching count
+ */
+ private static int classNameMatchingCount(String patternClass, String classToBeMatched) {
+ final char packageSeparator = PACKAGE_SEPARATOR.charAt(0);
+ final int length = Math.min(classToBeMatched.length(), patternClass.length());
+ int result = 0;
+ for (int i = 0; i < length && patternClass.charAt(i) == classToBeMatched.charAt(i); ++i) {
+ if (patternClass.charAt(i) == packageSeparator) {
+ result = i;
+ }
+ }
+ return result;
+ }
+
/**
* Check if class name matches with anonymous inner class name.
*
@@ -318,23 +404,6 @@ private static String getSuperClassName(DetailAST classAst) {
return superClassName;
}
- /**
- * Checks if given super class name in extend clause match super class qualified name.
- *
- * @param superClassQualifiedName super class qualified name (with package)
- * @param superClassInExtendClause name in extend clause
- * @return true if given super class name in extend clause match super class qualified name,
- * false otherwise
- */
- private static boolean doesNameInExtendMatchSuperClassName(String superClassQualifiedName,
- String superClassInExtendClause) {
- String superClassNormalizedName = superClassQualifiedName;
- if (!superClassInExtendClause.contains(PACKAGE_SEPARATOR)) {
- superClassNormalizedName = getClassNameFromQualifiedName(superClassQualifiedName);
- }
- return superClassNormalizedName.equals(superClassInExtendClause);
- }
-
/**
* Get class name from qualified name.
*
@@ -348,6 +417,9 @@ private static String getClassNameFromQualifiedName(String qualifiedName) {
/** Maintains information about class' ctors. */
private static final class ClassDesc {
+ /** Corresponding node. */
+ private final DetailAST classAst;
+
/** Qualified class name(with package). */
private final String qualifiedName;
@@ -357,6 +429,9 @@ private static final class ClassDesc {
/** Is class declared as abstract. */
private final boolean declaredAsAbstract;
+ /** Class nesting level. */
+ private final int depth;
+
/** Does class have non-private ctors. */
private boolean withNonPrivateCtor;
@@ -373,16 +448,16 @@ private static final class ClassDesc {
* Create a new ClassDesc instance.
*
* @param qualifiedName qualified class name(with package)
- * @param declaredAsFinal indicates if the
- * class declared as final
- * @param declaredAsAbstract indicates if the
- * class declared as abstract
+ * @param depth class nesting level
+ * @param classAst classAst node
*/
- /* package */ ClassDesc(String qualifiedName, boolean declaredAsFinal,
- boolean declaredAsAbstract) {
+ /* package */ ClassDesc(String qualifiedName, int depth, DetailAST classAst) {
this.qualifiedName = qualifiedName;
- this.declaredAsFinal = declaredAsFinal;
- this.declaredAsAbstract = declaredAsAbstract;
+ this.depth = depth;
+ this.classAst = classAst;
+ final DetailAST modifiers = classAst.findFirstToken(TokenTypes.MODIFIERS);
+ declaredAsFinal = modifiers.findFirstToken(TokenTypes.FINAL) != null;
+ declaredAsAbstract = modifiers.findFirstToken(TokenTypes.ABSTRACT) != null;
}
/**
@@ -394,6 +469,15 @@ private String getQualifiedName() {
return qualifiedName;
}
+ /**
+ * Get the classAst node.
+ *
+ * @return classAst node
+ */
+ public DetailAST getClassAst() {
+ return classAst;
+ }
+
/** Adds private ctor. */
private void registerPrivateCtor() {
withPrivateCtor = true;
@@ -414,6 +498,15 @@ private void registerAnonymousInnerClass() {
withAnonymousInnerClass = true;
}
+ /**
+ * Returns class nesting level.
+ *
+ * @return class nesting level
+ */
+ private int getDepth() {
+ return depth;
+ }
+
/**
* Does class have private ctors.
*
@@ -469,5 +562,4 @@ private boolean isWithAnonymousInnerClass() {
}
}
-
}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheck.java
index 8bfd76883a2..c379fbc8f9c 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheck.java
@@ -20,8 +20,6 @@
package com.puppycrawl.tools.checkstyle.checks.javadoc;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
@@ -264,12 +262,10 @@ public class SummaryJavadocCheck extends AbstractJavadocCheck {
private static final String SUMMARY_TEXT = "@summary";
/** Set of allowed Tokens tags in summary java doc. */
- private static final Set ALLOWED_TYPES = Collections.unmodifiableSet(
- new HashSet<>(Arrays.asList(
+ private static final Set ALLOWED_TYPES = Set.of(
JavadocTokenTypes.WS,
JavadocTokenTypes.DESCRIPTION,
- JavadocTokenTypes.TEXT))
- );
+ JavadocTokenTypes.TEXT);
/**
* Specify the regexp for forbidden summary fragments.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java
index c5bf1579dba..db7192d5aac 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/metrics/AbstractClassCouplingCheck.java
@@ -30,6 +30,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
+import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -150,7 +151,7 @@ public final void setMax(int max) {
*/
public final void setExcludedClasses(String... excludedClasses) {
this.excludedClasses =
- Collections.unmodifiableSet(Arrays.stream(excludedClasses).collect(Collectors.toSet()));
+ Arrays.stream(excludedClasses).collect(Collectors.toUnmodifiableSet());
}
/**
@@ -159,9 +160,10 @@ public final void setExcludedClasses(String... excludedClasses) {
* @param from array representing regular expressions of classes to ignore.
*/
public void setExcludeClassesRegexps(String... from) {
- excludeClassesRegexps.addAll(Arrays.stream(from.clone())
+ Arrays.stream(from)
.map(CommonUtil::createPattern)
- .collect(Collectors.toSet()));
+ .distinct()
+ .forEach(excludeClassesRegexps::add);
}
/**
@@ -173,16 +175,15 @@ public void setExcludeClassesRegexps(String... from) {
*/
public final void setExcludedPackages(String... excludedPackages) {
final List invalidIdentifiers = Arrays.stream(excludedPackages)
- .filter(excludedPackageName -> !CommonUtil.isName(excludedPackageName))
+ .filter(Predicate.not(CommonUtil::isName))
.collect(Collectors.toList());
if (!invalidIdentifiers.isEmpty()) {
throw new IllegalArgumentException(
- "the following values are not valid identifiers: "
- + invalidIdentifiers.stream().collect(Collectors.joining(", ", "[", "]")));
+ "the following values are not valid identifiers: " + invalidIdentifiers);
}
- this.excludedPackages = Collections.unmodifiableSet(
- Arrays.stream(excludedPackages).collect(Collectors.toSet()));
+ this.excludedPackages =
+ Arrays.stream(excludedPackages).collect(Collectors.toUnmodifiableSet());
}
@Override
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java
index 85c71f11be1..4a091322fb0 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/RedundantModifierCheck.java
@@ -48,7 +48,7 @@
* Final modifier on methods of final and anonymous classes.
*
*
- * Inner {@code interface} declarations that are declared as {@code static}.
+ * Type declarations nested under interfaces that are declared as {@code public} or {@code static}.
*
*
* Class constructors.
@@ -58,13 +58,11 @@
*
*
*
- * Interfaces by definition are abstract so the {@code abstract}
- * modifier on the interface is redundant.
+ * interfaces by definition are abstract so the {@code abstract} modifier is redundant on them.
*
- *
Classes inside of interfaces by definition are public and static,
- * so the {@code public} and {@code static} modifiers
- * on the inner classes are redundant. On the other hand, classes
- * inside of interfaces can be abstract or non abstract.
+ *
Type declarations nested under interfaces by definition are public and static,
+ * so the {@code public} and {@code static} modifiers on nested type declarations are redundant.
+ * On the other hand, classes inside of interfaces can be abstract or non abstract.
* So, {@code abstract} modifier is allowed.
*