diff --git a/.all-contributorsrc b/.all-contributorsrc
index 9a4a77c26d..9ce3555a85 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -7279,6 +7279,15 @@
"bug"
]
},
+ {
+ "login": "nakul777",
+ "name": "Nakul Sharma",
+ "avatar_url": "https://avatars.githubusercontent.com/u/1551545?v=4",
+ "profile": "https://github.com/nakul777",
+ "contributions": [
+ "bug"
+ ]
+ },
{
"login": "shai-bennathan",
"name": "Shai Bennathan",
diff --git a/.ci/build.sh b/.ci/build.sh
index 9927f9e5ee..eb7283cd6b 100755
--- a/.ci/build.sh
+++ b/.ci/build.sh
@@ -36,7 +36,7 @@ function build() {
if pmd_ci_utils_is_fork_or_pull_request; then
pmd_ci_log_group_start "Build with mvnw"
- ./mvnw clean install -Pcli-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
+ ./mvnw clean install --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
pmd_ci_log_group_end
# Execute danger and dogfood only for pull requests in our own repository
@@ -70,7 +70,7 @@ function build() {
if [ "$(pmd_ci_utils_get_os)" != "linux" ]; then
pmd_ci_log_group_start "Build with mvnw"
- ./mvnw clean verify -Pcli-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
+ ./mvnw clean verify --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
pmd_ci_log_group_end
pmd_ci_log_info "Stopping build here, because os is not linux"
@@ -87,7 +87,7 @@ function build() {
if [ "${PMD_CI_BRANCH}" = "experimental-apex-parser" ]; then
pmd_ci_log_group_start "Build with mvnw"
- ./mvnw clean install -Pcli-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
+ ./mvnw clean install --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
pmd_ci_log_group_end
pmd_ci_log_group_start "Creating new baseline for regression tester"
@@ -107,7 +107,7 @@ function build() {
pmd_ci_log_group_end
# release is published only for the case b) pmd-cli/pmd-dist release
- if pmd_ci_maven_isReleaseBuild && [[ "${PMD_CI_TAG}" == *-dist ]]; then
+ if pmd_ci_maven_isReleaseBuild && [ "${BUILD_CLI_DIST_ONLY}" = "true" ]; then
pmd_ci_log_group_start "Publishing Release"
pmd_ci_gh_releases_publishRelease "$GH_RELEASE"
pmd_ci_sourceforge_selectDefault "${PMD_CI_MAVEN_PROJECT_VERSION}"
@@ -117,7 +117,7 @@ function build() {
# create a baseline for snapshot builds (when pmd-dist is built)
# or for release builds for case b) when pmd-cli/pmd-dist is released
- if pmd_ci_maven_isSnapshotBuild || [[ "${PMD_CI_TAG}" == *-dist ]]; then
+ if pmd_ci_maven_isSnapshotBuild || [ "${BUILD_CLI_DIST_ONLY}" = "true" ]; then
pmd_ci_log_group_start "Creating new baseline for regression tester"
regression_tester_setup_ci
regression_tester_uploadBaseline
@@ -133,6 +133,7 @@ function build() {
pmd_ci_log_group_end
pmd_ci_log_group_start "Executing build with sonar"
+ pmd_ci_openjdk_setdefault 17
# Note: Sonar also needs GITHUB_TOKEN (!)
./mvnw \
-Dmaven.javadoc.skip=true \
@@ -141,11 +142,12 @@ function build() {
-Dpmd.skip \
--show-version --errors --batch-mode \
clean package \
- sonar:sonar -Dsonar.login="${SONAR_TOKEN}" -Psonar,cli-dist
+ sonar:sonar -Dsonar.login="${SONAR_TOKEN}" -Psonar
pmd_ci_log_success "New sonar results: https://sonarcloud.io/dashboard?id=net.sourceforge.pmd%3Apmd"
pmd_ci_log_group_end
pmd_ci_log_group_start "Executing build with coveralls"
+ pmd_ci_openjdk_setdefault 11
export CI_NAME="github actions"
export CI_BUILD_URL="${PMD_CI_JOB_URL}"
export CI_BRANCH="${PMD_CI_BRANCH}"
@@ -157,7 +159,7 @@ function build() {
-DrepoToken="${COVERALLS_REPO_TOKEN}" \
--show-version --errors --batch-mode \
clean package jacoco:report \
- coveralls:report -Pcoveralls,cli-dist
+ coveralls:report -Pcoveralls
pmd_ci_log_success "New coveralls result: https://coveralls.io/github/pmd/pmd"
pmd_ci_log_group_end
fi
@@ -185,16 +187,16 @@ function pmd_ci_build_run() {
mvn_profiles="${mvn_profiles},pmd-release"
# There are two possible (release) builds:
- if [[ "${PMD_CI_TAG}" != *-dist ]]; then
- # a) pmd-core and languages modules
- ./mvnw clean deploy -P"${mvn_profiles}",'!cli-dist' --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
+ if [ "${BUILD_CLI_DIST_ONLY}" = "false" ]; then
+ # a) everything without pmd-cli and pmd-dist
+ ./mvnw clean deploy -P"${mvn_profiles}" -Dskip-cli-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
else
- # b) pmd-cli and pmd-dist
- ./mvnw clean deploy -P"${mvn_profiles},cli-dist" -pl pmd-cli,pmd-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
+ # b) only pmd-cli and pmd-dist
+ ./mvnw clean deploy -P"${mvn_profiles}" -pl pmd-cli,pmd-dist --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
fi
else
pmd_ci_log_info "This is a snapshot build"
- ./mvnw clean deploy -P"${mvn_profiles},cli-dist" --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
+ ./mvnw clean deploy -P"${mvn_profiles}" --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
fi
}
@@ -214,15 +216,15 @@ function pmd_ci_deploy_build_artifacts() {
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-${PMD_CI_MAVEN_PROJECT_VERSION}-cyclonedx.json"
fi
- # release build case a): only pmd-core and language modules released
- if pmd_ci_maven_isReleaseBuild && [[ "${PMD_CI_TAG}" != *-dist ]]; then
+ # release build case a): everything without pmd-cli and pmd-dist is released
+ if pmd_ci_maven_isReleaseBuild && [ "${BUILD_CLI_DIST_ONLY}" = "false" ]; then
# create a draft github release
pmd_ci_gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 "${PMD_CI_TAG}")"
GH_RELEASE="$RESULT"
fi
- # release build case b): pmd-cli and pmd-dist are released
- if pmd_ci_maven_isReleaseBuild && [[ "${PMD_CI_TAG}" == *-dist ]]; then
+ # release build case b): only pmd-cli and pmd-dist are released
+ if pmd_ci_maven_isReleaseBuild && [ "${BUILD_CLI_DIST_ONLY}" = "true" ]; then
# Deploy to sourceforge files https://sourceforge.net/projects/pmd/files/pmd/
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-bin.zip"
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-src.zip"
@@ -254,7 +256,7 @@ function pmd_ci_build_and_upload_doc() {
pmd_doc_create_archive
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-doc.zip"
- if pmd_ci_maven_isReleaseBuild && [[ "${PMD_CI_TAG}" != *-dist ]]; then
+ if pmd_ci_maven_isReleaseBuild && [ "${BUILD_CLI_DIST_ONLY}" = "false" ]; then
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "docs/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-doc.zip"
fi
@@ -263,7 +265,7 @@ function pmd_ci_build_and_upload_doc() {
# Deploy javadoc to https://docs.pmd-code.org/apidocs/*/${PMD_CI_MAVEN_PROJECT_VERSION}/
pmd_code_uploadJavadoc "${PMD_CI_MAVEN_PROJECT_VERSION}" "$(pwd)"
- if pmd_ci_maven_isSnapshotBuild || [[ "${PMD_CI_TAG}" != *-dist ]]; then
+ if pmd_ci_maven_isSnapshotBuild || [ "${BUILD_CLI_DIST_ONLY}" = "false" ]; then
# render release notes
# updating github release text
rm -f .bundle/config
@@ -289,7 +291,7 @@ function pmd_ci_build_and_upload_doc() {
pmd_ci_sourceforge_rsyncSnapshotDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "snapshot"
fi
- if pmd_ci_maven_isReleaseBuild && [[ "${PMD_CI_TAG}" != *-dist ]]; then
+ if pmd_ci_maven_isReleaseBuild && [ "${BUILD_CLI_DIST_ONLY}" = "false" ]; then
# documentation is already uploaded to https://docs.pmd-code.org/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}
# we only need to setup symlinks for the released version
pmd_code_createSymlink "${PMD_CI_MAVEN_PROJECT_VERSION}" "latest"
@@ -321,16 +323,15 @@ ${rendered_release_notes}"
#
function pmd_ci_dogfood() {
local mpmdVersion=()
- ./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false -Pcli-dist
+ ./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false
sed -i 's/
Mykhailo Palahuta
💻 🐛
Nagendra Kumar Singh
🐛
+
Nahuel Barrios
🐛
Nakul Sharma
🐛
Nathan Braun
🐛
-
Nathan Reynolds
🐛
Nathan Reynolds
🐛
+
Nathan Reynolds
🐛
Nathanaël
🐛
Naveen
💻
Nazdravi
🐛
Neha-Dhonde
🐛
Nicholas Doyle
🐛
-
Nick Butcher
🐛
Nico Gallinal
🐛
+
Nico Gallinal
🐛
Nicola Dal Maso
🐛
Nicolas Filotto
💻
Nicolas Vervelle
🐛
Nicolas Vuillamy
📖
Nikita Chursin
🐛
-
Niklas Baudy
🐛
Nikolas Havrikov
🐛
+
Nikolas Havrikov
🐛
Nilesh Virkar
🐛
Nimit Patel
🐛
Niranjan Harpale
🐛
Nirvik Patel
💻
Noah Sussman
🐛
-
Noah0120
🐛
Noam Tamim
🐛
+
Noam Tamim
🐛
Noel Grandin
🐛
Olaf Haalstra
🐛
Oleg Andreych
💻 🐛
Oleg Pavlenko
🐛
Oleksii Dykov
💻 🐛
-
Oliver Eikemeier
🐛
Oliver Siegmar
💵
+
Oliver Siegmar
💵
Olivier Parent
💻 🐛
Ollie Abbey
💻 🐛
OverDrone
🐛
Ozan Gulle
💻 🐛
PUNEET JAIN
🐛
-
Parbati Bose
🐛
Paul Berg
🐛
+
Paul Berg
🐛
Paul Guyot
💻
Pavel Bludov
🐛
Pavel Mička
🐛
Pedro Nuno Santos
🐛
Pedro Rijo
🐛
-
Pelisse Romain
💻 📖 🐛
Per Abich
💻
+
Per Abich
💻
Pete Davids
🐛
Peter Bruin
🐛
Peter Chittum
💻 🐛
Peter Cudmore
🐛
Peter Kasson
🐛
-
Peter Kofler
🐛
Peter Paul Bakker
💻
+
Peter Paul Bakker
💻
Pham Hai Trung
🐛
Philip Graf
💻 🐛
Philip Hachey
🐛
Philippe Ozil
🐛
Phinehas Artemix
🐛
-
Phokham Nonava
🐛
Pim van der Loos
💻 ⚠️
+
Pim van der Loos
💻 ⚠️
Piotr Szymański
🐛
Piotrek Żygieło
💻 🐛 📖
Pranay Jaiswal
🐛
Prasad Kamath
🐛
Prasanna
🐛
-
Presh-AR
🐛
Puneet1726
🐛
+
Puneet1726
🐛
Rafael Cortês
🐛
RaheemShaik999
🐛
RajeshR
💻 🐛
Ramachandra Mohan
🐛
Ramel0921
🐛
-
Raquel Pau
🐛
Ravikiran Janardhana
🐛
+
Ravikiran Janardhana
🐛
Reda Benhemmouche
🐛
Renato Oliveira
💻 🐛
Rich DiCroce
🐛
Richard Corfield
💻
Richard Corfield
🐛 💻
-
Riot R1cket
🐛
Rishabh Jain
🐛
+
Rishabh Jain
🐛
RishabhDeep Singh
🐛
Robbie Martinus
💻 🐛
Robert Henry
🐛
Robert Mihaly
🐛
Robert Painsi
🐛
-
Robert Russell
🐛
Robert Sösemann
💻 📖 📢 🐛
+
Robert Sösemann
💻 📖 📢 🐛
Robert Whitebit
🐛
Robin Richtsfeld
🐛
Robin Stocker
💻 🐛
Robin Wils
🐛
RochusOest
🐛
-
Rodolfo Noviski
🐛
Rodrigo Casara
🐛
+
Rodrigo Casara
🐛
Rodrigo Fernandes
🐛
Roman Salvador
💻 🐛
Ronald Blaschke
🐛
Róbert Papp
🐛
Saikat Sengupta
🐛
-
Saksham Handu
🐛
Saladoc
🐛
+
Saladoc
🐛
Salesforce Bob Lightning
🐛
Sam Carlberg
🐛
Satoshi Kubo
🐛
Scott Kennedy
🐛
Scott Wells
🐛 💻
-
Scrates1
🐛
Scrsloota
💻
+
Scrsloota
💻
Sebastian Bögl
🐛
Sebastian Schuberth
🐛
Sebastian Schwarz
🐛
Seren
🐛 💻
Sergey Gorbaty
🐛
-
Sergey Kozlov
🐛
Sergey Yanzin
💻 🐛
+
Sergey Yanzin
💻 🐛
Seth Wilcox
💻
Shai Bennathan
🐛 💻
Shubham
💻 🐛
Simon Abykov
💻 🐛
Simon Xiao
🐛
-
Srinivasan Venkatachalam
🐛
Stanislav Gromov
🐛
+
Stanislav Gromov
🐛
Stanislav Myachenkov
💻
Stefan Birkner
🐛
Stefan Bohn
🐛
Stefan Endrullis
🐛
Stefan Klöss-Schuster
🐛
-
Stefan Wolf
🐛
Stephan H. Wissel
🐛
+
Stephan H. Wissel
🐛
Stephen
🐛
Stephen Friedrich
🐛
Steve Babula
💻
Steven Stearns
🐛 💻
Stexxe
🐛
-
Stian Lågstad
🐛
StuartClayton5
🐛
+
StuartClayton5
🐛
Supun Arunoda
🐛
Suren Abrahamyan
🐛
Suvashri
📖
SwatiBGupta1110
🐛
SyedThoufich
🐛
-
Szymon Sasin
🐛
T-chuangxin
🐛
+
T-chuangxin
🐛
TERAI Atsuhiro
🐛
TIOBE Software
💻 🐛
Tarush Singh
💻
Taylor Smock
🐛
Techeira Damián
💻 🐛
-
Ted Husted
🐛
TehBakker
🐛
+
TehBakker
🐛
The Gitter Badger
🐛
Theodoor
🐛
Thiago Henrique Hüpner
🐛
Thibault Meyer
🐛
Thomas Güttler
🐛
-
Thomas Jones-Low
🐛
Thomas Smith
💻 🐛
+
Thomas Smith
💻 🐛
ThrawnCA
🐛
Thunderforge
💻 🐛
Tim van der Lippe
🐛
Tobias Weimer
💻 🐛
Tom Copeland
🐛 💻 📖
-
Tom Daly
🐛
Tomer Figenblat
🐛
+
Tomer Figenblat
🐛
Tomi De Lucca
💻 🐛
Torsten Kleiber
🐛
TrackerSB
🐛
Tyson Stewart
🐛
Ullrich Hafner
🐛
-
Utku Cuhadaroglu
💻 🐛
Valentin Brandl
🐛
+
Valentin Brandl
🐛
Valeria
🐛
Valery Yatsynovich
📖
Vasily Anisimov
🐛
Vibhor Goyal
🐛
Vickenty Fesunov
🐛
-
Victor Noël
🐛
Vincent Galloy
💻
+
Vincent Galloy
💻
Vincent HUYNH
🐛
Vincent Maurin
🐛
Vincent Privat
🐛
Vishhwas
🐛
Vitaly
🐛
-
Vitaly Polonetsky
🐛
Vojtech Polivka
🐛
+
Vojtech Polivka
🐛
Vsevolod Zholobov
🐛
Vyom Yadav
💻
Wang Shidong
🐛
Waqas Ahmed
🐛
Wayne J. Earl
🐛
-
Wchenghui
🐛
Wener
💻
+
Wener
💻
Will Winder
🐛
William Brockhus
💻 🐛
Wilson Kurniawan
🐛
Wim Deblauwe
🐛
Woongsik Choi
🐛
-
XenoAmess
💻 🐛
Yang
💻
+
Yang
💻
YaroslavTER
🐛
Yasar Shaikh
💻
Young Chan
💻 🐛
YuJin Kim
🐛
Yuri Dolzhenko
🐛
-
Yurii Dubinka
🐛
Zoltan Farkas
🐛
+
Zoltan Farkas
🐛
Zustin
🐛
aaronhurst-google
🐛 💻
alexmodis
🐛
andreoss
🐛
andrey81inmd
💻 🐛
-
anicoara
🐛
arunprasathav
🐛
+
arunprasathav
🐛
asiercamara
🐛
astillich-igniti
💻
avesolovksyy
🐛
avishvat
🐛
avivmu
🐛
-
axelbarfod1
🐛
b-3-n
🐛
+
b-3-n
🐛
balbhadra9
🐛
base23de
🐛
bergander
🐛 💻
berkam
💻 🐛
breizh31
🐛
-
caesarkim
🐛
carolyujing
🐛
+
carolyujing
🐛
cbfiddle
🐛
cesares-basilico
🐛
chrite
🐛
ciufudean
📖
cobratbq
🐛
-
coladict
🐛
cosmoJFH
🐛
+
cosmoJFH
🐛
cristalp
🐛
crunsk
🐛
cwholmes
🐛
cyberjj999
🐛
cyw3
🐛 📖
-
d1ss0nanz
🐛
dague1
📖
+
dague1
📖
dalizi007
💻
danbrycefairsailcom
🐛
dariansanity
🐛
darrenmiliband
🐛
davidburstrom
🐛
-
dbirkman-paloalto
🐛
deepak-patra
🐛
+
deepak-patra
🐛
dependabot[bot]
💻 🐛
dinesh150
🐛
diziaq
🐛
dreaminpast123
🐛
duanyanan
🐛
-
dutt-sanjay
🐛
dylanleung
🐛
+
dylanleung
🐛
dzeigler
🐛
eant60
🐛
ekkirala
🐛
emersonmoura
🐛
eugenepugach
🐛
-
fairy
🐛
filiprafalowicz
💻
+
filiprafalowicz
💻
foxmason
🐛
frankegabor
🐛
frankl
🐛
freafrea
🐛
fsapatin
🐛
-
gracia19
🐛
guo fei
🐛
+
guo fei
🐛
gurmsc5
🐛
gwilymatgearset
💻 🐛
haigsn
🐛
hemanshu070
🐛
henrik242
🐛
-
hongpuwu
🐛
hvbtup
💻 🐛
+
hvbtup
💻 🐛
igniti GmbH
🐛
ilovezfs
🐛
itaigilo
🐛
jakivey32
🐛
jbennett2091
🐛
-
jcamerin
🐛
jkeener1
🐛
+
jkeener1
🐛
jmetertea
🐛
johnra2
💻
josemanuelrolon
💻 🐛
kabroxiko
💻 🐛
karwer
🐛
-
kaulonline
🐛
kdaemonv
🐛
+
kdaemonv
🐛
kdebski85
🐛 💻
kenji21
💻 🐛
kfranic
🐛
khalidkh
🐛
koalalam
🐛
-
krzyk
🐛
lasselindqvist
🐛
+
lasselindqvist
🐛
lgemeinhardt
🐛
lihuaib
🐛
lonelyma1021
🐛
lpeddy
🐛
lujiefsi
💻
-
lukelukes
💻
lyriccoder
🐛
+
lyriccoder
🐛
marcelmore
🐛
matchbox
🐛
matthiaskraaz
🐛
meandonlyme
🐛
mikesive
🐛
-
milossesic
🐛
mluckam
💻
+
mluckam
💻
mohan-chinnappan-n
💻
mriddell95
🐛
mrlzh
🐛
msloan
🐛
mucharlaravalika
🐛
-
mvenneman
🐛
nareshl119
🐛
+
nareshl119
🐛
nicolas-harraudeau-sonarsource
🐛
noerremark
🐛
novsirion
🐛
nwcm
📖 🐛
oggboy
🐛
-
oinume
🐛
orimarko
💻 🐛
+
orimarko
💻 🐛
pacvz
💻
pallavi agarwal
🐛
parksungrin
🐛
patpatpat123
🐛
patriksevallius
🐛
-
pbrajesh1
🐛
phoenix384
🐛
+
phoenix384
🐛
piotrszymanski-sc
💻
plan3d
🐛
poojasix
🐛
prabhushrikant
🐛
pujitha8783
🐛
-
r-r-a-j
🐛
raghujayjunk
🐛
+
raghujayjunk
🐛
rajeshveera
🐛
rajeswarreddy88
🐛
recdevs
🐛
reudismam
💻 🐛
rijkt
🐛
-
rillig-tk
🐛
rmohan20
💻 🐛
+
rmohan20
💻 🐛
rnveach
🐛
rxmicro
🐛
ryan-gustafson
💻 🐛
sabi0
🐛
scais
🐛
-
sebbASF
🐛
sergeygorbaty
💻
+
sergeygorbaty
💻
shilko2013
🐛
shiomiyan
📖
simeonKondr
🐛
snajberk
🐛
sniperrifle2004
🐛
-
snuyanzin
🐛 💻
soyodream
🐛
+
soyodream
🐛
sratz
🐛
stonio
🐛
sturton
💻 🐛
sudharmohan
🐛
suruchidawar
🐛
-
svenfinitiv
🐛
tashiscool
🐛
+
tashiscool
🐛
test-git-hook
🐛
testation21
💻 🐛
thanosa
🐛
tiandiyixian
🐛
tobwoerk
🐛
-
tprouvot
🐛 💻
trentchilders
🐛
+
trentchilders
🐛
triandicAnt
🐛
trishul14
🐛
tsui
🐛
winhkey
🐛
witherspore
🐛
-
wjljack
🐛
wuchiuwong
🐛
+
wuchiuwong
🐛
xingsong
🐛
xioayuge
🐛
xnYi9wRezm
💻 🐛
xuanuy
🐛
xyf0921
🐛
-
yalechen-cyw3
🐛
yasuharu-sato
🐛
+
yasuharu-sato
🐛
zenglian
🐛
zgrzyt93
💻 🐛
zh3ng
🐛
zt_soft
🐛
ztt79
🐛
-
zzzzfeng
🐛
Árpád Magosányi
🐛
+
diff --git a/docs/pages/pmd/projectdocs/decisions/adr-1.md b/docs/pages/pmd/projectdocs/decisions/adr-1.md
index 85d750b473..94b624e42c 100644
--- a/docs/pages/pmd/projectdocs/decisions/adr-1.md
+++ b/docs/pages/pmd/projectdocs/decisions/adr-1.md
@@ -9,7 +9,7 @@ adr_status: "Accepted"
last_updated: September 2022
---
-# Context
+## Context
PMD has grown over 20 years as an open-source project. Along the way many decisions have been made, but they are not
explicitly documented. PMD is also developed by many individuals and the original developers might
@@ -33,7 +33,7 @@ by Michael Nygard.
There are many templates around to choose from.
Árpád Magosányi
🐛
任贵杰
🐛
茅延安
💻
See also [Supported Languages](#supported-languages).
" %} - {% include custom/cli_option_row.html options="-language,-l" - option_arg="lang" - description="Specify the language PMD should use. Used together with `-version`. See also [Supported Languages](#supported-languages). -Deprecated since PMD 6.52.0. Use `--use-version` instead.
" - %} {% include custom/cli_option_row.html options="--minimum-priority" option_arg="priority" description="Rule priority threshold; rules with lower priority than configured here won't be used. @@ -303,6 +298,6 @@ Alternatively, you can create a filelist to only analyze files with a given exte id="file-list" linux="find src/ -name \"*.ext\" > filelist.txt pmd check --file-list filelist.txt -f text -R ruleset.xml --force-language xml" - windows="for /r src/ %i in (*.ext) do echo %i >> filelist.txt + windows="for /r src\ %i in (*.ext) do echo %i >> filelist.txt pmd.bat check --file-list filelist.txt -f text -R ruleset.xml --force-language xml" %} diff --git a/docs/pages/pmd/userdocs/extending/defining_properties.md b/docs/pages/pmd/userdocs/extending/defining_properties.md index f47996fe5a..3551accd42 100644 --- a/docs/pages/pmd/userdocs/extending/defining_properties.md +++ b/docs/pages/pmd/userdocs/extending/defining_properties.md @@ -3,7 +3,7 @@ title: Defining rule properties short_title: Defining rule properties tags: [extending, userdocs] summary: "Learn how to define your own properties both for Java and XPath rules." -last_updated: August 2022 (7.0.0) +last_updated: December 2023 (7.0.0) permalink: pmd_userdocs_extending_defining_properties.html author: Hooper BloobSample code (Java) | @@ -49,10 +46,11 @@ class Foo extends Object { ```java └─ CompilationUnit └─ TypeDeclaration - └─ ClassOrInterfaceDeclaration "Foo" + └─ ClassDeclaration "Foo" + ├─ ModifierList ├─ ExtendsList - │ └─ ClassOrInterfaceType "Object" - └─ ClassOrInterfaceBody + │ └─ ClassType "Object" + └─ ClassBody ``` @@ -95,6 +93,8 @@ complicated processing, to which an XPath rule couldn't scale. In the end, choosing one strategy or the other depends on the difficulty of what your rule does. I'd advise to keep to XPath unless you have no other choice. +Note: Despite that fact, the Java rules are written in Java, any language that PMD supports +can be analyzed. E.g. you can write a Java rule to analyze Apex source code. ## XML rule definition @@ -103,16 +103,18 @@ case for both XPath and Java rules. To do this, the `rule` element is used, but instead of mentioning the `ref` attribute, it mentions the `class` attribute, with the implementation class of your rule. -* **For Java rules:** this is the class extending AbstractRule (transitively) -* **For XPath rules:** this is `net.sourceforge.pmd.lang.rule.XPathRule` +* **For Java rules:** this is the concrete class extending AbstractRule (transitively) +* **For XPath rules:** this is `net.sourceforge.pmd.lang.rule.XPathRule`. +* **For XPath rules analyzing XML-based languages:** this is `net.sourceforge.pmd.lang.xml.rule.DomXPathRule`. + See [XPath rules in XML](pmd_languages_xml.html#xpath-rules-in-xml) for more info. -Example: +Example for Java rule: ```xml{% highlight js %} └─ Annotation "A" - ├─ ClassOrInterfaceType "A" + ├─ ClassType "A" └─ AnnotationMemberList {% endhighlight %} | @@ -607,7 +627,7 @@ which can also display the AST.{% highlight js %} └─ Annotation "A" - ├─ ClassOrInterfaceType "A" + ├─ ClassType "A" └─ AnnotationMemberList └─ MemberValuePair "value" [ @Shorthand = false() ] └─ StringLiteral '"v"' @@ -634,7 +654,7 @@ which can also display the AST. | {% highlight js %} └─ Annotation "A" - ├─ ClassOrInterfaceType "A" + ├─ ClassType "A" └─ AnnotationMemberList └─ MemberValuePair "value" [ @Shorthand = true() ] └─ StringLiteral '"v"' @@ -669,7 +689,7 @@ which can also display the AST. | {% highlight js %} └─ Annotation "A" - ├─ ClassOrInterfaceType "A" + ├─ ClassType "A" └─ AnnotationMemberList ├─ MemberValuePair "value" [ @Shorthand = false() ] │ └─ StringLiteral '"v"' @@ -718,7 +738,7 @@ public void set(int x) { } └─ MethodDeclaration ├─ ModifierList │ └─ Annotation "A" - │ └─ ClassOrInterfaceType "A" + │ └─ ClassType "A" ├─ VoidType ├─ ... {% endhighlight %} @@ -743,11 +763,11 @@ Top-level type declaration | {% highlight js %} -└─ ClassOrInterfaceDeclaration +└─ ClassDeclaration ├─ ModifierList │ └─ Annotation "A" - │ └─ ClassOrInterfaceType "A" - └─ ClassOrInterfaceBody + │ └─ ClassType "A" + └─ ClassBody {% endhighlight %} | {% highlight js %} └─ CastExpression - ├─ ClassOrInterfaceType "S" - │ ├─ ClassOrInterfaceType "T" + ├─ ClassType "S" + │ ├─ ClassType "T" │ │ └─ Annotation "A" - │ │ └─ ClassOrInterfaceType "A" + │ │ └─ ClassType "A" │ └─ Annotation "B" - │ └─ ClassOrInterfaceType "B" + │ └─ ClassType "B" └─ VariableAccess "expr" {% endhighlight %} | @@ -814,10 +834,10 @@ var x = (@A T & S) expr; {% highlight js %} └─ CastExpression ├─ IntersectionType - │ ├─ ClassOrInterfaceType "T" + │ ├─ ClassType "T" │ │ └─ Annotation "A" - │ │ └─ ClassOrInterfaceType "A" - │ └─ ClassOrInterfaceType "S" + │ │ └─ ClassType "A" + │ └─ ClassType "S" └─ VariableAccess "expr" {% endhighlight %} @@ -844,9 +864,9 @@ new @A T(){% highlight js %} └─ ConstructorCall - ├─ ClassOrInterfaceType "T" + ├─ ClassType "T" │ └─ Annotation "A" - │ └─ ClassOrInterfaceType "A" + │ └─ ClassType "A" └─ ArgumentList {% endhighlight %} | @@ -877,7 +897,7 @@ new @A int[0] └─ ArrayType ├─ PrimitiveType "int" │ └─ Annotation "A" - │ └─ ClassOrInterfaceType "A" + │ └─ ClassType "A" └─ ArrayDimensions └─ ArrayDimExpr └─ NumericLiteral "0" @@ -911,15 +931,15 @@ Array type └─ LocalVariableDeclaration ├─ ModifierList │ └─ Annotation "A" - │ └─ ClassOrInterfaceType "A" + │ └─ ClassType "A" ├─ ArrayType │ ├─ PrimitiveType "int" │ └─ ArrayDimensions │ └─ ArrayTypeDim │ └─ Annotation "B" - │ └─ ClassOrInterfaceType "B" + │ └─ ClassType "B" └─ VariableDeclarator - └─ VariableDeclaratorId "x" + └─ VariableId "x" {% endhighlight %} @@ -953,13 +973,13 @@ Type parameters └─ TypeParameters ├─ TypeParameter "T" │ └─ Annotation "A" - │ └─ ClassOrInterfaceType "A" + │ └─ ClassType "A" └─ TypeParameter "S" [ @TypeBound = true() ] ├─ Annotation "B" - │ └─ ClassOrInterfaceType "B" - └─ ClassOrInterfaceType "Object" + │ └─ ClassType "B" + └─ ClassType "Object" └─ Annotation "C" - └─ ClassOrInterfaceType "C" + └─ ClassType "C" {% endhighlight %}
{% highlight js %}
-└─ ClassOrInterfaceType "List"
+└─ ClassType "List"
└─ TypeArguments
- └─ ClassOrInterfaceType "String"
+ └─ ClassType "String"
{% endhighlight %}
|
@@ -1115,7 +1135,7 @@ String[][] myArray;
{% highlight js %} └─ ArrayType[ @ArrayDepth = 2 ] - ├─ ClassOrInterfaceType "String" + ├─ ClassType "String" └─ ArrayDimensions[ @Size = 2 ] ├─ ArrayTypeDim └─ ArrayTypeDim @@ -1142,14 +1162,14 @@ String @Annotation1[] @Annotation2[] myArray; | {% highlight js %} └─ ArrayType[ @ArrayDepth = 2 ] - ├─ ClassOrInterfaceType "String" + ├─ ClassType "String" └─ ArrayDimensions[ @Size = 2 ] ├─ ArrayTypeDim │ └─ Annotation "Annotation1" - │ └─ ClassOrInterfaceType "Annotation1" + │ └─ ClassType "Annotation1" └─ ArrayTypeDim └─ Annotation "Annotation2" - └─ ClassOrInterfaceType "Annotation2" + └─ ClassType "Annotation2" {% endhighlight %} | @@ -1213,7 +1233,7 @@ new Foo[] { f, g }; └─ ArrayType[ @Array Depth = 2 ] ├─ PrimitiveType "int" │ └─ Annotation "Bar" - │ └─ ClassOrInterfaceType "Bar" + │ └─ ClassType "Bar" └─ ArrayDimensions[ @Size = 2 ] ├─ ArrayDimExpr │ └─ NumericLiteral "3" @@ -1222,7 +1242,7 @@ new Foo[] { f, g }; └─ ArrayAllocation[ @ArrayDepth = 1 ] └─ ArrayType[ @ArrayDepth = 1 ] - │ ├─ ClassOrInterfaceType "Foo" + │ ├─ ClassType "Foo" │ └─ ArrayDimensions[ @Size = 1 ] │ └─ ArrayTypeDim └─ ArrayInitializer[ @Length = 2 ] @@ -1234,14 +1254,15 @@ new Foo[] { f, g }; -##### ClassOrInterfaceType nesting +##### ClassType nesting -* What: {% jdoc jast::ASTClassOrInterfaceType %} appears to be left recursive now, and encloses its qualifying type. +* What: {% jdoc jast::ASTClassType %} (formerly ASTClassOrInterfaceType) appears to be left recursive now, + and encloses its qualifying type. * Why: To preserve the position of annotations and type arguments * Related issue: [[java] ClassOrInterfaceType AST improvements (#1150)](https://github.com/pmd/pmd/issues/1150)
---|
Code | Old AST (PMD 6) | New AST (PMD 7) | {% highlight js %} -└─ ClassOrInterfaceType "Entry" - ├─ ClassOrInterfaceType "Map" +└─ ClassType "Entry" + ├─ ClassType "Map" └─ TypeArguments[ @Size = 2 ] - ├─ ClassOrInterfaceType "K" - └─ ClassOrInterfaceType "V" + ├─ ClassType "K" + └─ ClassType "V" {% endhighlight %} | @@ -1291,13 +1312,13 @@ First{% highlight js %} -└─ ClassOrInterfaceType "Third" - ├─ ClassOrInterfaceType "Second" - │ └─ ClassOrInterfaceType "First" +└─ ClassType "Third" + ├─ ClassType "Second" + │ └─ ClassType "First" │ └─ TypeArguments[ @Size = 1] - │ └─ ClassOrInterfaceType "K" + │ └─ ClassType "K" └─ TypeArguments[ @Size = 1 ] - └─ ClassOrInterfaceType "V" + └─ ClassType "V" {% endhighlight %} |
---|
Such members may be removed, renamed, moved, or otherwise broken at any time and should not be + * relied upon outside the main PMD codebase. * *
Members and types tagged with this annotation will remain * supported until 7.0.0, after which some will be moved to internal diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/annotation/ReservedSubclassing.java b/pmd-core/src/main/java/net/sourceforge/pmd/annotation/ReservedSubclassing.java deleted file mode 100644 index 47f10de80c..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/annotation/ReservedSubclassing.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - - -/** - * Indicates that subclassing this type is not publicly - * supported API. Abstract methods may be added or removed - * at any time, which could break binary compatibility with - * existing implementors. Protected methods are also part of - * the private API of this type. - * - *
The API that is not inheritance-specific (unless {@linkplain InternalApi noted otherwise}, - * all public members), is still public API and will remain binary- - * compatible between major releases. - * - *
Types tagged with this annotation will remain supported - * until 7.0.0, at which point no guarantees will be maintained - * about the stability of the inheritance hierarchy for external - * clients. - * - *
This should be used for example for base rule classes that
- * are meant to be used in PMD only, or for AST-related interfaces
- * and abstract classes.
- *
- * @since 6.7.0
- */
-@Target(ElementType.TYPE)
-@Documented
-public @interface ReservedSubclassing {
-}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/ClasspathClassLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/ClasspathClassLoader.java
index 024542c01f..2d5da86589 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/ClasspathClassLoader.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/ClasspathClassLoader.java
@@ -7,14 +7,27 @@ package net.sourceforge.pmd.internal.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.UncheckedIOException;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.StringTokenizer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -33,29 +46,38 @@ public class ClasspathClassLoader extends URLClassLoader {
private static final Logger LOG = LoggerFactory.getLogger(ClasspathClassLoader.class);
+ String javaHome;
+
+ private FileSystem fileSystem;
+ private Map Two attributes are equal if they have the same name
* and their parent nodes are equal.
*
- * @author daniels
+ * Note that attributes do not support just any type, but
+ * a restricted set of value types that can be mapped to XPath types.
+ * The exact supported types are not specified, but include at
+ * least Java primitives and String.
+ *
+ * @see Node#getXPathAttributesIterator()
*/
-public class Attribute {
+public final class Attribute {
private static final Logger LOG = LoggerFactory.getLogger(Attribute.class);
- private final Node parent;
- private final String name;
+ private final @NonNull Node parent;
+ private final @NonNull String name;
- private final MethodHandle handle;
- private final Method method;
+ private final @Nullable MethodHandle handle;
+ private final @Nullable Method method;
+ /** If true, we won't invoke the method handle again. */
private boolean invoked;
- private Object value;
+ /** May be null after invocation too. */
+ private @Nullable Object value;
+
+ /** Must be non-null after {@link #getStringValue()} has been invoked. */
private String stringValue;
- /** Creates a new attribute belonging to the given node using its accessor. */
- public Attribute(Node parent, String name, MethodHandle handle, Method m) {
- this.parent = parent;
- this.name = name;
- this.handle = handle;
- this.method = m;
+ /**
+ * Creates a new attribute belonging to the given node using its accessor.
+ *
+ * @param handle A method handle, used to fetch the attribute.
+ * @param method The method corresponding to the method handle. This
+ * is used to perform reflective queries, eg to
+ * find annotations on the attribute getter, but only
+ * the method handle is ever invoked.
+ */
+ public Attribute(@NonNull Node parent, @NonNull String name, @NonNull MethodHandle handle, @NonNull Method method) {
+ this.parent = Objects.requireNonNull(parent);
+ this.name = Objects.requireNonNull(name);
+ this.handle = Objects.requireNonNull(handle);
+ this.method = Objects.requireNonNull(method);
}
/** Creates a new attribute belonging to the given node using its string value. */
- public Attribute(Node parent, String name, String value) {
- this.parent = parent;
- this.name = name;
+ public Attribute(@NonNull Node parent, @NonNull String name, @Nullable String value) {
+ this.parent = Objects.requireNonNull(parent);
+ this.name = Objects.requireNonNull(name);
this.value = value;
this.handle = null;
this.method = null;
- this.stringValue = value;
+ this.stringValue = value == null ? "" : value;
this.invoked = true;
}
-
/**
* Gets the generic type of the value of this attribute.
*/
@@ -67,12 +85,14 @@ public class Attribute {
return method == null ? String.class : method.getGenericReturnType();
}
- public String getName() {
+ /** Return the name of the attribute (without leading @ sign). */
+ public @NonNull String getName() {
return name;
}
- public Node getParent() {
+ /** Return the node that owns this attribute. */
+ public @NonNull Node getParent() {
return parent;
}
@@ -99,13 +119,23 @@ public class Attribute {
}
}
+ /**
+ * Return whether this attribute was deprecated. This is the case if the getter
+ * has the annotation {@link Deprecated} or {@link DeprecatedAttribute}.
+ */
public boolean isDeprecated() {
return replacementIfDeprecated() != null;
}
+ /**
+ * Return the value of the attribute. This may return null. The getter
+ * is invoked at most once.
+ */
public Object getValue() {
if (this.invoked) {
return this.value;
+ } else if (handle == null) {
+ throw new NullPointerException("Cannot fetch value of attribute with null getter! " + this);
}
Object value;
@@ -121,13 +151,23 @@ public class Attribute {
return value;
}
- public String getStringValue() {
+ /**
+ * Return the string value of the attribute. If the getter returned null,
+ * then return the empty string (which is a falsy value in XPath).
+ * Otherwise, return a string representation of the value (e.g. with
+ * {@link Object#toString()}, but this is not guaranteed).
+ */
+ public @NonNull String getStringValue() {
if (stringValue != null) {
return stringValue;
}
Object v = getValue();
- stringValue = v == null ? "" : String.valueOf(v);
+ if (v == null) {
+ stringValue = "";
+ } else {
+ stringValue = v.toString();
+ }
return stringValue;
}
@@ -148,11 +188,11 @@ public class Attribute {
@Override
public int hashCode() {
- return Objects.hash(parent, name);
+ return parent.hashCode() * 31 + name.hashCode();
}
@Override
public String toString() {
- return name + ':' + getValue() + ':' + parent.getXPathNodeName();
+ return parent.getXPathNodeName() + "/@" + name + " = " + getValue();
}
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/DeprecatedAttribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/DeprecatedAttribute.java
index f881ce68cd..7026980897 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/DeprecatedAttribute.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/DeprecatedAttribute.java
@@ -16,6 +16,9 @@ import java.lang.annotation.Target;
* to mark the attribute as deprecated for XPath. Unlike {@link Deprecated}, this
* annotation does not deprecate the method for java usage.
*
+ * When used in combination with {@link Deprecated}, this attribute allows specifying
+ * a replacement for the XPath attribute.
+ *
* @since 6.21.0
*/
@Documented
@@ -23,12 +26,16 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
public @interface DeprecatedAttribute {
+ /** Sentinel expressing that the attribute is deprecated without replacement. */
String NO_REPLACEMENT = "";
/**
- * The simple name of the attribute to use for replacement (with '@' prefix).
+ * An XPath expression to suggest as a replacement for use of the
+ * deprecated attribute.
* If empty, then the attribute is deprecated for removal.
+ * Example values: {@code @NewerAttribute}, {@code NodeType/@SomeAttribute},
+ * {@code some-function()}.
*/
String replaceWith() default NO_REPLACEMENT;
}
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/NoAttribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/NoAttribute.java
index ab0be8251f..727ea31fa1 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/NoAttribute.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/NoAttribute.java
@@ -4,6 +4,7 @@
package net.sourceforge.pmd.lang.rule.xpath;
+import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -17,6 +18,7 @@ import net.sourceforge.pmd.lang.ast.impl.AbstractNode;
*
* @author Clément Fournier
*/
+@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface NoAttribute {
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/AttributeAxisIterator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/AttributeAxisIterator.java
index 31dd02335f..f3840458a1 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/AttributeAxisIterator.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/impl/AttributeAxisIterator.java
@@ -4,13 +4,16 @@
package net.sourceforge.pmd.lang.rule.xpath.impl;
+import static net.sourceforge.pmd.util.CollectionUtil.emptyList;
+import static net.sourceforge.pmd.util.CollectionUtil.setOf;
+
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -18,8 +21,11 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
+import org.checkerframework.checker.nullness.qual.NonNull;
+
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.impl.AbstractNode;
+import net.sourceforge.pmd.lang.document.Chars;
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
import net.sourceforge.pmd.lang.rule.xpath.NoAttribute;
import net.sourceforge.pmd.lang.rule.xpath.NoAttribute.NoAttrScope;
@@ -31,6 +37,8 @@ import net.sourceforge.pmd.util.AssertionUtil;
* attributes. This is the default way the attributes of a node
* are made accessible to XPath rules, and defines an important
* piece of PMD's XPath support.
+ *
+ * @see Node#getXPathAttributesIterator()
*/
public class AttributeAxisIterator implements Iterator
+ * This test only runs, if you have a folder ${HOME}/openjdk{javaVersion}.
+ * foobar Returns {@code null} otherwise.
*/
- public ASTClassOrInterfaceType getSuperClassTypeNode() {
+ public ASTClassType getSuperClassTypeNode() {
if (isInterface()) {
return null;
}
- ASTExtendsList extendsList = getFirstChildOfType(ASTExtendsList.class);
+ ASTExtendsList extendsList = firstChild(ASTExtendsList.class);
return extendsList == null ? null : extendsList.iterator().next();
}
- public List Note: This node was called ASTClassOrInterfaceType in PMD 6.
+ *
* @implNote
* The parser may produce an AmbiguousName for the qualifier.
* This is systematically removed by the disambiguation phase.
*/
// @formatter:on
-public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implements ASTReferenceType {
- // todo rename to ASTClassType
-
+public final class ASTClassType extends AbstractJavaTypeNode implements ASTReferenceType {
private JTypeDeclSymbol symbol;
private String simpleName;
@@ -43,8 +43,8 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
private boolean isFqcn;
private JClassType implicitEnclosing;
- ASTClassOrInterfaceType(ASTAmbiguousName lhs, String simpleName) {
- super(JavaParserImplTreeConstants.JJTCLASSORINTERFACETYPE);
+ ASTClassType(ASTAmbiguousName lhs, String simpleName) {
+ super(JavaParserImplTreeConstants.JJTCLASSTYPE);
assert lhs != null : "Null LHS";
this.addChild(lhs, 0);
@@ -53,8 +53,8 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
}
- ASTClassOrInterfaceType(ASTAmbiguousName simpleName) {
- super(JavaParserImplTreeConstants.JJTCLASSORINTERFACETYPE);
+ ASTClassType(ASTAmbiguousName simpleName) {
+ super(JavaParserImplTreeConstants.JJTCLASSTYPE);
this.simpleName = simpleName.getFirstToken().getImage();
assertSimpleNameOk();
@@ -62,13 +62,13 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
// Just for one usage in Symbol table
@Deprecated
- public ASTClassOrInterfaceType(String simpleName) {
- super(JavaParserImplTreeConstants.JJTCLASSORINTERFACETYPE);
+ public ASTClassType(String simpleName) {
+ super(JavaParserImplTreeConstants.JJTCLASSTYPE);
this.simpleName = simpleName;
}
- ASTClassOrInterfaceType(@Nullable ASTClassOrInterfaceType lhs, boolean isFqcn, JavaccToken firstToken, JavaccToken identifier) {
- super(JavaParserImplTreeConstants.JJTCLASSORINTERFACETYPE);
+ ASTClassType(@Nullable ASTClassType lhs, boolean isFqcn, JavaccToken firstToken, JavaccToken identifier) {
+ super(JavaParserImplTreeConstants.JJTCLASSTYPE);
this.setImage(identifier.getImage());
this.isFqcn = isFqcn;
if (lhs != null) {
@@ -79,7 +79,7 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
}
- ASTClassOrInterfaceType(int id) {
+ ASTClassType(int id) {
super(id);
}
@@ -141,8 +141,8 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
* @return A type, or null if this is a base type
*/
@Nullable
- public ASTClassOrInterfaceType getQualifier() {
- return getFirstChildOfType(ASTClassOrInterfaceType.class);
+ public ASTClassType getQualifier() {
+ return firstChild(ASTClassType.class);
}
/**
@@ -150,7 +150,7 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
*/
@Nullable
public ASTTypeArguments getTypeArguments() {
- return getFirstChildOfType(ASTTypeArguments.class);
+ return firstChild(ASTTypeArguments.class);
}
@@ -181,7 +181,7 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
@Deprecated
public boolean isReferenceToClassSameCompilationUnit() {
ASTCompilationUnit root = getFirstParentOfType(ASTCompilationUnit.class);
- for (ASTClassOrInterfaceDeclaration c : root.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class, true)) {
+ for (ASTClassDeclaration c : root.findDescendantsOfType(ASTClassDeclaration.class, true)) {
if (c.hasImageEqualTo(getImage())) {
return true;
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompactConstructorDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompactConstructorDeclaration.java
index d46ad0863e..04d2bf3677 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompactConstructorDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompactConstructorDeclaration.java
@@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
*
* Compact record constructors must be declared "public".
*
- * TODO make implicit formal parameter node and implement ASTMethodOrConstructorDeclaration.
+ * TODO make implicit formal parameter node and implement ASTExecutableDeclaration.
*
* Note: This interface was called ASTMethodOrConstructorDeclaration in PMD 6.
+ *
* @author Clément Fournier
* @since 5.8.1
*/
-public interface ASTMethodOrConstructorDeclaration
- extends AccessNode,
+public interface ASTExecutableDeclaration
+ extends ModifierOwner,
ASTBodyDeclaration,
TypeParamOwnerNode,
GenericNode This statement may define several variables, possibly of different types
- * (see {@link ASTVariableDeclaratorId#getType()}). The nodes corresponding to
+ * (see {@link ASTVariableId#getTypeNode()}). The nodes corresponding to
* the declared variables are accessible through {@link #getVarIds()}.
*
* Invalid literals or overflows result in {@code 0L}.
+ */
+ static long parseIntegralValue(Chars image) {
+ final int base = getBase(image);
+ if (base == 8) {
+ image = image.subSequence(1); // 0
+ } else if (base != 10) {
+ image = image.subSequence(2); // 0x / 0b
+ }
+
+ int length = image.length();
+ char lastChar = image.charAt(length - 1);
+ if (lastChar == 'l' || lastChar == 'L') {
+ length--;
+ }
+
+ try {
+ String literalImage = image.substring(0, length).replaceAll("_", "");
+ return Long.parseUnsignedLong(literalImage, base);
+ } catch (NumberFormatException e) {
+ // invalid literal or overflow
+ return 0L;
+ }
+ }
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPermitsList.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPermitsList.java
index 29c0d1d394..87f9975632 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPermitsList.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPermitsList.java
@@ -16,14 +16,14 @@ import net.sourceforge.pmd.lang.java.ast.ASTList.ASTNonEmptyList;
*
* Note: In PMD 6, there was a node with this name (ASTTypeDeclaration) which was a top-level wrapper
+ * node around type declarations. This node has been removed in PMD 7 and the name has been reused.
*/
-public interface ASTAnyTypeDeclaration
+public interface ASTTypeDeclaration
extends TypeNode,
- AccessNode,
+ ModifierOwner,
TypeParamOwnerNode,
ASTBodyDeclaration,
ASTTopLevelDeclaration,
- FinalizableNode,
JavadocCommentOwner {
@Override
@@ -135,13 +137,25 @@ public interface ASTAnyTypeDeclaration
return hasModifiers(ABSTRACT);
}
+ /**
+ * Returns true if this type is static. Only inner types can be static.
+ */
+ @Override
+ default boolean isStatic() {
+ return hasModifiers(JModifier.STATIC);
+ }
+
+ @Override
+ default boolean isFinal() {
+ return hasModifiers(JModifier.FINAL);
+ }
/**
* Returns the enum constants declared by this enum. If this is not
* an enum declaration, returns an empty stream.
*/
default NodeStream Note: This node has been called ASTVariableDeclaratorId in PMD 6.
*/
// @formatter:on
-public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator The type of the returned node is not necessarily the type of this
- * node. See {@link #getType()} for an explanation.
+ * node. See {@link #getTypeMirror()} for an explanation.
*
* @return the type node, or {@code null} if there is no explicit type,
* e.g. if {@link #isTypeInferred()} returns true.
*/
public @Nullable ASTType getTypeNode() {
- AccessNode parent = getModifierOwnerParent();
+ ModifierOwner parent = getModifierOwnerParent();
return parent.firstChild(ASTType.class);
}
@@ -321,7 +328,7 @@ public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator
// @formatter:on
@Override
@SuppressWarnings("PMD.UselessOverridingMethod")
- public Class> getType() {
- return super.getType();
+ public @NonNull JTypeMirror getTypeMirror() {
+ return super.getTypeMirror();
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractMethodOrConstructorDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractExecutableDeclaration.java
similarity index 82%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractMethodOrConstructorDeclaration.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractExecutableDeclaration.java
index fe2699fec1..179bc077a1 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractMethodOrConstructorDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractExecutableDeclaration.java
@@ -8,15 +8,15 @@ import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol;
import net.sourceforge.pmd.lang.java.types.JMethodSig;
-abstract class AbstractMethodOrConstructorDeclaration extends AstVisitorBase implements JavaV
// extends AstVisitorBase implements JavaV
// extends AstVisitorBase implements JavaV
}
@Override
- public R visit(ASTClassOrInterfaceType node, P data) {
+ public R visit(ASTClassType node, P data) {
return visitReferenceType(node, data);
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AccessNode.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ModifierOwner.java
similarity index 88%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AccessNode.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ModifierOwner.java
index 55db9498a4..098305da0b 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AccessNode.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ModifierOwner.java
@@ -15,22 +15,21 @@ import net.sourceforge.pmd.lang.ast.NodeStream;
/**
* A node that owns a {@linkplain ASTModifierList modifier list}.
*
- * {@link AccessNode} methods take into account the syntactic context of the
- * declaration, e.g. {@link #isPublic()} will always return true for a field
+ * {@link ModifierOwner} methods take into account the syntactic context of the
+ * declaration, e.g. {@link #hasModifiers(JModifier, JModifier...) hasModifiers(JModifier.PUBLIC)}
+ * will always return true for a field
* declared inside an interface, regardless of whether the {@code public}
* modifier was specified explicitly or not. If you want to know whether
* the modifier was explicitly stated, use {@link #hasExplicitModifiers(JModifier, JModifier...)}.
*
- * TODO make modifiers accessible from XPath
- * * Ideally we'd have two attributes, eg @EffectiveModifiers and @ExplicitModifiers,
- * which would each return a sequence, eg ("public", "static", "final")
- * * Ideally we'd have a way to add attributes that are not necessarily
- * getters on the node. It makes no sense in the Java API to expose
- * those getters on the node, it's more orthogonal to query getModifiers() directly.
+ * Modifiers are accessible from XPath through the functions {@code pmd:modifiers()} and
+ * {@code pmd:explicitModifiers()}. They return a sequence, e.g. {@code ("public", "static", "final")}.
*
- * TODO rename to ModifierOwner, kept out from PR to reduce diff
+ * Note: This interface was called AccessNode in PMD 6.
+ *
+ * @see net.sourceforge.pmd.lang.java.rule.xpath.internal.GetModifiersFun
*/
-public interface AccessNode extends Annotatable {
+public interface ModifierOwner extends Annotatable {
@Override
default NodeStream
- * {@linkplain #of(Node) NodeStream.of}(someNode) // the stream here is empty if the node is null
- * {@linkplain #filterIs(Class) .filterIs}(ASTVariableDeclaratorId.class)// the stream here is empty if the node was not a variable declarator id
- * {@linkplain #followingSiblings() .followingSiblings}() // the stream here contains only the siblings, not the original node
- * {@linkplain #take(int) .take}(1) // the stream here contains only the first sibling, if it exists
+ * {@linkplain #of(Node) NodeStream.of}(someNode) // the stream here is empty if the node is null
+ * {@linkplain #filterIs(Class) .filterIs}(ASTVariableId.class) // the stream here is empty if the node was not a variable declarator id
+ * {@linkplain #followingSiblings() .followingSiblings}() // the stream here contains only the siblings, not the original node
+ * {@linkplain #take(int) .take}(1) // the stream here contains only the first sibling, if it exists
* {@linkplain #filterIs(Class) .filterIs}(ASTNumericLiteral.class)
* {@linkplain #filter(Predicate) .filter}(it -> !it.isFloatingPoint() && it.getValueAsInt() == 0)
* {@linkplain #nonEmpty() .nonEmpty}(); // If the stream is non empty here, then all the pipeline matched
@@ -1113,9 +1113,9 @@ public interface NodeStream<@NonNull T extends Node> extends Iterable<@NonNull T
* explicit type arguments:
*
*
*
*/
-public final class ASTAnnotationTypeDeclaration extends AbstractAnyTypeDeclaration {
+public final class ASTAnnotationTypeDeclaration extends AbstractTypeDeclaration {
ASTAnnotationTypeDeclaration(int id) {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnonymousClassDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnonymousClassDeclaration.java
index 4834af36a1..1c1a322151 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnonymousClassDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnonymousClassDeclaration.java
@@ -19,11 +19,11 @@ import net.sourceforge.pmd.lang.java.types.JTypeMirror;
*
* {@code
- * ASTAnyTypeDeclaration ts =
+ * ASTTypeDeclaration ts =
* node.ancestors()
- * .
*
@@ -1123,8 +1123,8 @@ public interface NodeStream<@NonNull T extends Node> extends Iterable<@NonNull T
* may be used, which reduces the above to
*
* {@code
- * ASTAnyTypeDeclaration ts =
- * node.ancestors().firstNonNull(asInstanceOf(ASTClassOrInterfaceDeclaration.class, ASTEnumDeclaration.class));
+ * ASTTypeDeclaration ts =
+ * node.ancestors().firstNonNull(asInstanceOf(ASTClassDeclaration.class, ASTEnumDeclaration.class));
* }
*
* @param c1 First type to test
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/TokenMgrError.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/TokenMgrError.java
index d4115e77b3..28bee8a79e 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/TokenMgrError.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/TokenMgrError.java
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.ast;
+import static java.lang.Math.max;
+
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -25,14 +27,14 @@ public final class TokenMgrError extends FileAnalysisException {
*
* @param line Line number
* @param column Column number
- * @param filename Filename. If unknown, it can be completed with {@link #setFileName(String)} later
+ * @param filename Filename. If unknown, it can be completed with {@link #setFileId(FileId)}} later
* @param message Message of the error
* @param cause Cause of the error, if any
*/
public TokenMgrError(int line, int column, @Nullable FileId filename, String message, @Nullable Throwable cause) {
super(message, cause);
- this.line = line;
- this.column = column;
+ this.line = max(line, 1);
+ this.column = max(column, 1);
if (filename != null) {
super.setFileId(filename);
}
@@ -44,8 +46,8 @@ public final class TokenMgrError extends FileAnalysisException {
@InternalApi
public TokenMgrError(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
super(makeReason(eofSeen, lexStateName, errorAfter, curChar));
- line = errorLine;
- column = errorColumn;
+ line = max(errorLine, 1);
+ column = max(errorColumn, 1);
}
public int getLine() {
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrNode.java
index 3805dbe8e0..044ed1ddd8 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrNode.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrNode.java
@@ -72,7 +72,7 @@ public abstract class BaseAntlrNode, N e
@Override
public TextRegion getTextRegion() {
return TextRegion.fromBothOffsets(getFirstAntlrToken().getStartIndex(),
- getFirstAntlrToken().getStopIndex());
+ getLastAntlrToken().getStopIndex() + 1);
}
void setIndexInParent(int indexInParent) {
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/Chars.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/Chars.java
index a350fefa69..54a10845c9 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/Chars.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/Chars.java
@@ -198,6 +198,13 @@ public final class Chars implements CharSequence {
return NOT_FOUND;
}
+ /**
+ * See {@link String#indexOf(int)}
+ */
+ public int indexOf(int ch) {
+ return indexOf(ch, 0);
+ }
+
/**
* See {@link String#indexOf(int, int)}.
*/
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java
index 84c5f4adda..64857cca51 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java
@@ -10,6 +10,8 @@ import java.lang.reflect.Type;
import java.util.List;
import java.util.Objects;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -24,42 +26,58 @@ import net.sourceforge.pmd.lang.ast.Node;
*
*
- * Annotation ::= "@" {@link ASTClassOrInterfaceType ClassName} {@link ASTAnnotationMemberList AnnotationMemberList}?
+ * Annotation ::= "@" {@link ASTClassType ClassName} {@link ASTAnnotationMemberList AnnotationMemberList}?
*
*
*/
@@ -32,8 +32,8 @@ public final class ASTAnnotation extends AbstractJavaTypeNode implements TypeNod
/**
* Returns the node that represents the name of the annotation.
*/
- public ASTClassOrInterfaceType getTypeNode() {
- return (ASTClassOrInterfaceType) getChild(0);
+ public ASTClassType getTypeNode() {
+ return (ASTClassType) getChild(0);
}
@Override
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnnotationTypeDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnnotationTypeDeclaration.java
index 32f4785c6c..f2551b3d1e 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnnotationTypeDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnnotationTypeDeclaration.java
@@ -23,7 +23,7 @@ import net.sourceforge.pmd.lang.ast.Node;
*
*
- * AnonymousClassDeclaration ::= {@link ASTModifierList EmptyModifierList} {@link ASTClassOrInterfaceBody}
+ * AnonymousClassDeclaration ::= {@link ASTModifierList EmptyModifierList} {@link ASTClassBody}
*
*
*/
-public final class ASTAnonymousClassDeclaration extends AbstractAnyTypeDeclaration {
+public final class ASTAnonymousClassDeclaration extends AbstractTypeDeclaration {
ASTAnonymousClassDeclaration(int id) {
@@ -42,7 +42,7 @@ public final class ASTAnonymousClassDeclaration extends AbstractAnyTypeDeclarati
}
@Override
- public @NonNull NodeStreampublic int newIntArray(int length) [];
*
- * public int a[], b[][];
*
*
* ArrayType ::= {@link ASTPrimitiveType PrimitiveType} {@link ASTArrayDimensions ArrayDimensions}
- * | {@link ASTClassOrInterfaceType ClassOrInterfaceType} {@link ASTArrayDimensions ArrayDimensions}
+ * | {@link ASTClassType ClassOrInterfaceType} {@link ASTArrayDimensions ArrayDimensions}
*
*
*/
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTBodyDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTBodyDeclaration.java
index f28fb1ca46..69106d9faf 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTBodyDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTBodyDeclaration.java
@@ -11,7 +11,7 @@ package net.sourceforge.pmd.lang.java.ast;
*
*
*
- * BodyDeclaration ::= {@link ASTAnyTypeDeclaration AnyTypeDeclaration}
+ * BodyDeclaration ::= {@link ASTTypeDeclaration TypeDeclaration}
* | {@link ASTMethodDeclaration MethodDeclaration}
* | {@link ASTConstructorDeclaration ConstructorDeclaration}
* | {@link ASTCompactConstructorDeclaration CompactConstructorDeclaration}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCastExpression.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCastExpression.java
index f7bac6965d..1c4ccf07e6 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCastExpression.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCastExpression.java
@@ -21,7 +21,7 @@ public final class ASTCastExpression extends AbstractJavaExpr implements ASTExpr
}
public ASTType getCastType() {
- return getFirstChildOfType(ASTType.class);
+ return firstChild(ASTType.class);
}
public ASTExpression getOperand() {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchClause.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchClause.java
index 675c701a24..e9f6b2f9c5 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchClause.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchClause.java
@@ -32,7 +32,7 @@ public final class ASTCatchClause extends AbstractJavaNode {
/** Returns the body of this catch branch. */
public ASTBlock getBody() {
- return getFirstChildOfType(ASTBlock.class);
+ return firstChild(ASTBlock.class);
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchParameter.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchParameter.java
index 875198d373..6af66a3e1c 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchParameter.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCatchParameter.java
@@ -19,13 +19,13 @@ import net.sourceforge.pmd.lang.java.types.TypeSystem;
*
*
*/
@@ -63,7 +63,7 @@ public final class ASTConstructorCall extends AbstractInvocationExpr
@Override
public @Nullable ASTTypeArguments getExplicitTypeArguments() {
- return getFirstChildOfType(ASTTypeArguments.class);
+ return firstChild(ASTTypeArguments.class);
}
@@ -86,25 +86,25 @@ public final class ASTConstructorCall extends AbstractInvocationExpr
/**
* Returns the type node.
*/
- public ASTClassOrInterfaceType getTypeNode() {
- return getFirstChildOfType(ASTClassOrInterfaceType.class);
+ public ASTClassType getTypeNode() {
+ return firstChild(ASTClassType.class);
}
/**
* Returns true if this expression defines a body,
- * which is compiled to an anonymous class. If this
+ * which is compiled to an anonymous class. Otherwise, this
* method returns false.
*/
public boolean isAnonymousClass() {
- return getChild(getNumChildren() - 1) instanceof ASTAnonymousClassDeclaration;
+ return getLastChild() instanceof ASTAnonymousClassDeclaration;
}
@Nullable
public ASTAnonymousClassDeclaration getAnonymousClassDeclaration() {
return isAnonymousClass()
- ? (ASTAnonymousClassDeclaration) getChild(getNumChildren() - 1)
+ ? (ASTAnonymousClassDeclaration) getLastChild()
: null;
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java
index 680cc67820..8747e35f74 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTConstructorDeclaration.java
@@ -24,7 +24,7 @@ import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
*
*
*/
-public final class ASTConstructorDeclaration extends AbstractMethodOrConstructorDeclaration
*
- * CatchParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableDeclaratorId VariableDeclaratorId}
+ * CatchParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableId VariableId}
*
*
*/
public final class ASTCatchParameter extends AbstractJavaNode
implements InternalInterfaces.VariableIdOwner,
- FinalizableNode {
+ ModifierOwner {
ASTCatchParameter(int id) {
super(id);
@@ -50,8 +50,8 @@ public final class ASTCatchParameter extends AbstractJavaNode
@Override
@NonNull
- public ASTVariableDeclaratorId getVarId() {
- return (ASTVariableDeclaratorId) getLastChild();
+ public ASTVariableId getVarId() {
+ return (ASTVariableId) getLastChild();
}
/** Returns the name of this parameter. */
@@ -79,13 +79,17 @@ public final class ASTCatchParameter extends AbstractJavaNode
* Since exception types cannot be interfaces, the LUB always erases
* to a single class supertype (eg {@link RuntimeException}).
*/
- public NodeStream
*
- * ClassOrInterfaceBody ::= "{" {@linkplain ASTBodyDeclaration ClassOrInterfaceBodyDeclaration}* "}"
+ * ClassBody ::= "{" {@linkplain ASTBodyDeclaration ClassBodyDeclaration}* "}"
*
*
*/
-public final class ASTClassOrInterfaceBody extends ASTTypeBody {
+public final class ASTClassBody extends ASTTypeBody {
- ASTClassOrInterfaceBody(int id) {
+ ASTClassBody(int id) {
super(id);
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassDeclaration.java
similarity index 59%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassDeclaration.java
index 82a552135f..5345f20792 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassDeclaration.java
@@ -15,21 +15,21 @@ import net.sourceforge.pmd.lang.ast.Node;
*
*
*
- * ClassOrInterfaceDeclaration ::= {@link ASTModifierList ModifierList}
- * ( "class" | "interface" )
- * <IDENTIFIER>
- * {@link ASTTypeParameters TypeParameters}?
- * {@link ASTExtendsList ExtendsList}?
- * {@link ASTImplementsList ImplementsList}?
- * {@link ASTClassOrInterfaceBody ClassOrInterfaceBody}
+ * ClassDeclaration ::= {@link ASTModifierList ModifierList}
+ * ( "class" | "interface" )
+ * <IDENTIFIER>
+ * {@link ASTTypeParameters TypeParameters}?
+ * {@link ASTExtendsList ExtendsList}?
+ * {@link ASTImplementsList ImplementsList}?
+ * {@link ASTClassBody ClassBody}
*
*
*/
-public final class ASTClassOrInterfaceDeclaration extends AbstractAnyTypeDeclaration {
+public final class ASTClassDeclaration extends AbstractTypeDeclaration {
private boolean isInterface;
- ASTClassOrInterfaceDeclaration(int id) {
+ ASTClassDeclaration(int id) {
super(id);
}
@@ -38,11 +38,6 @@ public final class ASTClassOrInterfaceDeclaration extends AbstractAnyTypeDeclara
return visitor.visit(this, data);
}
- @Override
- public boolean isPackagePrivate() {
- return super.isPackagePrivate() && !isLocal();
- }
-
@Override
public boolean isInterface() {
return this.isInterface;
@@ -70,17 +65,17 @@ public final class ASTClassOrInterfaceDeclaration extends AbstractAnyTypeDeclara
*
*
*
- * ClassOrInterfaceType ::= {@link ASTAnnotation Annotation}* <IDENTIFIER> {@link ASTTypeArguments TypeArguments}?
- * | ClassOrInterfaceType "." {@link ASTAnnotation Annotation}* <IDENTIFIER> {@link ASTTypeArguments TypeArguments}?
+ * ClassType ::= {@link ASTAnnotation Annotation}* <IDENTIFIER> {@link ASTTypeArguments TypeArguments}?
+ * | ClassType "." {@link ASTAnnotation Annotation}* <IDENTIFIER> {@link ASTTypeArguments TypeArguments}?
*
*
*
+ *
*
@@ -24,7 +24,7 @@ import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
*
*
*/
-public final class ASTCompactConstructorDeclaration extends AbstractJavaNode implements ASTBodyDeclaration, SymbolDeclaratorNode, AccessNode {
+public final class ASTCompactConstructorDeclaration extends AbstractJavaNode implements ASTBodyDeclaration, SymbolDeclaratorNode, ModifierOwner {
ASTCompactConstructorDeclaration(int id) {
super(id);
@@ -36,7 +36,7 @@ public final class ASTCompactConstructorDeclaration extends AbstractJavaNode imp
}
public ASTBlock getBody() {
- return getFirstChildOfType(ASTBlock.class);
+ return firstChild(ASTBlock.class);
}
public ASTCompactConstructorDeclaration getDeclarationNode() {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java
index 33fcb2e24b..c13a716375 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java
@@ -32,7 +32,7 @@ import net.sourceforge.pmd.lang.rule.xpath.NoAttribute;
* RegularCompilationUnit ::=
* {@linkplain ASTPackageDeclaration PackageDeclaration}?
* {@linkplain ASTImportDeclaration ImportDeclaration}*
- * {@linkplain ASTAnyTypeDeclaration TypeDeclaration}*
+ * {@linkplain ASTTypeDeclaration TypeDeclaration}*
*
* UnnamedClassCompilationUnit ::=
* {@linkplain ASTImportDeclaration ImportDeclaration}*
@@ -105,8 +105,8 @@ public final class ASTCompilationUnit extends AbstractJavaNode implements JavaNo
* unit. This may be empty, eg if this a package-info.java, or a modular
* compilation unit (but ordinary compilation units may also be empty).
*/
- public NodeStream
*
- * EnumConstant ::= {@link ASTModifierList AnnotationList} {@link ASTVariableDeclaratorId VariableDeclaratorId} {@linkplain ASTArgumentList ArgumentList}? {@linkplain ASTAnonymousClassDeclaration AnonymousClassDeclaration}?
+ * EnumConstant ::= {@link ASTModifierList AnnotationList} {@link ASTVariableId VariableId} {@linkplain ASTArgumentList ArgumentList}? {@linkplain ASTAnonymousClassDeclaration AnonymousClassDeclaration}?
*
*
*/
public final class ASTEnumConstant extends AbstractJavaTypeNode
implements Annotatable,
InvocationNode,
- AccessNode,
+ ModifierOwner,
ASTBodyDeclaration,
InternalInterfaces.VariableIdOwner,
JavadocCommentOwner {
@@ -45,8 +45,8 @@ public final class ASTEnumConstant extends AbstractJavaTypeNode
@Override
- public ASTVariableDeclaratorId getVarId() {
- return getFirstChildOfType(ASTVariableDeclaratorId.class);
+ public ASTVariableId getVarId() {
+ return firstChild(ASTVariableId.class);
}
@Override
@@ -57,7 +57,7 @@ public final class ASTEnumConstant extends AbstractJavaTypeNode
@Override
@Nullable
public ASTArgumentList getArguments() {
- return getFirstChildOfType(ASTArgumentList.class);
+ return firstChild(ASTArgumentList.class);
}
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java
index f20818f7a0..bf0ad882bc 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java
@@ -24,7 +24,7 @@ import net.sourceforge.pmd.lang.ast.Node;
*
*
*/
-public final class ASTEnumDeclaration extends AbstractAnyTypeDeclaration {
+public final class ASTEnumDeclaration extends AbstractTypeDeclaration {
ASTEnumDeclaration(int id) {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodOrConstructorDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTExecutableDeclaration.java
similarity index 87%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodOrConstructorDeclaration.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTExecutableDeclaration.java
index 77b23f8acc..6b0775fca1 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodOrConstructorDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTExecutableDeclaration.java
@@ -18,16 +18,18 @@ import net.sourceforge.pmd.lang.java.types.JMethodSig;
*
*
*
- * MethodOrConstructorDeclaration ::= {@link ASTMethodDeclaration MethodDeclaration}
- * | {@link ASTConstructorDeclaration ConstructorDeclaration}
+ * ExecutableDeclaration ::= {@link ASTMethodDeclaration MethodDeclaration}
+ * | {@link ASTConstructorDeclaration ConstructorDeclaration}
*
*
*
+ *
*
- * ExtendsList ::= "extends" {@link ASTType Type} ( "," {@link ASTType Type} )*
+ * ExtendsList ::= "extends" {@link ASTClassType ClassType} ( "," {@link ASTClassType ClassType} )*
*
*/
-public final class ASTExtendsList extends ASTNonEmptyListnull
if
+ * VariableId node and returns its image or null
if
* the child node is not found.
*
* @return a String representing the name of the variable
*
* @deprecated FieldDeclaration may declare several variables, so this is not exhaustive
- * Iterate on the {@linkplain ASTVariableDeclaratorId VariableDeclaratorIds} instead
+ * Iterate on the {@linkplain ASTVariableId VariableIds} instead
*/
@Deprecated
- @DeprecatedAttribute(replaceWith = "VariableDeclaratorId/@Name")
+ @DeprecatedAttribute(replaceWith = "VariableId/@Name")
public String getVariableName() {
return getVarIds().firstOrThrow().getName();
}
@@ -66,11 +66,18 @@ public final class ASTFieldDeclaration extends AbstractJavaNode
/**
* Returns the type node at the beginning of this field declaration.
* The type of this node is not necessarily the type of the variables,
- * see {@link ASTVariableDeclaratorId#getType()}.
+ * see {@link ASTVariableId#getTypeNode()}.
*/
@Override
public ASTType getTypeNode() {
- return getFirstChildOfType(ASTType.class);
+ return firstChild(ASTType.class);
}
+ /**
+ * Returns true if this field is static.
+ */
+ @Override
+ public boolean isStatic() {
+ return hasModifiers(JModifier.STATIC);
+ }
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForStatement.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForStatement.java
index 007115705c..e2c744efef 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForStatement.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForStatement.java
@@ -31,7 +31,7 @@ public final class ASTForStatement extends AbstractStatement implements ASTLoopS
@Override
public ASTExpression getCondition() {
- return getFirstChildOfType(ASTExpression.class);
+ return firstChild(ASTExpression.class);
}
/**
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForeachStatement.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForeachStatement.java
index d005a2e82b..65734e85f6 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForeachStatement.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTForeachStatement.java
@@ -34,9 +34,9 @@ public final class ASTForeachStatement extends AbstractStatement implements Inte
@Override
@NonNull
- public ASTVariableDeclaratorId getVarId() {
+ public ASTVariableId getVarId() {
// in case of destructuring record patterns, there might be multiple vars
- return getFirstChild().descendants(ASTVariableDeclaratorId.class).first();
+ return getFirstChild().descendants(ASTVariableId.class).first();
}
/**
@@ -45,7 +45,7 @@ public final class ASTForeachStatement extends AbstractStatement implements Inte
*/
@NonNull
public ASTExpression getIterableExpr() {
- return getFirstChildOfType(ASTExpression.class);
+ return firstChild(ASTExpression.class);
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameter.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameter.java
index 36d77b48a1..efc7a97a6b 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameter.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTFormalParameter.java
@@ -20,12 +20,12 @@ import net.sourceforge.pmd.lang.java.types.TypingContext;
*
*
*
- * FormalParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableDeclaratorId VariableDeclaratorId}
+ * FormalParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableId VariableId}
*
*
*/
public final class ASTFormalParameter extends AbstractJavaNode
- implements FinalizableNode,
+ implements ModifierOwner,
TypeNode,
Annotatable,
VariableIdOwner {
@@ -69,8 +69,8 @@ public final class ASTFormalParameter extends AbstractJavaNode
* Returns the declarator ID of this formal parameter.
*/
@Override
- public @NonNull ASTVariableDeclaratorId getVarId() {
- return firstChild(ASTVariableDeclaratorId.class);
+ public @NonNull ASTVariableId getVarId() {
+ return firstChild(ASTVariableId.class);
}
@@ -90,4 +90,9 @@ public final class ASTFormalParameter extends AbstractJavaNode
public @NonNull JTypeMirror getTypeMirror(TypingContext ctx) {
return getVarId().getTypeMirror(ctx);
}
+
+ @Override
+ public boolean isFinal() {
+ return hasModifiers(JModifier.FINAL);
+ }
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTImplementsList.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTImplementsList.java
index e7b1c0cf08..61b7dc22ac 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTImplementsList.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTImplementsList.java
@@ -12,14 +12,14 @@ import net.sourceforge.pmd.lang.java.ast.ASTList.ASTNonEmptyList;
*
*
*
- * ImplementsList ::= "implements" {@link ASTClassOrInterfaceType ClassOrInterfaceType} ( "," {@link ASTClassOrInterfaceType ClassOrInterfaceType})*
+ * ImplementsList ::= "implements" {@link ASTClassType InterfaceType} ( "," {@link ASTClassType InterfaceType})*
*
*
*/
-public final class ASTImplementsList extends ASTNonEmptyList
*
- * IntersectionType ::= {@link ASTClassOrInterfaceType ClassOrInterfaceType} ("&" {@link ASTClassOrInterfaceType InterfaceType})+
+ * IntersectionType ::= {@link ASTClassType ClassOrInterfaceType} ("&" {@link ASTClassType InterfaceType})+
*
*
*/
@@ -36,8 +36,8 @@ public final class ASTIntersectionType extends AbstractJavaTypeNode
}
/** Returns a stream of component types. */
- public NodeStream
*
- * LambdaParameter ::= {@link ASTModifierList LocalVarModifierList} ( "var" | {@link ASTType Type} ) {@link ASTVariableDeclaratorId VariableDeclaratorId}
- * | {@link ASTModifierList EmptyModifierList} {@link ASTVariableDeclaratorId VariableDeclaratorId}
+ * LambdaParameter ::= {@link ASTModifierList LocalVarModifierList} ( "var" | {@link ASTType Type} ) {@link ASTVariableId VariableId}
+ * | {@link ASTModifierList EmptyModifierList} {@link ASTVariableId VariableId}
*
*
*/
public final class ASTLambdaParameter extends AbstractJavaTypeNode
- implements InternalInterfaces.VariableIdOwner,
- FinalizableNode {
+ implements InternalInterfaces.VariableIdOwner, ModifierOwner {
ASTLambdaParameter(int id) {
super(id);
@@ -30,7 +29,7 @@ public final class ASTLambdaParameter extends AbstractJavaTypeNode
* If true, this formal parameter represents one without explicit types.
* This can appear as part of a lambda expression with java11 using "var".
*
- * @see ASTVariableDeclaratorId#isTypeInferred()
+ * @see ASTVariableId#isTypeInferred()
*/
public boolean isTypeInferred() {
return getTypeNode() == null;
@@ -53,14 +52,18 @@ public final class ASTLambdaParameter extends AbstractJavaTypeNode
*/
@Override
@NonNull
- public ASTVariableDeclaratorId getVarId() {
- return getFirstChildOfType(ASTVariableDeclaratorId.class);
+ public ASTVariableId getVarId() {
+ return firstChild(ASTVariableId.class);
}
/** Returns the type node of this formal parameter. */
@Nullable
public ASTType getTypeNode() {
- return getFirstChildOfType(ASTType.class);
+ return firstChild(ASTType.class);
}
+ @Override
+ public boolean isFinal() {
+ return hasModifiers(JModifier.FINAL);
+ }
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLiteral.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLiteral.java
index a41af7d2c9..948e03f101 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLiteral.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLiteral.java
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.ast;
+import net.sourceforge.pmd.lang.document.Chars;
+
/**
* A lexical literal. This is an expression that is represented by exactly
* one token. This interface is implemented by several nodes.
@@ -103,4 +105,9 @@ public interface ASTLiteral extends ASTPrimaryExpression {
return false;
}
+ /**
+ * Return the text of the literal in the source file. Note that
+ * {@link #getText()} may include parentheses.
+ */
+ Chars getLiteralText();
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalClassStatement.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalClassStatement.java
index dc47d51924..38f7930b8c 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalClassStatement.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalClassStatement.java
@@ -12,7 +12,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
*
*
*
- * LocalClassStatement ::= {@link ASTAnyTypeDeclaration TypeDeclaration}
+ * LocalClassStatement ::= {@link ASTTypeDeclaration TypeDeclaration}
*
*
*/
@@ -22,7 +22,7 @@ public final class ASTLocalClassStatement extends AbstractStatement {
super(id);
}
- ASTLocalClassStatement(ASTAnyTypeDeclaration tdecl) {
+ ASTLocalClassStatement(ASTTypeDeclaration tdecl) {
super(JavaParserImplTreeConstants.JJTLOCALCLASSSTATEMENT);
assert tdecl != null;
addChild((AbstractJavaNode) tdecl, 0);
@@ -39,8 +39,8 @@ public final class ASTLocalClassStatement extends AbstractStatement {
/**
* Returns the contained declaration.
*/
- public @NonNull ASTAnyTypeDeclaration getDeclaration() {
- return (ASTAnyTypeDeclaration) getChild(0);
+ public @NonNull ASTTypeDeclaration getDeclaration() {
+ return (ASTTypeDeclaration) getChild(0);
}
@Override
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclaration.java
index 816b6956ff..a1cac8ac1a 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclaration.java
@@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.document.FileLocation;
* {@linkplain ASTForStatement foreach statements}.
*
*
@@ -25,9 +25,9 @@ import net.sourceforge.pmd.lang.document.FileLocation;
*/
// TODO extend AbstractStatement
public final class ASTLocalVariableDeclaration extends AbstractJavaNode
- implements Iterable
*/
-public final class ASTMethodDeclaration extends AbstractMethodOrConstructorDeclaration
*
* ModuleProvidesDirective ::=
- * "provides" {@linkplain ASTClassOrInterfaceType ClassType}
- * "with" {@linkplain ASTClassOrInterfaceType ClassType} ( "," {@linkplain ASTClassOrInterfaceType ClassType} )*
+ * "provides" {@linkplain ASTClassType ClassType}
+ * "with" {@linkplain ASTClassType ClassType} ( "," {@linkplain ASTClassType ClassType} )*
* ";"
*
*
@@ -32,15 +32,15 @@ public final class ASTModuleProvidesDirective extends ASTModuleDirective {
/**
* Returns the node representing the provided interface.
*/
- public ASTClassOrInterfaceType getService() {
- return firstChild(ASTClassOrInterfaceType.class);
+ public ASTClassType getService() {
+ return firstChild(ASTClassType.class);
}
/**
* Returns the nodes representing the service providers, that is,
* the service implementations.
*/
- public NodeStream
*
- * PermitsList ::= "permits" ClassOrInterfaceType
- * ( "," ClassOrInterfaceType )*
+ * PermitsList ::= "permits" ClassType
+ * ( "," ClassType )*
*
*/
-public final class ASTPermitsList extends ASTNonEmptyList
*
- * ReceiverParameter ::= {@link ASTClassOrInterfaceType ClassOrInterfaceType} (<IDENTIFIER> ".")? "this"
+ * ReceiverParameter ::= {@link ASTClassType ClassType} (<IDENTIFIER> ".")? "this"
*
*
*/
@@ -58,8 +58,8 @@ public final class ASTReceiverParameter extends AbstractJavaNode {
* must be {@code Identifier.this} where {@code Identifier} is the simple name of C.
*/
@NonNull
- public ASTClassOrInterfaceType getReceiverType() {
- return (ASTClassOrInterfaceType) getChild(0);
+ public ASTClassType getReceiverType() {
+ return (ASTClassType) getChild(0);
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordComponent.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordComponent.java
index 41150fab7e..faf4d77d1e 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordComponent.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordComponent.java
@@ -20,7 +20,7 @@ import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
* scope in the body of a {@linkplain ASTRecordConstructorDeclaration compact record constructor}).
* They also may imply the declaration of an accessor method.
*
- *
*
- * RecordComponent ::= {@linkplain ASTAnnotation Annotation}* {@linkplain ASTType Type} {@linkplain ASTVariableDeclaratorId VariableDeclaratorId}
+ * RecordComponent ::= {@linkplain ASTAnnotation Annotation}* {@linkplain ASTType Type} {@linkplain ASTVariableId VariableId}
*
*
*/
-public final class ASTRecordComponent extends AbstractJavaNode implements AccessNode, VariableIdOwner {
+public final class ASTRecordComponent extends AbstractJavaNode implements ModifierOwner, VariableIdOwner {
ASTRecordComponent(int id) {
super(id);
@@ -56,11 +56,11 @@ public final class ASTRecordComponent extends AbstractJavaNode implements Access
}
public ASTType getTypeNode() {
- return getFirstChildOfType(ASTType.class);
+ return firstChild(ASTType.class);
}
@Override
- public ASTVariableDeclaratorId getVarId() {
- return getFirstChildOfType(ASTVariableDeclaratorId.class);
+ public ASTVariableId getVarId() {
+ return firstChild(ASTVariableId.class);
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java
index d264b51603..8b200646fa 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java
@@ -28,7 +28,7 @@ import net.sourceforge.pmd.lang.ast.NodeStream;
*
* @see JEP 395: Records
*/
-public final class ASTRecordDeclaration extends AbstractAnyTypeDeclaration {
+public final class ASTRecordDeclaration extends AbstractTypeDeclaration {
ASTRecordDeclaration(int id) {
super(id);
}
@@ -40,12 +40,12 @@ public final class ASTRecordDeclaration extends AbstractAnyTypeDeclaration {
@Override
public NodeStream
*
- * ReferenceType ::= {@link ASTClassOrInterfaceType ClassOrInterfaceType}
+ * ReferenceType ::= {@link ASTClassType ClassOrInterfaceType}
* | {@link ASTArrayType ArrayType}
* | {@link ASTIntersectionType IntersectionType}
* | {@link ASTUnionType UnionType}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTStringLiteral.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTStringLiteral.java
index 651eefe415..5612c7a4bc 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTStringLiteral.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTStringLiteral.java
@@ -15,7 +15,7 @@ import net.sourceforge.pmd.util.StringUtil;
/**
* Represents a string literal. The image of this node is the literal as it appeared
- * in the source ({@link #getText()}). {@link #getConstValue()} allows to recover
+ * in the source ({@link #getLiteralText()}). {@link #getConstValue()} allows to recover
* the actual runtime value, by processing escapes.
*/
public final class ASTStringLiteral extends AbstractLiteral implements ASTLiteral {
@@ -29,7 +29,7 @@ public final class ASTStringLiteral extends AbstractLiteral implements ASTLitera
}
- // todo deprecate this
+ // TODO deprecate / remove this
// it's ambiguous whether it returns getOriginalText or getTranslatedText
@Override
public String getImage() {
@@ -50,7 +50,7 @@ public final class ASTStringLiteral extends AbstractLiteral implements ASTLitera
if (isTextBlock) {
return getConstValue().isEmpty(); // could be a bunch of ignorable indents?
} else {
- return getImage().length() == 2; // ""
+ return getLiteralText().length() == 2; // ""
}
}
@@ -85,9 +85,9 @@ public final class ASTStringLiteral extends AbstractLiteral implements ASTLitera
@Override
protected @NonNull String buildConstValue() {
if (isTextBlock()) {
- return determineTextBlockContent(getText());
+ return determineTextBlockContent(getLiteralText());
} else {
- return determineStringContent(getText());
+ return determineStringContent(getLiteralText());
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSuperExpression.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSuperExpression.java
index bf91ebba8f..b565424356 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSuperExpression.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSuperExpression.java
@@ -13,7 +13,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*
*
* SuperExpression ::= "super"
- * | {@link ASTClassOrInterfaceType TypeName} "." "super"
+ * | {@link ASTClassType ClassType} "." "super"
*
*
*/
@@ -24,8 +24,8 @@ public final class ASTSuperExpression extends AbstractJavaExpr implements ASTPri
@Nullable
- public ASTClassOrInterfaceType getQualifier() {
- return getNumChildren() > 0 ? (ASTClassOrInterfaceType) getChild(0) : null;
+ public ASTClassType getQualifier() {
+ return getNumChildren() > 0 ? (ASTClassType) getChild(0) : null;
}
@Override
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThisExpression.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThisExpression.java
index 7af226d5e3..145dd50dc9 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThisExpression.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThisExpression.java
@@ -13,7 +13,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*
*
* ThisExpression ::= "this"
- * | {@link ASTClassOrInterfaceType TypeName} "." "this"
+ * | {@link ASTClassType ClassType} "." "this"
*
*
*/
@@ -25,8 +25,8 @@ public final class ASTThisExpression extends AbstractJavaExpr implements ASTPrim
@Nullable
- public ASTClassOrInterfaceType getQualifier() {
- return getNumChildren() > 0 ? (ASTClassOrInterfaceType) getChild(0) : null;
+ public ASTClassType getQualifier() {
+ return getNumChildren() > 0 ? (ASTClassType) getChild(0) : null;
}
@Override
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowsList.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowsList.java
index 5a845eea57..05847e6056 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowsList.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowsList.java
@@ -11,14 +11,14 @@ import net.sourceforge.pmd.lang.java.ast.ASTList.ASTNonEmptyList;
*
*
*
- * ThrowsList ::= "throws" {@link ASTClassOrInterfaceType ClassType} ("," {@link ASTClassOrInterfaceType ClassType})*
+ * ThrowsList ::= "throws" {@link ASTClassType ClassType} ("," {@link ASTClassType ClassType})*
*
*
*/
-public final class ASTThrowsList extends ASTNonEmptyList
*
- * TypeBody ::= {@link ASTClassOrInterfaceBody ClassOrInterfaceBody}
+ * TypeBody ::= {@link ASTClassBody ClassBody}
* | {@link ASTEnumBody EnumBody}
* | {@link ASTRecordBody RecordBody}
* | {@link ASTAnnotationTypeBody AnnotationTypeBody}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTTypeDeclaration.java
similarity index 85%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTTypeDeclaration.java
index 5a51c7b109..0d37452459 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTTypeDeclaration.java
@@ -21,21 +21,23 @@ import net.sourceforge.pmd.lang.rule.xpath.DeprecatedAttribute;
*
*
*
* @see JEP 394: Pattern Matching for instanceof
*/
-public final class ASTTypePattern extends AbstractJavaNode implements ASTPattern, AccessNode {
+public final class ASTTypePattern extends AbstractJavaNode implements ASTPattern, ModifierOwner {
private int parenDepth;
@@ -44,8 +44,8 @@ public final class ASTTypePattern extends AbstractJavaNode implements ASTPattern
}
/** Returns the declared variable. */
- public @NonNull ASTVariableDeclaratorId getVarId() {
- return Objects.requireNonNull(firstChild(ASTVariableDeclaratorId.class));
+ public @NonNull ASTVariableId getVarId() {
+ return Objects.requireNonNull(firstChild(ASTVariableId.class));
}
void bumpParenDepth() {
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTUnionType.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTUnionType.java
index fe08133cce..0d458c3ff4 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTUnionType.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTUnionType.java
@@ -19,7 +19,7 @@ import net.sourceforge.pmd.lang.java.ast.InternalInterfaces.AtLeastOneChildOfTyp
*
*
*
- * AnyTypeDeclaration ::= {@link ASTClassOrInterfaceDeclaration ClassOrInterfaceDeclaration}
- * | {@link ASTAnonymousClassDeclaration AnonymousClassDeclaration}
- * | {@link ASTEnumDeclaration EnumDeclaration}
- * | {@link ASTAnnotationTypeDeclaration AnnotationTypeDeclaration}
- * | {@link ASTRecordDeclaration RecordDeclaration}
+ * TypeDeclaration ::= {@link ASTClassDeclaration ClassDeclaration}
+ * | {@link ASTAnonymousClassDeclaration AnonymousClassDeclaration}
+ * | {@link ASTEnumDeclaration EnumDeclaration}
+ * | {@link ASTAnnotationTypeDeclaration AnnotationTypeDeclaration}
+ * | {@link ASTRecordDeclaration RecordDeclaration}
*
*
+ *
+ *
*
- * UnionType ::= {@link ASTClassOrInterfaceType ClassType} ("|" {@link ASTClassOrInterfaceType ClassType})+
+ * UnionType ::= {@link ASTClassType ClassType} ("|" {@link ASTClassType ClassType})+
*
*
*
@@ -27,8 +27,8 @@ import net.sourceforge.pmd.lang.java.ast.InternalInterfaces.AtLeastOneChildOfTyp
*/
public final class ASTUnionType extends AbstractJavaTypeNode
implements ASTReferenceType,
- AtLeastOneChildOfType
*
- * VariableDeclarator ::= {@linkplain ASTVariableDeclaratorId VariableDeclaratorId} ( "=" {@linkplain ASTExpression Expression} )?
+ * VariableDeclarator ::= {@linkplain ASTVariableId VariableId} ( "=" {@linkplain ASTExpression Expression} )?
*
*
*/
@@ -48,8 +48,8 @@ public class ASTVariableDeclarator extends AbstractJavaNode implements InternalI
*/
@Override
@NonNull
- public ASTVariableDeclaratorId getVarId() {
- return (ASTVariableDeclaratorId) getChild(0);
+ public ASTVariableId getVarId() {
+ return (ASTVariableId) getChild(0);
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableId.java
similarity index 92%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableId.java
index 4c2d2c1089..63666c0b41 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableId.java
@@ -14,6 +14,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
import net.sourceforge.pmd.lang.java.symbols.JVariableSymbol;
+import net.sourceforge.pmd.lang.java.types.JTypeMirror;
import net.sourceforge.pmd.lang.rule.xpath.DeprecatedAttribute;
// @formatter:off
@@ -36,17 +37,18 @@ import net.sourceforge.pmd.lang.rule.xpath.DeprecatedAttribute;
*
*
*
- * VariableDeclaratorId ::= <IDENTIFIER> {@link ASTArrayDimensions ArrayDimensions}?
+ * VariableId ::= <IDENTIFIER> {@link ASTArrayDimensions ArrayDimensions}?
*
*
*
+ *