Skip to content

Commit f50a01f

Browse files
Anmol202005romani
authored andcommitted
Issue #132: renamed CheckstyleCheck and CheckstyleCheckInstance
1 parent a22e41a commit f50a01f

File tree

12 files changed

+106
-106
lines changed

12 files changed

+106
-106
lines changed

config/pitest-suppressions.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,19 @@
499499
<mutation unstable="false">
500500
<sourceFile>Header.java</sourceFile>
501501
<mutatedClass>org.checkstyle.autofix.recipe.Header</mutatedClass>
502-
<mutatedMethod>toLfLineEnding</mutatedMethod>
503-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
504-
<description>replaced call to java/lang/String::replaceAll with receiver</description>
505-
<lineContent>return text.replaceAll(&quot;(?x)\\\\r(?=\\\\n)|\\r(?=\\n)&quot;, &quot;&quot;);</lineContent>
502+
<mutatedMethod>getDisplayName</mutatedMethod>
503+
<mutator>org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator</mutator>
504+
<description>replaced return value with &quot;&quot; for org/checkstyle/autofix/recipe/Header::getDisplayName</description>
505+
<lineContent>return &quot;Header recipe&quot;;</lineContent>
506506
</mutation>
507507

508508
<mutation unstable="false">
509509
<sourceFile>Header.java</sourceFile>
510510
<mutatedClass>org.checkstyle.autofix.recipe.Header</mutatedClass>
511-
<mutatedMethod>getDisplayName</mutatedMethod>
512-
<mutator>org.pitest.mutationtest.engine.gregor.mutators.returns.EmptyObjectReturnValsMutator</mutator>
513-
<description>replaced return value with &quot;&quot; for org/checkstyle/autofix/recipe/Header::getDisplayName</description>
514-
<lineContent>return &quot;Header recipe&quot;;</lineContent>
511+
<mutatedMethod>toLfLineEnding</mutatedMethod>
512+
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
513+
<description>replaced call to java/lang/String::replaceAll with receiver</description>
514+
<lineContent>return text.replaceAll(&quot;(?x)\\\\r(?=\\\\n)|\\r(?=\\n)&quot;, &quot;&quot;);</lineContent>
515515
</mutation>
516516

517517
<mutation unstable="false">
@@ -1330,7 +1330,7 @@
13301330
<mutatedMethod>parseErrorTag</mutatedMethod>
13311331
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
13321332
<description>removed call to java/util/Optional::empty</description>
1333-
<lineContent>Optional&lt;CheckstyleCheck&gt; check = Optional.empty();</lineContent>
1333+
<lineContent>Optional&lt;CheckFullName&gt; checkName = Optional.empty();</lineContent>
13341334
</mutation>
13351335

13361336
<mutation unstable="false">
@@ -1339,7 +1339,7 @@
13391339
<mutatedMethod>parseErrorTag</mutatedMethod>
13401340
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF</mutator>
13411341
<description>removed conditional - replaced equality check with true</description>
1342-
<lineContent>if (check.isPresent()) {</lineContent>
1342+
<lineContent>if (checkName.isPresent()) {</lineContent>
13431343
</mutation>
13441344

13451345
<mutation unstable="false">
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
///////////////////////////////////////////////////////////////////////////////////////////////
2+
// checkstyle-openrewrite-recipes: Automatically fix Checkstyle violations with OpenRewrite.
3+
// Copyright (C) 2025 The Checkstyle OpenRewrite Recipes Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
///////////////////////////////////////////////////////////////////////////////////////////////
17+
18+
package org.checkstyle.autofix;
19+
20+
import java.util.Arrays;
21+
import java.util.Optional;
22+
23+
public enum CheckFullName {
24+
FINAL_LOCAL_VARIABLE("com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck"),
25+
HEADER("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"),
26+
NEWLINE_AT_END_OF_FILE("com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"),
27+
UPPER_ELL("com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"),
28+
HEX_LITERAL_CASE("com.puppycrawl.tools.checkstyle.checks.HexLiteralCaseCheck"),
29+
REDUNDANT_IMPORT("com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck");
30+
31+
private final String id;
32+
33+
CheckFullName(String id) {
34+
this.id = id;
35+
}
36+
37+
public String getId() {
38+
return id;
39+
}
40+
41+
public static Optional<CheckFullName> fromSource(String source) {
42+
return Arrays.stream(values())
43+
.filter(check -> check.getId().contains(source.split("#")[0]))
44+
.findFirst();
45+
}
46+
}

src/main/java/org/checkstyle/autofix/CheckstyleAutoFix.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public List<Recipe> getRecipeList() {
8888
final ReportParser reportParser = createReportParser(getViolationReportPath());
8989
final List<CheckstyleViolation> violations = reportParser
9090
.parse(Path.of(getViolationReportPath()));
91-
final Map<CheckstyleCheckInstance,
91+
final Map<CheckstyleCheck,
9292
CheckConfiguration> configuration = loadCheckstyleConfiguration();
9393

9494
return CheckstyleRecipeRegistry.getRecipes(violations, configuration);
@@ -108,7 +108,7 @@ else if (path.endsWith(".sarif") || path.endsWith(".sarif.json")) {
108108
return result;
109109
}
110110

111-
private Map<CheckstyleCheckInstance, CheckConfiguration> loadCheckstyleConfiguration() {
111+
private Map<CheckstyleCheck, CheckConfiguration> loadCheckstyleConfiguration() {
112112
return ConfigurationLoader.loadConfiguration(getConfigurationPath(), getPropertiesPath());
113113
}
114114
}

src/main/java/org/checkstyle/autofix/CheckstyleCheck.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,8 @@
1717

1818
package org.checkstyle.autofix;
1919

20-
import java.util.Arrays;
21-
import java.util.Optional;
22-
23-
public enum CheckstyleCheck {
24-
FINAL_LOCAL_VARIABLE("com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck"),
25-
HEADER("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"),
26-
NEWLINE_AT_END_OF_FILE("com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"),
27-
UPPER_ELL("com.puppycrawl.tools.checkstyle.checks.UpperEllCheck"),
28-
HEX_LITERAL_CASE("com.puppycrawl.tools.checkstyle.checks.HexLiteralCaseCheck"),
29-
REDUNDANT_IMPORT("com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck");
30-
31-
private final String id;
32-
33-
CheckstyleCheck(String id) {
34-
this.id = id;
35-
}
36-
37-
public String getId() {
38-
return id;
39-
}
40-
41-
public static Optional<CheckstyleCheck> fromSource(String source) {
42-
return Arrays.stream(values())
43-
.filter(check -> check.getId().contains(source.split("#")[0]))
44-
.findFirst();
45-
}
20+
public record CheckstyleCheck(
21+
CheckFullName checkName,
22+
String id
23+
) {
4624
}

src/main/java/org/checkstyle/autofix/CheckstyleCheckInstance.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/main/java/org/checkstyle/autofix/CheckstyleRecipeRegistry.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@
3737

3838
public final class CheckstyleRecipeRegistry {
3939

40-
private static final EnumMap<CheckstyleCheck, Function<List<CheckstyleViolation>,
41-
Recipe>> RECIPE_MAP = new EnumMap<>(CheckstyleCheck.class);
40+
private static final EnumMap<CheckFullName, Function<List<CheckstyleViolation>,
41+
Recipe>> RECIPE_MAP = new EnumMap<>(CheckFullName.class);
4242

43-
private static final EnumMap<CheckstyleCheck, BiFunction<List<CheckstyleViolation>,
43+
private static final EnumMap<CheckFullName, BiFunction<List<CheckstyleViolation>,
4444
CheckConfiguration, Recipe>> RECIPE_MAP_WITH_CONFIG =
45-
new EnumMap<>(CheckstyleCheck.class);
45+
new EnumMap<>(CheckFullName.class);
4646

4747
static {
48-
RECIPE_MAP.put(CheckstyleCheck.UPPER_ELL, UpperEll::new);
49-
RECIPE_MAP.put(CheckstyleCheck.HEX_LITERAL_CASE, HexLiteralCase::new);
50-
RECIPE_MAP.put(CheckstyleCheck.FINAL_LOCAL_VARIABLE, FinalLocalVariable::new);
51-
RECIPE_MAP_WITH_CONFIG.put(CheckstyleCheck.HEADER, Header::new);
52-
RECIPE_MAP_WITH_CONFIG.put(CheckstyleCheck.NEWLINE_AT_END_OF_FILE, NewlineAtEndOfFile::new);
53-
RECIPE_MAP.put(CheckstyleCheck.REDUNDANT_IMPORT, RedundantImport::new);
48+
RECIPE_MAP.put(CheckFullName.UPPER_ELL, UpperEll::new);
49+
RECIPE_MAP.put(CheckFullName.HEX_LITERAL_CASE, HexLiteralCase::new);
50+
RECIPE_MAP.put(CheckFullName.FINAL_LOCAL_VARIABLE, FinalLocalVariable::new);
51+
RECIPE_MAP_WITH_CONFIG.put(CheckFullName.HEADER, Header::new);
52+
RECIPE_MAP_WITH_CONFIG.put(CheckFullName.NEWLINE_AT_END_OF_FILE, NewlineAtEndOfFile::new);
53+
RECIPE_MAP.put(CheckFullName.REDUNDANT_IMPORT, RedundantImport::new);
5454
}
5555

5656
private CheckstyleRecipeRegistry() {
@@ -67,7 +67,7 @@ private CheckstyleRecipeRegistry() {
6767
* @return a list of generated Recipe objects
6868
*/
6969
public static List<Recipe> getRecipes(List<CheckstyleViolation> violations,
70-
Map<CheckstyleCheckInstance, CheckConfiguration> config) {
70+
Map<CheckstyleCheck, CheckConfiguration> config) {
7171
return violations.stream()
7272
.collect(Collectors.groupingBy(CheckstyleViolation::getSource))
7373
.entrySet()
@@ -84,16 +84,16 @@ private static Recipe createRecipe(List<CheckstyleViolation> violations,
8484
Recipe result = null;
8585
if (checkConfig != null) {
8686

87-
final CheckstyleCheck check = checkConfig.getCheck();
87+
final CheckFullName checkName = checkConfig.getCheckName();
8888

8989
final BiFunction<List<CheckstyleViolation>, CheckConfiguration,
90-
Recipe> configRecipeFactory = RECIPE_MAP_WITH_CONFIG.get(check);
90+
Recipe> configRecipeFactory = RECIPE_MAP_WITH_CONFIG.get(checkName);
9191

9292
if (configRecipeFactory != null) {
9393
result = configRecipeFactory.apply(violations, checkConfig);
9494
}
9595
else {
96-
result = RECIPE_MAP.get(check).apply(violations);
96+
result = RECIPE_MAP.get(checkName).apply(violations);
9797
}
9898
}
9999
return result;

src/main/java/org/checkstyle/autofix/parser/CheckConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23-
import org.checkstyle.autofix.CheckstyleCheck;
23+
import org.checkstyle.autofix.CheckFullName;
2424

2525
public final class CheckConfiguration {
26-
private final CheckstyleCheck check;
26+
private final CheckFullName checkName;
2727
private final Map<String, String> globalProperties;
2828
private final Map<String, String> properties;
2929

30-
public CheckConfiguration(CheckstyleCheck name,
30+
public CheckConfiguration(CheckFullName checkName,
3131
Map<String, String> globalProperties,
3232
Map<String, String> properties) {
33-
this.check = name;
33+
this.checkName = checkName;
3434
this.globalProperties = new HashMap<>(globalProperties);
3535
this.properties = new HashMap<>(properties);
3636
}
3737

38-
public CheckstyleCheck getCheck() {
39-
return check;
38+
public CheckFullName getCheckName() {
39+
return checkName;
4040
}
4141

4242
public String getProperty(String key) {

src/main/java/org/checkstyle/autofix/parser/CheckstyleViolation.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.nio.file.Path;
2121

22-
import org.checkstyle.autofix.CheckstyleCheckInstance;
22+
import org.checkstyle.autofix.CheckstyleCheck;
2323

2424
public final class CheckstyleViolation {
2525

@@ -29,14 +29,14 @@ public final class CheckstyleViolation {
2929

3030
private final String severity;
3131

32-
private final CheckstyleCheckInstance source;
32+
private final CheckstyleCheck source;
3333

3434
private final String message;
3535

3636
private final Path filePath;
3737

3838
public CheckstyleViolation(int line, int column, String severity,
39-
CheckstyleCheckInstance source, String message, Path filePath) {
39+
CheckstyleCheck source, String message, Path filePath) {
4040
this.line = line;
4141
this.column = column;
4242
this.severity = severity;
@@ -46,7 +46,7 @@ public CheckstyleViolation(int line, int column, String severity,
4646
}
4747

4848
public CheckstyleViolation(int line, String severity,
49-
CheckstyleCheckInstance source, String message, Path filePath) {
49+
CheckstyleCheck source, String message, Path filePath) {
5050
this(line, -1, severity, source, message, filePath);
5151
}
5252

@@ -58,7 +58,7 @@ public Integer getColumn() {
5858
return column;
5959
}
6060

61-
public CheckstyleCheckInstance getSource() {
61+
public CheckstyleCheck getSource() {
6262
return source;
6363
}
6464

src/main/java/org/checkstyle/autofix/parser/ConfigurationLoader.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.util.Optional;
2525
import java.util.Properties;
2626

27+
import org.checkstyle.autofix.CheckFullName;
2728
import org.checkstyle.autofix.CheckstyleCheck;
28-
import org.checkstyle.autofix.CheckstyleCheckInstance;
2929

3030
import com.puppycrawl.tools.checkstyle.PropertiesExpander;
3131
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
@@ -37,15 +37,15 @@ private ConfigurationLoader() {
3737
// utility class
3838
}
3939

40-
public static Map<CheckstyleCheckInstance,
40+
public static Map<CheckstyleCheck,
4141
CheckConfiguration> mapConfiguration(Configuration config) {
4242

43-
final Map<CheckstyleCheckInstance, CheckConfiguration> result = new HashMap<>();
43+
final Map<CheckstyleCheck, CheckConfiguration> result = new HashMap<>();
4444
final Map<String, String> inherited = getProperties(config);
45-
final Optional<CheckstyleCheck> module = CheckstyleCheck.fromSource(config.getName());
45+
final Optional<CheckFullName> checkName = CheckFullName.fromSource(config.getName());
4646

47-
module.ifPresent(checkstyleCheck -> {
48-
result.put(new CheckstyleCheckInstance(checkstyleCheck, inherited.get("id")),
47+
checkName.ifPresent(checkstyleCheck -> {
48+
result.put(new CheckstyleCheck(checkstyleCheck, inherited.get("id")),
4949
new CheckConfiguration(checkstyleCheck, new HashMap<>(), inherited));
5050
});
5151

@@ -72,7 +72,7 @@ private static Map<String, String> getProperties(Configuration config) {
7272
return props;
7373
}
7474

75-
public static Map<CheckstyleCheckInstance, CheckConfiguration> loadConfiguration(
75+
public static Map<CheckstyleCheck, CheckConfiguration> loadConfiguration(
7676
String checkstyleConfigurationPath, String propFile) {
7777
Properties props = new Properties();
7878
if (propFile == null) {

src/main/java/org/checkstyle/autofix/parser/SarifReportParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import java.util.List;
2626
import java.util.Optional;
2727

28+
import org.checkstyle.autofix.CheckFullName;
2829
import org.checkstyle.autofix.CheckstyleCheck;
29-
import org.checkstyle.autofix.CheckstyleCheckInstance;
3030

3131
import de.jcup.sarif_2_1_0.SarifSchema210ImportExportSupport;
3232
import de.jcup.sarif_2_1_0.model.PhysicalLocation;
@@ -58,22 +58,22 @@ public List<CheckstyleViolation> parse(Path reportPath) {
5858
for (final Run run: report.getRuns()) {
5959
if (run.getResults() != null) {
6060
run.getResults().forEach(resultEntry -> {
61-
CheckstyleCheck.fromSource(resultEntry.getRuleId()).ifPresent(
62-
check -> {
61+
CheckFullName.fromSource(resultEntry.getRuleId()).ifPresent(
62+
checkName -> {
6363
final String id = Optional.of(resultEntry.getRuleId())
6464
.filter(src -> src.contains("#"))
6565
.map(src -> src.substring(src.indexOf('#') + 1))
6666
.orElse(null);
6767
result.add(createViolation(new
68-
CheckstyleCheckInstance(check, id), resultEntry));
68+
CheckstyleCheck(checkName, id), resultEntry));
6969
}); }
7070
);
7171
}
7272
}
7373
return result;
7474
}
7575

76-
private CheckstyleViolation createViolation(CheckstyleCheckInstance check, Result result) {
76+
private CheckstyleViolation createViolation(CheckstyleCheck check, Result result) {
7777
final String severity = result.getLevel().name();
7878
final String message = result.getMessage().getText();
7979
final PhysicalLocation location = result.getLocations().get(0).getPhysicalLocation();

0 commit comments

Comments
 (0)