Skip to content

Commit 20941f3

Browse files
committed
Checkstyle: Fine-tune checks, fix some violations, add IntelliJ Checkstyle plugin config
- Fine-tune some of the checks to be more generally applicable - Fix violations except in code that is planned to be changed soon - Commit IntelliJ's checkstyle-idea.xml plugin config so that the right file and Checkstyle version are used out of the box
1 parent 2c1c08e commit 20941f3

12 files changed

+68
-9
lines changed

.checkstyle.xml

+8-6
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,6 @@
214214
<module name="TypeName" />
215215

216216
<!-- Regexp -->
217-
<module name="Regexp">
218-
<property name="format" value="System\.out"/>
219-
<property name="illegalPattern" value="true"/>
220-
</module>
221217

222218
<!-- Size violations -->
223219

@@ -228,8 +224,14 @@
228224
<module name="GenericWhitespace" />
229225
<module name="MethodParamPad" />
230226
<module name="NoLineWrap" />
231-
<module name="NoWhitespaceAfter" />
232-
<module name="NoWhitespaceBefore" />
227+
<module name="NoWhitespaceAfter">
228+
<!-- Override to exclude ARRAY_INIT and to add LITERAL_SYNCHRONIZED, METHOD_REF -->
229+
<property name="tokens" value="AT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, ARRAY_DECLARATOR, INDEX_OP, LITERAL_SYNCHRONIZED, METHOD_REF" />
230+
</module>
231+
<module name="NoWhitespaceBefore">
232+
<!-- Override to exclude ELLIPSIS and to add METHOD_REF -->
233+
<property name="tokens" value="COMMA, SEMI, POST_INC, POST_DEC, LABELED_STAT, METHOD_REF" />
234+
</module>
233235
<!-- Checkstyle 8.45: <module name="NoWhitespaceBeforeCaseDefaultColon" /> -->
234236
<module name="OperatorWrap" />
235237
<module name="ParenPad" />

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ hs_err_pid*
1818

1919
# Ignore IDEA directory
2020
.idea/*
21+
!.idea/vcs.xml
22+
!.idea/checkstyle-idea.xml
2123

2224
# File-based project format:
2325
*.ipr

.idea/checkstyle-idea.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void add(@NotNull Property<?> property) {
3838
final String lastElement = pathElements[pathElements.length - 1];
3939
if (mapForProperty.containsKey(lastElement)) {
4040
throw new ConfigMeException("Path at '" + property.getPath() + "' already exists");
41-
} else if (pathElements.length > 1 && lastElement.equals("")) {
41+
} else if (pathElements.length > 1 && "".equals(lastElement)) {
4242
throwExceptionForMalformedPath(property.getPath());
4343
}
4444
mapForProperty.put(lastElement, property);

src/main/java/ch/jalu/configme/properties/ArrayProperty.java

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
import java.util.Objects;
1111
import java.util.function.IntFunction;
1212

13+
/**
14+
* Property whose value is an array of a given type.
15+
*
16+
* @param <T> the type of the elements in the array
17+
*/
1318
public class ArrayProperty<T> extends BaseProperty<T[]> {
1419

1520
private final PropertyType<T> type;

src/main/java/ch/jalu/configme/properties/BeanProperty.java

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import ch.jalu.typeresolver.TypeInfo;
88
import org.jetbrains.annotations.NotNull;
99

10+
/**
11+
* Property whose value is a bean class.
12+
*
13+
* @param <T> the bean type
14+
*/
1015
public class BeanProperty<T> extends TypeBasedProperty<T> {
1116

1217
public BeanProperty(@NotNull Class<T> beanType, @NotNull String path, @NotNull T defaultValue) {

src/main/java/ch/jalu/configme/properties/OptionalProperty.java

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* <p>
1313
* Wraps another property with an {@link Optional}: if a property is not present in the property resource,
1414
* {@link Optional#empty} is returned.
15+
*
16+
* @param <T> the type of value
1517
*/
1618
public class OptionalProperty<T> implements Property<Optional<T>> {
1719

src/main/java/ch/jalu/configme/properties/types/BeanPropertyType.java

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import org.jetbrains.annotations.NotNull;
88
import org.jetbrains.annotations.Nullable;
99

10+
/**
11+
* Property type that maps values to a specific bean class.
12+
*
13+
* @param <B> the bean type
14+
*/
1015
public class BeanPropertyType<B> implements PropertyType<B> {
1116

1217
private final TypeInfo beanType;

src/main/java/ch/jalu/configme/resource/PropertyReader.java

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import java.util.List;
66
import java.util.Set;
77

8+
/**
9+
* A property reader provides values from a resource (e.g. a YAML file) based on whose data the values of properties
10+
* are determined. Property readers typically provide a snapshot of the file's contents, i.e. their values are not
11+
* updated if the underlying file changes.
12+
*/
813
public interface PropertyReader {
914

1015
/**

src/main/java/ch/jalu/configme/resource/YamlFileResource.java

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import java.util.stream.Collectors;
2626
import java.util.stream.Stream;
2727

28+
/**
29+
* Property resource based on a YAML file.
30+
*/
2831
public class YamlFileResource implements PropertyResource {
2932

3033
private final Path path;

src/main/java/ch/jalu/configme/resource/YamlFileResourceOptions.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import java.nio.charset.StandardCharsets;
99
import java.util.function.ToIntFunction;
1010

11+
/**
12+
* Options for {@link YamlFileResource} to configure reading and writing YAML.
13+
*/
1114
public class YamlFileResourceOptions {
1215

1316
private final @NotNull Charset charset;
@@ -49,11 +52,16 @@ public int getIndentationSize() {
4952
return numberOfLinesBeforeFunction;
5053
}
5154

55+
/**
56+
* Builder to create YAML file resource options.
57+
*/
5258
public static class Builder {
5359

60+
private static final int DEFAULT_INDENTATION_SIZE = 4;
61+
5462
private Charset charset;
5563
private ToIntFunction<PathElement> numberOfLinesBeforeFunction;
56-
private int indentationSize = 4;
64+
private int indentationSize = DEFAULT_INDENTATION_SIZE;
5765

5866
public @NotNull Builder charset(@Nullable Charset charset) {
5967
this.charset = charset;

src/main/java/ch/jalu/configme/utils/SettingsHolderClassValidator.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
public class SettingsHolderClassValidator {
3434

35+
private static final int DEFAULT_MAX_COMMENTS_LENGTH = 90;
36+
3537
// ---- Main validation methods (with default settings)
3638

3739
/**
@@ -62,7 +64,7 @@ public void validate(@NotNull Iterable<Class<? extends SettingsHolder>> settingH
6264
// no properties have overlapping paths
6365
ConfigurationData configurationData = createConfigurationData(settingHolders);
6466
validateHasCommentOnEveryProperty(configurationData, null);
65-
validateCommentLengthsAreWithinBounds(configurationData, null, 90);
67+
validateCommentLengthsAreWithinBounds(configurationData, null, DEFAULT_MAX_COMMENTS_LENGTH);
6668
validateHasAllEnumEntriesInComment(configurationData, null);
6769
}
6870

0 commit comments

Comments
 (0)