Skip to content

Commit 940c235

Browse files
committed
support for jspecify @nullable annotations with TYPE_USE
1 parent eb734d0 commit 940c235

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ dependencies {
8989
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
9090
testImplementation 'org.assertj:assertj-core:3.15.0'
9191
testImplementation 'org.jetbrains:annotations:20.1.0'
92+
testImplementation 'org.jspecify:jspecify:1.0.0'
9293
testImplementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.1'
9394

9495
implementation 'com.beust:jcommander:1.78'

src/main/java/jvm2dts/Converter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ else if (annotationName.equals("JsonProperty")) {
139139

140140
fieldBuffer.append(propertyName);
141141

142-
if (!nonRuntimeAnnotations.isEmpty()) {
143-
for (var annotation : nonRuntimeAnnotations.getOrDefault(method.getName(), emptyList()))
144-
if (annotation.contains("Nullable;")) fieldBuffer.append("?");
142+
if (nonRuntimeAnnotations.getOrDefault(method.getName(), emptyList()).stream().anyMatch(a -> a.contains("Nullable;")) ||
143+
stream(method.getAnnotatedReturnType().getAnnotations()).anyMatch(a -> a.annotationType().getSimpleName().equals("Nullable"))) {
144+
fieldBuffer.append("?");
145145
}
146146

147147
var type = method.getReturnType();

src/test/java/jvm2dts/ClassConverterTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnore;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import org.jetbrains.annotations.Nullable;
65
import org.junit.jupiter.api.Test;
76

87
import java.lang.annotation.Retention;
@@ -54,7 +53,7 @@ void wrapperTypes() {
5453
"double?: number; " +
5554
"float?: number; " +
5655
"integer: number; " +
57-
"long: number; " +
56+
"long?: number; " +
5857
"optional?: string;" +
5958
"}");
6059
}
@@ -111,9 +110,9 @@ interface WrapperTypes {
111110
Byte getAByte();
112111
Short getAShort();
113112
Integer getInteger();
114-
Long getLong();
115113
Boolean isBoolean();
116-
@Nullable Float getFloat();
114+
@org.jspecify.annotations.Nullable Long getLong();
115+
@org.jetbrains.annotations.Nullable Float getFloat();
117116
@ClassConverterTest.Nullable Double getDouble();
118117
Optional<String> getOptional();
119118
}

0 commit comments

Comments
 (0)