Skip to content

Commit 6c135f0

Browse files
authored
Merge pull request #72 from SentryMan/main
Sonar Fixes
2 parents ea0fd9d + 8279e0a commit 6c135f0

File tree

9 files changed

+61
-67
lines changed

9 files changed

+61
-67
lines changed

jsonb-generator/src/main/java/io/avaje/jsonb/generator/AdapterName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class AdapterName {
1919
} else {
2020
shortName = name;
2121
}
22-
this.adapterPackage = originPackage.equals("") ? "jsonb" : originPackage + ".jsonb";
22+
this.adapterPackage = "".equals(originPackage) ? "jsonb" : originPackage + ".jsonb";
2323
this.fullName = adapterPackage + "." + shortName + "JsonAdapter";
2424
}
2525

jsonb-generator/src/main/java/io/avaje/jsonb/generator/BeanReader.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ public BeanReader(TypeElement beanType, TypeElement mixInElement) {
6161
this.isRecord = isRecord(beanType);
6262
}
6363

64+
@SuppressWarnings("unchecked")
6465
boolean isRecord(TypeElement beanType) {
6566
try {
66-
final List<? extends Element> recordComponents =
67-
(List<? extends Element>) TypeElement.class
68-
.getMethod("getRecordComponents")
69-
.invoke(beanType);
67+
final var recordComponents =
68+
(List<? extends Element>)
69+
TypeElement.class.getMethod("getRecordComponents").invoke(beanType);
7070
return !recordComponents.isEmpty();
71-
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
71+
} catch (IllegalAccessException
72+
| InvocationTargetException
73+
| NoSuchMethodException
74+
| SecurityException e) {
7275
return false;
7376
}
7477
}
@@ -173,10 +176,8 @@ void writeFields(Append writer) {
173176
}
174177
Set<String> uniqueTypes = new HashSet<>();
175178
for (FieldReader allField : allFields) {
176-
if (allField.include() && !allField.isRaw()) {
177-
if (uniqueTypes.add(allField.adapterShortType())) {
178-
allField.writeField(writer);
179-
}
179+
if (allField.include() && !allField.isRaw() && uniqueTypes.add(allField.adapterShortType())) {
180+
allField.writeField(writer);
180181
}
181182
}
182183
writer.append(" private final PropertyNames names;").eol();
@@ -189,10 +190,8 @@ void writeConstructor(Append writer) {
189190
}
190191
Set<String> uniqueTypes = new HashSet<>();
191192
for (FieldReader allField : allFields) {
192-
if (allField.include() && !allField.isRaw()) {
193-
if (uniqueTypes.add(allField.adapterShortType())) {
194-
allField.writeConstructor(writer);
195-
}
193+
if (allField.include() && !allField.isRaw() && uniqueTypes.add(allField.adapterShortType())) {
194+
allField.writeConstructor(writer);
196195
}
197196
}
198197
writer.append(" this.names = jsonb.properties(");
@@ -318,11 +317,9 @@ void writeFromJson(Append writer) {
318317
}
319318
if (!directLoad) {
320319
writeJsonBuildResult(writer, varName);
321-
} else {
322-
if (unmappedField != null) {
323-
writer.append(" // unmappedField... ", varName).eol();
324-
unmappedField.writeFromJsonUnmapped(writer, varName);
325-
}
320+
} else if (unmappedField != null) {
321+
writer.append(" // unmappedField... ", varName).eol();
322+
unmappedField.writeFromJsonUnmapped(writer, varName);
326323
}
327324
writer.append(" return _$%s;", varName).eol();
328325
writer.append(" }").eol();
@@ -358,10 +355,8 @@ private void writeFromJsonWithSubTypes(Append writer, String varName) {
358355
}
359356

360357
String constructorParamName(String name) {
361-
if (unmappedField != null) {
362-
if (unmappedField.fieldName().equals(name)) {
363-
return "unmapped";
364-
}
358+
if ((unmappedField != null) && unmappedField.fieldName().equals(name)) {
359+
return "unmapped";
365360
}
366361
return "_val$" + name;
367362
}

jsonb-generator/src/main/java/io/avaje/jsonb/generator/FieldReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ String propertyName() {
134134
}
135135

136136
boolean typeObjectBooleanWithIsPrefix() {
137-
return nameHasIsPrefix() && genericType.topType().equals("java.lang.Boolean");
137+
return nameHasIsPrefix() && "java.lang.Boolean".equals(genericType.topType());
138138
}
139139

140140
boolean typeBooleanWithIsPrefix() {
141-
return nameHasIsPrefix() && (genericType.topType().equals("boolean") || genericType.topType().equals("java.lang.Boolean"));
141+
return nameHasIsPrefix() && ("boolean".equals(genericType.topType()) || "java.lang.Boolean".equals(genericType.topType()));
142142
}
143143

144144
private boolean nameHasIsPrefix() {

jsonb-generator/src/main/java/io/avaje/jsonb/generator/TypeReader.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,16 @@ private void matchFieldsToSetterOrConstructor() {
175175
}
176176

177177
private void matchFieldToSetter(FieldReader field) {
178-
if (!matchFieldToSetter2(field, false)) {
179-
if (!matchFieldToSetter2(field, true)) {
180-
if (!matchFieldToSetterByParam(field)) {
181-
if (!field.isPublicField()) {
182-
logError("Non public field " + baseType + " " + field.fieldName() + " with no matching setter or constructor?");
183-
}
184-
}
185-
}
178+
if (!matchFieldToSetter2(field, false)
179+
&& !matchFieldToSetter2(field, true)
180+
&& !matchFieldToSetterByParam(field)
181+
&& !field.isPublicField()) {
182+
logError(
183+
"Non public field "
184+
+ baseType
185+
+ " "
186+
+ field.fieldName()
187+
+ " with no matching setter or constructor?");
186188
}
187189
}
188190

@@ -238,16 +240,19 @@ private void matchFieldsToGetter() {
238240
}
239241

240242
private void matchFieldToGetter(FieldReader field) {
241-
if (!matchFieldToGetter2(field, false)) {
242-
if (!matchFieldToGetter2(field, true)) {
243-
if (!field.isPublicField()) {
244-
nonAccessibleField = true;
245-
if (hasJsonAnnotation) {
246-
logError("Non accessible field " + baseType + " " + field.fieldName() + " with no matching getter?");
247-
} else {
248-
logDebug("Non accessible field " + baseType + " " + field.fieldName());
249-
}
250-
}
243+
if (!matchFieldToGetter2(field, false)
244+
&& !matchFieldToGetter2(field, true)
245+
&& !field.isPublicField()) {
246+
nonAccessibleField = true;
247+
if (hasJsonAnnotation) {
248+
logError(
249+
"Non accessible field "
250+
+ baseType
251+
+ " "
252+
+ field.fieldName()
253+
+ " with no matching getter?");
254+
} else {
255+
logDebug("Non accessible field " + baseType + " " + field.fieldName());
251256
}
252257
}
253258
}
@@ -398,11 +403,9 @@ private void setFieldPositions() {
398403

399404
private void addSuperType(TypeElement element, TypeElement matchType) {
400405
String type = element.getQualifiedName().toString();
401-
if (!type.equals(JAVA_LANG_OBJECT)) {
402-
if (!GenericType.isGeneric(type)) {
403-
read(element);
404-
addSuperType(superOf(element), matchType);
405-
}
406+
if (!JAVA_LANG_OBJECT.equals(type) && !GenericType.isGeneric(type)) {
407+
read(element);
408+
addSuperType(superOf(element), matchType);
406409
}
407410
}
408411

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
@io.avaje.prism.GeneratePrisms({
2-
@GeneratePrism(value = io.avaje.jsonb.Json.class),
3-
@GeneratePrism(value = io.avaje.jsonb.Json.Import.class),
4-
@GeneratePrism(value = io.avaje.jsonb.Json.JsonAlias.class),
5-
@GeneratePrism(value = io.avaje.jsonb.Json.Ignore.class),
6-
@GeneratePrism(value = io.avaje.jsonb.Json.Property.class),
7-
@GeneratePrism(value = io.avaje.jsonb.Json.MixIn.class),
8-
@GeneratePrism(value = io.avaje.jsonb.Json.Raw.class),
9-
@GeneratePrism(value = io.avaje.jsonb.Json.SubTypes.class),
10-
@GeneratePrism(value = io.avaje.jsonb.Json.SubType.class),
11-
@GeneratePrism(value = io.avaje.jsonb.Json.Unmapped.class),
12-
@GeneratePrism(value = io.avaje.jsonb.Json.Value.class),
13-
@GeneratePrism(value = io.avaje.jsonb.spi.MetaData.class),
14-
@GeneratePrism(value = io.avaje.jsonb.spi.MetaData.Factory.class),
15-
})
1+
@GeneratePrism(value = io.avaje.jsonb.Json.class)
2+
@GeneratePrism(value = io.avaje.jsonb.Json.Import.class)
3+
@GeneratePrism(value = io.avaje.jsonb.Json.JsonAlias.class)
4+
@GeneratePrism(value = io.avaje.jsonb.Json.Ignore.class)
5+
@GeneratePrism(value = io.avaje.jsonb.Json.Property.class)
6+
@GeneratePrism(value = io.avaje.jsonb.Json.MixIn.class)
7+
@GeneratePrism(value = io.avaje.jsonb.Json.Raw.class)
8+
@GeneratePrism(value = io.avaje.jsonb.Json.SubTypes.class)
9+
@GeneratePrism(value = io.avaje.jsonb.Json.SubType.class)
10+
@GeneratePrism(value = io.avaje.jsonb.Json.Unmapped.class)
11+
@GeneratePrism(value = io.avaje.jsonb.Json.Value.class)
12+
@GeneratePrism(value = io.avaje.jsonb.spi.MetaData.class)
13+
@GeneratePrism(value = io.avaje.jsonb.spi.MetaData.Factory.class)
1614
package io.avaje.jsonb.generator;
1715

1816
import io.avaje.prism.GeneratePrism;

jsonb/src/main/java/io/avaje/jsonb/core/CollectionAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import io.avaje.jsonb.spi.ViewBuilder;
2020
import io.avaje.jsonb.spi.ViewBuilderAware;
2121

22-
import java.io.IOException;
2322
import java.lang.invoke.MethodHandle;
2423
import java.lang.reflect.Type;
2524
import java.util.*;

jsonb/src/main/java/io/avaje/jsonb/core/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public final class Util {
2828

29-
static final Type[] EMPTY_TYPE_ARRAY = new Type[]{};
29+
static final Type[] EMPTY_TYPE_ARRAY = {};
3030

3131
private Util() {
3232
}

jsonb/src/main/java/io/avaje/jsonb/stream/Base64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static int findEnd(final byte[] sArr, final int start) {
129129
return sArr.length;
130130
}
131131

132-
private final static byte[] EMPTY_ARRAY = new byte[0];
132+
private final static byte[] EMPTY_ARRAY = {};
133133

134134
static byte[] decodeFast(final byte[] sArr, final int start, final int end) {
135135
// Check special case

jsonb/src/main/java/io/avaje/jsonb/stream/WriterOutputStream.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.nio.charset.Charset;
2525
import java.nio.charset.CharsetDecoder;
2626
import java.nio.charset.CoderResult;
27-
import java.nio.charset.CodingErrorAction;
2827

2928
/**
3029
* {@link OutputStream} implementation that transforms a byte stream to a

0 commit comments

Comments
 (0)