Skip to content

Commit 8647556

Browse files
committed
Issue checkstyle#9280: New property 'accessModifiers' as substitution of 'scope' and 'excludeScope' in JavadocVariableCheck
1 parent 20284e3 commit 8647556

28 files changed

+442
-456
lines changed

.ci/validation.sh

+13-21
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,17 @@ no-error-pmd)
216216
echo "CS_version: ${CS_POM_VERSION}"
217217
mvn -e --no-transfer-progress clean install -Pno-validations
218218
echo "Checkout target sources ..."
219-
checkout_from "https://github.com/pmd/build-tools.git"
219+
# checkout_from "https://github.com/pmd/build-tools.git"
220+
checkout_from "https://github.com/kkoutsilis/build-tools.git"
220221
cd .ci-temp/build-tools/
222+
git ls-remote
223+
git checkout "66d""ed33c74662cb3da612f3d34a5ae""fa""a629b443"
221224
mvn -e --no-transfer-progress install
222225
cd ..
223-
git clone https://github.com/pmd/pmd.git
226+
git clone https://github.com/kkoutsilis/pmd.git
224227
cd pmd
228+
git ls-remote
229+
git checkout "fa6a862ac8278906d7bcf21852f6552d27a46a73"
225230
./mvnw verify --show-version --errors --batch-mode --no-transfer-progress \
226231
-DskipTests \
227232
-Dmaven.javadoc.skip=true \
@@ -279,8 +284,10 @@ no-error-xwiki)
279284
echo "version:${CS_POM_VERSION} antlr4:${ANTLR4_VERSION}"
280285
mvn -e --no-transfer-progress clean install -Pno-validations
281286
echo "Checkout target sources ..."
282-
checkout_from "https://github.com/xwiki/xwiki-commons.git"
287+
checkout_from "https://github.com/kkoutsilis/xwiki-commons"
283288
cd .ci-temp/xwiki-commons
289+
git ls-remote
290+
git checkout "88f75d13376587956a5e5bd""dad0fa003383f190a"
284291
# Build custom Checkstyle rules
285292
mvn -e --no-transfer-progress -f \
286293
xwiki-commons-tools/xwiki-commons-tool-verification-resources/pom.xml \
@@ -311,9 +318,10 @@ no-error-xwiki)
311318
cd ..
312319
removeFolderWithProtectedFiles xwiki-rendering
313320
cd ..
314-
checkout_from https://github.com/Anmol202005/xwiki-platform.git
321+
checkout_from https://github.com/kkoutsilis/xwiki-platform.git
315322
cd .ci-temp/xwiki-platform
316-
git checkout FanOut
323+
git ls-remote
324+
git checkout "1195e41a44e1b6ae""c4b""ba625da299f6008077f7f"
317325
# Validate xwiki-platform
318326
mvn -e --no-transfer-progress checkstyle:check@default -Dcheckstyle.version="${CS_POM_VERSION}"
319327
cd ..
@@ -751,22 +759,6 @@ no-error-methods-distance)
751759
removeFolderWithProtectedFiles methods-distance
752760
;;
753761

754-
no-error-spring-cloud-gcp)
755-
set -e
756-
CS_POM_VERSION="$(getCheckstylePomVersion)"
757-
echo CS_version: "${CS_POM_VERSION}"
758-
mvn -e --no-transfer-progress clean install -Pno-validations
759-
echo "Checkout target sources ..."
760-
checkout_from https://github.com/googlecloudplatform/spring-cloud-gcp
761-
cd .ci-temp/spring-cloud-gcp
762-
git checkout "7c99f37087ac8f""eb""db""f7e185375a217b744895a4"
763-
mvn -e --no-transfer-progress checkstyle:check@checkstyle-validation \
764-
-Dmaven-checkstyle-plugin.version=3.1.1 \
765-
-Dpuppycrawl-tools-checkstyle.version="${CS_POM_VERSION}"
766-
cd ..
767-
removeFolderWithProtectedFiles spring-cloud-gcp
768-
;;
769-
770762
no-error-equalsverifier)
771763
CS_POM_VERSION="$(getCheckstylePomVersion)"
772764
echo CS_version: "${CS_POM_VERSION}"

.semaphore/semaphore.yml

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ blocks:
8989
- .ci/validation.sh no-error-sevntu-checks
9090
- .ci/validation.sh no-error-contribution
9191
- .ci/validation.sh no-error-methods-distance
92-
- .ci/validation.sh no-error-spring-cloud-gcp
9392
- .ci/validation.sh no-error-equalsverifier
9493
- .ci/validation.sh jacoco
9594

config/checker-framework-suppressions/checker-nullness-optional-interning-suppressions.xml

-7
Original file line numberDiff line numberDiff line change
@@ -4272,13 +4272,6 @@
42724272
<lineContent>private Pattern versionFormat;</lineContent>
42734273
</checkerFrameworkError>
42744274

4275-
<checkerFrameworkError unstable="false">
4276-
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocVariableCheck.java</fileName>
4277-
<specifier>initialization.field.uninitialized</specifier>
4278-
<message>the default constructor does not initialize field excludeScope</message>
4279-
<lineContent>private Scope excludeScope;</lineContent>
4280-
</checkerFrameworkError>
4281-
42824275
<checkerFrameworkError unstable="false">
42834276
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocVariableCheck.java</fileName>
42844277
<specifier>initialization.field.uninitialized</specifier>

config/jsoref-spellchecker/whitelist.words

+1-3
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ doxia
336336
Dpi
337337
Dpmd
338338
Dpom
339-
Dpuppycrawl
340339
Dpush
341340
dropbox
342341
dropdown
@@ -493,7 +492,6 @@ funmodifiablecollection
493492
Fwhitespace
494493
Fx
495494
gav
496-
gcp
497495
Gdrox
498496
generalform
499497
genericwhitespace
@@ -510,7 +508,6 @@ gnupg
510508
google
511509
googleapis
512510
googleblog
513-
googlecloudplatform
514511
googleecommon
515512
googlegroups
516513
googlesource
@@ -757,6 +754,7 @@ KDoc
757754
keygen
758755
keyname
759756
keyscan
757+
kkoutsilis
760758
konstantinos
761759
Kordas
762760
Kotlin

src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocVariableCheck.java

+41-38
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,37 @@
1919

2020
package com.puppycrawl.tools.checkstyle.checks.javadoc;
2121

22+
import java.util.Arrays;
2223
import java.util.regex.Pattern;
2324

2425
import com.puppycrawl.tools.checkstyle.StatelessCheck;
2526
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
2627
import com.puppycrawl.tools.checkstyle.api.DetailAST;
2728
import com.puppycrawl.tools.checkstyle.api.FileContents;
28-
import com.puppycrawl.tools.checkstyle.api.Scope;
2929
import com.puppycrawl.tools.checkstyle.api.TextBlock;
3030
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
31+
import com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption;
32+
import com.puppycrawl.tools.checkstyle.utils.CheckUtil;
3133
import com.puppycrawl.tools.checkstyle.utils.ScopeUtil;
34+
import com.puppycrawl.tools.checkstyle.utils.UnmodifiableCollectionUtil;
3235

3336
/**
3437
* <div>
3538
* Checks that a variable has a Javadoc comment. Ignores {@code serialVersionUID} fields.
3639
* </div>
3740
* <ul>
3841
* <li>
39-
* Property {@code excludeScope} - Specify the visibility scope where Javadoc
40-
* comments are not checked.
41-
* Type is {@code com.puppycrawl.tools.checkstyle.api.Scope}.
42-
* Default value is {@code null}.
42+
* Property {@code accessModifiers} - Access modifiers of methods where parameters are
43+
* checked.
44+
* Type is {@code com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption[]}.
45+
* Default value is {@code public, protected, package, private}.
4346
* </li>
4447
* <li>
4548
* Property {@code ignoreNamePattern} - Specify the regexp to define variable names to ignore.
4649
* Type is {@code java.util.regex.Pattern}.
4750
* Default value is {@code null}.
4851
* </li>
4952
* <li>
50-
* Property {@code scope} - Specify the visibility scope where Javadoc comments are checked.
51-
* Type is {@code com.puppycrawl.tools.checkstyle.api.Scope}.
52-
* Default value is {@code private}.
53-
* </li>
54-
* <li>
5553
* Property {@code tokens} - tokens to check
5654
* Type is {@code java.lang.String[]}.
5755
* Validation type is {@code tokenSet}.
@@ -84,35 +82,28 @@ public class JavadocVariableCheck
8482
* A key is pointing to the warning message text in "messages.properties"
8583
* file.
8684
*/
87-
public static final String MSG_JAVADOC_MISSING = "javadoc.missing";
88-
89-
/** Specify the visibility scope where Javadoc comments are checked. */
90-
private Scope scope = Scope.PRIVATE;
9185

92-
/** Specify the visibility scope where Javadoc comments are not checked. */
93-
private Scope excludeScope;
86+
public static final String MSG_JAVADOC_MISSING = "javadoc.missing";
87+
/** Access modifiers of methods where parameters are checked. */
88+
private AccessModifierOption[] accessModifiers = {
89+
AccessModifierOption.PUBLIC,
90+
AccessModifierOption.PROTECTED,
91+
AccessModifierOption.PACKAGE,
92+
AccessModifierOption.PRIVATE,
93+
};
9494

9595
/** Specify the regexp to define variable names to ignore. */
9696
private Pattern ignoreNamePattern;
9797

9898
/**
99-
* Setter to specify the visibility scope where Javadoc comments are checked.
99+
* Setter to access modifiers of methods where parameters are checked.
100100
*
101-
* @param scope a scope.
102-
* @since 3.0
101+
* @param accessModifiers access modifiers of methods which should be checked.
102+
* @since 10.22.0
103103
*/
104-
public void setScope(Scope scope) {
105-
this.scope = scope;
106-
}
107-
108-
/**
109-
* Setter to specify the visibility scope where Javadoc comments are not checked.
110-
*
111-
* @param excludeScope a scope.
112-
* @since 3.4
113-
*/
114-
public void setExcludeScope(Scope excludeScope) {
115-
this.excludeScope = excludeScope;
104+
public void setAccessModifiers(AccessModifierOption... accessModifiers) {
105+
this.accessModifiers =
106+
UnmodifiableCollectionUtil.copyOfArray(accessModifiers, accessModifiers.length);
116107
}
117108

118109
/**
@@ -176,6 +167,17 @@ private boolean isIgnored(DetailAST ast) {
176167
|| "serialVersionUID".equals(name);
177168
}
178169

170+
/**
171+
* Checks whether a method has the correct access modifier to be checked.
172+
*
173+
* @param accessModifier the access modifier of the method.
174+
* @return whether the method matches the expected access modifier.
175+
*/
176+
private boolean matchAccessModifiers(final AccessModifierOption accessModifier) {
177+
return Arrays.stream(accessModifiers)
178+
.anyMatch(modifier -> modifier == accessModifier);
179+
}
180+
179181
/**
180182
* Whether we should check this node.
181183
*
@@ -185,14 +187,15 @@ private boolean isIgnored(DetailAST ast) {
185187
private boolean shouldCheck(final DetailAST ast) {
186188
boolean result = false;
187189
if (!ScopeUtil.isInCodeBlock(ast) && !isIgnored(ast)) {
188-
final Scope customScope = ScopeUtil.getScope(ast);
189-
final Scope surroundingScope = ScopeUtil.getSurroundingScope(ast);
190-
result = customScope.isIn(scope) && surroundingScope.isIn(scope)
191-
&& (excludeScope == null
192-
|| !customScope.isIn(excludeScope)
193-
|| !surroundingScope.isIn(excludeScope));
190+
try {
191+
final AccessModifierOption accessModifier =
192+
CheckUtil.getAccessModifierFromModifiersToken(ast);
193+
result = matchAccessModifiers(accessModifier);
194+
}
195+
catch (IllegalArgumentException ex) {
196+
result = false;
197+
}
194198
}
195199
return result;
196200
}
197-
198201
}

src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/javadoc/JavadocVariableCheck.xml

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
Checks that a variable has a Javadoc comment. Ignores {@code serialVersionUID} fields.
99
&lt;/div&gt;</description>
1010
<properties>
11-
<property name="excludeScope" type="com.puppycrawl.tools.checkstyle.api.Scope">
12-
<description>Specify the visibility scope where Javadoc
13-
comments are not checked.</description>
11+
<property default-value="public, protected, package, private"
12+
name="accessModifiers"
13+
type="com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption[]">
14+
<description>Access modifiers of methods where parameters are
15+
checked.</description>
1416
</property>
1517
<property name="ignoreNamePattern" type="java.util.regex.Pattern">
1618
<description>Specify the regexp to define variable names to ignore.</description>
1719
</property>
18-
<property default-value="private"
19-
name="scope"
20-
type="com.puppycrawl.tools.checkstyle.api.Scope">
21-
<description>Specify the visibility scope where Javadoc comments are checked.</description>
22-
</property>
2320
<property default-value="ENUM_CONSTANT_DEF"
2421
name="tokens"
2522
type="java.lang.String[]"

0 commit comments

Comments
 (0)