Skip to content

Commit e44fe97

Browse files
zyadahmedromani
authored andcommitted
Issue #16836: New Check HexLiteralCase
1 parent c87ec0d commit e44fe97

File tree

32 files changed

+651
-58
lines changed

32 files changed

+651
-58
lines changed

config/checkstyle-checks.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@
835835
<property name="excludedClasses" value="\.(Main|JavadocPropertiesGenerator)$"/>
836836
</module>
837837
<module name="UpperEll"/>
838+
<module name="HexLiteralCase"/>
838839

839840
<!-- Modifiers -->
840841
<module name="ClassMemberImpliedModifier">

config/checkstyle-non-main-files-suppressions.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,7 @@
316316
files="src[\\/]site[\\/]xdoc[\\/]checks[\\/]coding[\\/]whenshouldbeused.xml.template"/>
317317
<suppress id="propertiesMacroMustExist"
318318
files="src[\\/]site[\\/]xdoc[\\/]checks[\\/]coding[\\/]patternvariableassignment.xml.template"/>
319+
<suppress id="propertiesMacroMustExist"
320+
files="src[\\/]site[\\/]xdoc[\\/]checks[\\/]misc[\\/]hexliteralcase.xml.template"/>
319321

320322
</suppressions>

config/jsoref-spellchecker/whitelist.words

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ allchecks
2323
allclasses
2424
allowlegacy
2525
alot
26+
alundblad
2627
amazonaws
2728
amd
2829
amitkumardeoghoria
@@ -270,7 +271,9 @@ dcm
270271
Dconfig
271272
Dconnection
272273
ddd
274+
DDDL
273275
Ddry
276+
DEADBEEF
274277
DECCHARS
275278
declarationorder
276279
declaredwhenneeded
@@ -423,8 +426,11 @@ FEF
423426
fenum
424427
ffd
425428
fff
429+
FFFA
430+
FFFB
426431
FFFD
427-
FFFF
432+
ffff
433+
FFFFL
428434
Fgoogle
429435
Fheader
430436
fht
@@ -541,6 +547,7 @@ hcoles
541547
Headerjava
542548
Hejl
543549
HEXCHARS
550+
hexliteralcase
544551
hh
545552
hiddenfield
546553
hideutilityclassconstructor
@@ -1094,6 +1101,7 @@ Popup
10941101
Postgresql
10951102
powershell
10961103
prebuilts
1104+
prefs
10971105
PRESIZE
10981106
prettyprint
10991107
printf
@@ -1517,19 +1525,16 @@ Wsdl
15171525
www
15181526
Wyq
15191527
xa
1528+
xabc
15201529
xar
15211530
xargs
15221531
XDcompile
1532+
xdeadbeef
15231533
xdoc
15241534
xdocspagetitle
15251535
Xep
15261536
Xerces
15271537
xf
1528-
xfeff
1529-
xfff
1530-
xfffa
1531-
xfffb
1532-
xffff
15331538
xffffffff
15341539
xffffffffffffffff
15351540
xg

config/linkcheck-suppressions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheck.UniqueProperties.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
210210
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
211211
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
212+
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/HexLiteralCaseCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
212213
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
213214
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationOnSameLineCheck.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
214215
<a href="apidocs/com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleCheck.ClosingParensOption.html#%3Cinit%3E()">#%3Cinit%3E()</a>: doesn't exist.
@@ -970,6 +971,7 @@
970971
<a href="com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheck.UniqueProperties.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheck.UniqueProperties.html#%3Cinit%3E()</a>: doesn't exist.
971972
<a href="com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheck.html#%3Cinit%3E()</a>: doesn't exist.
972973
<a href="com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.html#%3Cinit%3E()</a>: doesn't exist.
974+
<a href="com/puppycrawl/tools/checkstyle/checks/HexLiteralCaseCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/HexLiteralCaseCheck.html#%3Cinit%3E()</a>: doesn't exist.
973975
<a href="com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationLocationCheck.html#%3Cinit%3E()</a>: doesn't exist.
974976
<a href="com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationOnSameLineCheck.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationOnSameLineCheck.html#%3Cinit%3E()</a>: doesn't exist.
975977
<a href="com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleCheck.ClosingParensOption.html#%3Cinit%3E()">com/puppycrawl/tools/checkstyle/checks/annotation/AnnotationUseStyleCheck.ClosingParensOption.html#%3Cinit%3E()</a>: doesn't exist.

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,7 @@
32383238
<param>com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheck*</param>
32393239
<param>com.puppycrawl.tools.checkstyle.checks.UniquePropertiesCheck*</param>
32403240
<param>com.puppycrawl.tools.checkstyle.checks.UpperEllCheck*</param>
3241+
<param>com.puppycrawl.tools.checkstyle.checks.HexLiteralCaseCheck*</param>
32413242
</targetClasses>
32423243
<targetTests>
32433244
<param>com.puppycrawl.tools.checkstyle.checks.ArrayTypeStyleCheckTest</param>
@@ -3257,6 +3258,7 @@
32573258
<param>com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheckTest</param>
32583259
<param>com.puppycrawl.tools.checkstyle.checks.UniquePropertiesCheckTest</param>
32593260
<param>com.puppycrawl.tools.checkstyle.checks.UpperEllCheckTest</param>
3261+
<param>com.puppycrawl.tools.checkstyle.checks.HexLiteralCaseCheckTest</param>
32603262
<!-- needed for SuppressWarningsFilter -->
32613263
<param>com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilterTest</param>
32623264
</targetTests>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
///////////////////////////////////////////////////////////////////////////////////////////////
2+
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3+
// Copyright (C) 2001-2025 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
///////////////////////////////////////////////////////////////////////////////////////////////
19+
20+
package org.checkstyle.suppressionxpathfilter;
21+
22+
import java.io.File;
23+
import java.util.Arrays;
24+
import java.util.List;
25+
26+
import org.junit.jupiter.api.Test;
27+
28+
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29+
import com.puppycrawl.tools.checkstyle.checks.HexLiteralCaseCheck;
30+
31+
public class XpathRegressionHexLiteralCaseTest extends AbstractXpathTestSupport {
32+
33+
private final String checkName = HexLiteralCaseCheck.class.getSimpleName();
34+
35+
@Override
36+
protected String getCheckName() {
37+
return checkName;
38+
}
39+
40+
@Test
41+
public void testHexLiteralCaseCheck() throws Exception {
42+
final File fileProcess =
43+
new File(getPath("InputXpathHexLiteralCase.java"));
44+
final DefaultConfiguration config =
45+
createModuleConfig(HexLiteralCaseCheck.class);
46+
47+
final String[] expected = {
48+
"4:14: " + getCheckMessage(HexLiteralCaseCheck.class,
49+
HexLiteralCaseCheck.MSG_KEY),
50+
};
51+
final List<String> expectedXpathQueries = Arrays.asList(
52+
"/COMPILATION_UNIT/CLASS_DEF"
53+
+ "[./IDENT[@text='InputXpathHexLiteralCase']]"
54+
+ "/OBJBLOCK/VARIABLE_DEF"
55+
+ "[./IDENT[@text='i']]/ASSIGN/EXPR[./NUM_INT[@text='0xa']]",
56+
57+
"/COMPILATION_UNIT/CLASS_DEF"
58+
+ "[./IDENT[@text='InputXpathHexLiteralCase']]"
59+
+ "/OBJBLOCK/VARIABLE_DEF"
60+
+ "[./IDENT[@text='i']]/ASSIGN/EXPR/NUM_INT[@text='0xa']"
61+
);
62+
runVerifications(config, fileProcess, expected, expectedXpathQueries);
63+
}
64+
65+
@Test
66+
public void testLongHexLiteralCaseCheck() throws Exception {
67+
final File fileProcess =
68+
new File(getPath("InputXpathHexLiteralCaseLong.java"));
69+
final DefaultConfiguration config =
70+
createModuleConfig(HexLiteralCaseCheck.class);
71+
72+
final String[] expected = {
73+
"4:15: " + getCheckMessage(HexLiteralCaseCheck.class,
74+
HexLiteralCaseCheck.MSG_KEY),
75+
};
76+
final List<String> expectedXpathQueries = Arrays.asList(
77+
"/COMPILATION_UNIT/CLASS_DEF"
78+
+ "[./IDENT[@text='InputXpathHexLiteralCaseLong']]"
79+
+ "/OBJBLOCK/VARIABLE_DEF"
80+
+ "[./IDENT[@text='i']]/ASSIGN/EXPR[./NUM_LONG[@text='0x00efL']]",
81+
82+
"/COMPILATION_UNIT/CLASS_DEF"
83+
+ "[./IDENT[@text='InputXpathHexLiteralCaseLong']]"
84+
+ "/OBJBLOCK/VARIABLE_DEF"
85+
+ "[./IDENT[@text='i']]/ASSIGN/EXPR/NUM_LONG[@text='0x00efL']"
86+
);
87+
runVerifications(config, fileProcess, expected, expectedXpathQueries);
88+
}
89+
90+
@Test
91+
public void testHexLiteralCaseCheckTwo() throws Exception {
92+
final File fileProcess =
93+
new File(getPath("InputXpathHexLiteralCaseTwo.java"));
94+
final DefaultConfiguration config =
95+
createModuleConfig(HexLiteralCaseCheck.class);
96+
97+
final String[] expected = {
98+
"4:14: " + getCheckMessage(HexLiteralCaseCheck.class,
99+
HexLiteralCaseCheck.MSG_KEY),
100+
};
101+
final List<String> expectedXpathQueries = Arrays.asList(
102+
"/COMPILATION_UNIT/CLASS_DEF"
103+
+ "[./IDENT[@text='InputXpathHexLiteralCaseTwo']]"
104+
+ "/OBJBLOCK/VARIABLE_DEF"
105+
+ "[./IDENT[@text='a']]/ASSIGN/EXPR[./NUM_INT[@text='0xFa1']]",
106+
107+
"/COMPILATION_UNIT/CLASS_DEF"
108+
+ "[./IDENT[@text='InputXpathHexLiteralCaseTwo']]"
109+
+ "/OBJBLOCK/VARIABLE_DEF"
110+
+ "[./IDENT[@text='a']]/ASSIGN/EXPR/NUM_INT[@text='0xFa1']"
111+
);
112+
runVerifications(config, fileProcess, expected, expectedXpathQueries);
113+
}
114+
115+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.checkstyle.suppressionxpathfilter.hexliteralcase;
2+
3+
public class InputXpathHexLiteralCase {
4+
int i = 0xa;//warn
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.checkstyle.suppressionxpathfilter.hexliteralcase;
2+
3+
public class InputXpathHexLiteralCaseLong {
4+
long i = 0x00efL;//warn
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.checkstyle.suppressionxpathfilter.hexliteralcase;
2+
3+
public class InputXpathHexLiteralCaseTwo {
4+
int a = 0xFa1;//warn
5+
}
6+

src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,8 @@ private static void fillModulesFromChecksPackage() {
925925
BASE_PACKAGE + ".checks.UniquePropertiesCheck");
926926
NAME_TO_FULL_MODULE_NAME.put("UpperEllCheck",
927927
BASE_PACKAGE + ".checks.UpperEllCheck");
928+
NAME_TO_FULL_MODULE_NAME.put("HexLiteralCaseCheck",
929+
BASE_PACKAGE + ".checks.HexLiteralCaseCheck");
928930
}
929931

930932
/**

0 commit comments

Comments
 (0)