Skip to content

Commit e078b5c

Browse files
committed
Update gradle, more tests, update checkstyle max line length, optimization and other minor changes.
1 parent 899972a commit e078b5c

File tree

21 files changed

+290
-267
lines changed

21 files changed

+290
-267
lines changed

.config/checkstyle/checkstyle.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE module PUBLIC
33
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
44
"https://checkstyle.org/dtds/configuration_1_3.dtd">
@@ -42,7 +42,7 @@
4242

4343
<module name="LineLength">
4444
<property name="fileExtensions" value="java"/>
45-
<property name="max" value="155"/>
45+
<property name="max" value="205"/>
4646
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
4747
</module>
4848

@@ -129,14 +129,14 @@
129129
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
130130
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
131131
<message key="ws.notFollowed"
132-
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
132+
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks
133+
may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
133134
<message key="ws.notPreceded"
134135
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
135136
</module>
136137
<module name="OneStatementPerLine"/>
137138
<module name="MultipleVariableDeclarations"/>
138139
<module name="ArrayTypeStyle"/>
139-
<module name="MissingSwitchDefault"/>
140140
<module name="FallThrough"/>
141141
<module name="UpperEll"/>
142142
<module name="ModifierOrder"/>
@@ -186,7 +186,7 @@
186186
value="Type name ''{0}'' must match pattern ''{1}''."/>
187187
</module>
188188
<module name="MemberName">
189-
<property name="format" value="^[a-z][a-z0-9]{0,1}[a-zA-Z0-9]*$"/>
189+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
190190
<message key="name.invalidPattern"
191191
value="Member name ''{0}'' must match pattern ''{1}''."/>
192192
</module>
@@ -253,15 +253,15 @@
253253
</module>
254254
<module name="Indentation">
255255
<property name="basicOffset" value="2"/>
256-
<property name="braceAdjustment" value="2"/>
256+
<property name="braceAdjustment" value="0"/>
257257
<property name="caseIndent" value="2"/>
258258
<property name="throwsIndent" value="4"/>
259259
<property name="lineWrappingIndentation" value="4"/>
260260
<property name="arrayInitIndent" value="2"/>
261261
</module>
262262
<module name="AbbreviationAsWordInName">
263263
<property name="ignoreFinal" value="false"/>
264-
<property name="allowedAbbreviationLength" value="2"/>
264+
<property name="allowedAbbreviationLength" value="3"/>
265265
<property name="tokens"
266266
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
267267
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF,
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE suppressions PUBLIC
3-
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
4-
"http://checkstyle.org/dtds/suppressions_1_2.dtd">
3+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
4+
"http://checkstyle.org/dtds/suppressions_1_2.dtd">
55

66
<suppressions>
7-
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*" checks="SummaryJavadoc"/>
8-
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*" checks="MissingJavadocType"/>
9-
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*" checks="MissingJavadocMethod"/>
7+
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*" checks="SummaryJavadoc"/>
8+
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*" checks="MissingJavadocType"/>
9+
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*" checks="MissingJavadocMethod"/>
1010

11-
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*[\\/]YamlConfigTest.java" checks="TypeName"/>
12-
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*[\\/]YamlConfigTest.java" checks="MemberName"/>
13-
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*[\\/]YamlConfigTest.java" checks="AbbreviationAsWordInName"/>
11+
<suppress files=".*[\\/]net[\\/]elytrium[\\/].*[\\/]SerializerTest.java" checks="MemberName"/>
1412
</suppressions>

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
# These are Windows script files and should use crlf
88
*.bat text eol=crlf
99

10+
*.yml text eol=lf

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ Elytrium Java Serializer is uploaded to the Maven Central repository, so you can
4848
2) Create YamlWriter
4949
```java
5050
Settings settings = new Settings();
51-
YamlWriter writer = new YamlWriter(Files.newBufferedWriter(Path.of("/config.yml")));
51+
YamlWriter writer = new YamlWriter(Files.newBufferedWriter(Path.of("config.yml")));
5252
writer.writeNode(settings, null);
5353
```
5454
3) Create YamlReader
5555
```java
5656
Settings settings = new Settings();
57-
YamlReader reader = new YamlReader(Files.newBufferedReader(Path.of("./config.yml")));
57+
YamlReader reader = new YamlReader(Files.newBufferedReader(Path.of("config.yml")));
5858
reader.readSerializableObject(settings, Settings.class);
5959
```
6060

@@ -76,7 +76,7 @@ Elytrium Java Serializer is uploaded to the Maven Central repository, so you can
7676
2) Instantiate it.
7777
```java
7878
Settings settings = new Settings();
79-
settings.reload(Path.of("./config.yml"));
79+
settings.reload(Path.of("config.yml"));
8080
```
8181
3) Done!
8282

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ this.group = "net.elytrium"
1313
this.version = "1.0.3-SNAPSHOT"
1414

1515
compileJava() {
16-
sourceCompatibility = "17"
17-
targetCompatibility = "17"
16+
sourceCompatibility = JavaVersion.VERSION_17
17+
targetCompatibility = JavaVersion.VERSION_17
1818
options.getRelease().set(8)
1919

2020
options.setEncoding("UTF-8")
@@ -31,6 +31,8 @@ dependencies() {
3131
compileOnly("com.github.spotbugs:spotbugs-annotations:$spotbugsVersion")
3232
testCompileOnly("com.github.spotbugs:spotbugs-annotations:$spotbugsVersion")
3333

34+
testImplementation("it.unimi.dsi:fastutil-core:8.5.12")
35+
3436
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
3537
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
3638
}
@@ -51,7 +53,7 @@ checkstyle() {
5153
spotbugsMain() {
5254
reports.register("html") {
5355
required = true
54-
outputLocation.fileValue(file("$buildDir/reports/spotbugs/main/spotbugs.html"))
56+
outputLocation.value(layout.buildDirectory.file("reports/spotbugs/main/spotbugs.html"))
5557
stylesheet = "fancy-hist.xsl"
5658
}
5759
}

gradle/wrapper/gradle-wrapper.jar

346 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ done
8383
# This is normally unused
8484
# shellcheck disable=SC2034
8585
APP_BASE_NAME=${0##*/}
86-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
86+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
8788

8889
# Use the maximum available, or set MAX_FD != -1 to use that value.
8990
MAX_FD=maximum

src/main/java/net/elytrium/serializer/SerializerConfig.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,38 @@ public String toFieldName(String field, NameStyle overriddenFieldNameStyle, Name
112112
overriddenNodeNameStyle = this.nodeNameStyle;
113113
}
114114

115-
return overriddenFieldNameStyle == overriddenNodeNameStyle
116-
? field
117-
: overriddenFieldNameStyle.fromMacroCase(overriddenNodeNameStyle.toMacroCase(field));
115+
return overriddenFieldNameStyle == overriddenNodeNameStyle ? field : overriddenFieldNameStyle.fromMacroCase(overriddenNodeNameStyle.toMacroCase(field));
118116
}
119117

120-
public PlaceholderReplacer<?, ?> getAndCacheReplacer(Class<? extends PlaceholderReplacer<?, ?>> replacerClass) throws ReflectiveOperationException {
121-
PlaceholderReplacer<?, ?> replacer = this.cachedReplacers.get(replacerClass);
118+
public PlaceholderReplacer<?, ?> getAndCacheReplacer(Class<? extends PlaceholderReplacer<?, ?>> clazz) throws ReflectiveOperationException {
119+
PlaceholderReplacer<?, ?> replacer = this.cachedReplacers.get(clazz);
122120
if (replacer == null) {
123-
Constructor<? extends PlaceholderReplacer<?, ?>> constructor = replacerClass.getDeclaredConstructor();
121+
replacer = this.registeredReplacers.get(clazz);
122+
}
123+
124+
if (replacer == null) {
125+
Constructor<? extends PlaceholderReplacer<?, ?>> constructor = clazz.getDeclaredConstructor();
124126
constructor.setAccessible(true);
125127
replacer = constructor.newInstance();
126-
this.cachedReplacers.put(replacerClass, replacer);
128+
this.cachedReplacers.put(clazz, replacer);
127129
}
128130

129131
return replacer;
130132
}
131133

132134
@SuppressWarnings("unchecked")
133135
public <T, F> ClassSerializer<T, F> getAndCacheSerializer(Serializer serializer) throws ReflectiveOperationException {
134-
Class<? extends ClassSerializer<?, ?>> serializerClass = serializer.value();
135-
var configSerializer = (ClassSerializer<T, F>) this.cachedSerializers.get(serializerClass);
136+
Class<? extends ClassSerializer<?, ?>> clazz = serializer.value();
137+
var configSerializer = (ClassSerializer<T, F>) this.cachedSerializers.get(clazz);
138+
if (configSerializer == null) {
139+
configSerializer = (ClassSerializer<T, F>) this.registeredSerializers.get(clazz);
140+
}
141+
136142
if (configSerializer == null) {
137-
Constructor<? extends ClassSerializer<?, ?>> constructor = serializerClass.getDeclaredConstructor();
143+
Constructor<? extends ClassSerializer<?, ?>> constructor = clazz.getDeclaredConstructor();
138144
constructor.setAccessible(true);
139145
configSerializer = (ClassSerializer<T, F>) constructor.newInstance();
140-
this.cachedSerializers.put(serializerClass, configSerializer);
146+
this.cachedSerializers.put(clazz, configSerializer);
141147
}
142148

143149
return configSerializer;
@@ -250,16 +256,6 @@ public static class Builder {
250256
private boolean backupOnErrors = true;
251257
private int commentValueIndent = 0;
252258

253-
public Builder registerSerializer(Collection<ClassSerializer<?, ?>> serializers) {
254-
serializers.forEach(serializer -> this.registeredSerializers.put(serializer.getToType(), serializer));
255-
return this;
256-
}
257-
258-
public Builder registerSerializer(ClassSerializer<?, ?> serializer) {
259-
this.registeredSerializers.put(serializer.getToType(), serializer);
260-
return this;
261-
}
262-
263259
public Builder registerReplacer(Collection<PlaceholderReplacer<?, ?>> replacers) {
264260
replacers.forEach(this::registerReplacer);
265261
return this;
@@ -275,9 +271,7 @@ public Builder registerReplacer(PlaceholderReplacer<?, ?> serializer) {
275271
}
276272

277273
if (valueClass == null) {
278-
throw new IllegalStateException(
279-
"Failed to determine value class, please use SerializerConfig.Builder#registerPlaceholder(Class, PlaceholderReplacer)"
280-
);
274+
throw new IllegalStateException("Failed to determine value class, please use SerializerConfig.Builder#registerPlaceholder(Class, PlaceholderReplacer)");
281275
}
282276

283277
return this.registerReplacer(valueClass, serializer);
@@ -293,6 +287,16 @@ public Builder registerReplacer(Class<?> valueClass, PlaceholderReplacer<?, ?> s
293287
return this;
294288
}
295289

290+
public Builder registerSerializer(Collection<ClassSerializer<?, ?>> serializers) {
291+
serializers.forEach(this::registerSerializer);
292+
return this;
293+
}
294+
295+
public Builder registerSerializer(ClassSerializer<?, ?> serializer) {
296+
this.registeredSerializers.put(serializer.getToType(), serializer);
297+
return this;
298+
}
299+
296300
public Builder setFieldNameStyle(NameStyle fieldNameStyle) {
297301
this.fieldNameStyle = fieldNameStyle;
298302
return this;

src/main/java/net/elytrium/serializer/annotations/CollectionType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import java.util.Collection;
2626

2727
/**
28-
* Changes collection type
28+
* Specifies which collection type to use.
2929
*/
30-
@SuppressWarnings("rawtypes")
3130
@Documented
31+
@Target(ElementType.FIELD)
3232
@Retention(RetentionPolicy.RUNTIME)
33-
@Target({ElementType.FIELD})
33+
@SuppressWarnings("rawtypes")
3434
public @interface CollectionType {
3535

3636
/**

0 commit comments

Comments
 (0)