[*] Migrate to jspecify annotations

This commit is contained in:
2025-04-24 21:52:33 +02:00
parent cef5227bf1
commit c97f711c0b
100 changed files with 553 additions and 369 deletions

View File

@@ -3,7 +3,7 @@ package de.siphalor.tweed5.data.hjson;
import de.siphalor.tweed5.dataapi.api.TweedDataReadException;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;
import java.io.IOException;
import java.io.Reader;
@@ -58,8 +58,7 @@ public class HjsonLexer {
}
}
@Nullable
private HjsonLexerToken.Type getTerminalTokenType(int codePoint) {
private HjsonLexerToken.@Nullable Type getTerminalTokenType(int codePoint) {
switch (codePoint) {
case -1: return HjsonLexerToken.Type.EOF;
case '[': return HjsonLexerToken.Type.BRACKET_OPEN;
@@ -78,8 +77,7 @@ public class HjsonLexer {
return new HjsonLexerToken(tokenType, position, position, null);
}
@Nullable
private HjsonLexerToken tryReadQuotedString(int codePoint) throws TweedDataReadException {
private @Nullable HjsonLexerToken tryReadQuotedString(int codePoint) throws TweedDataReadException {
if (codePoint == '"') {
return readJsonQuotedString('"');
} else if (codePoint == '\'') {

View File

@@ -3,7 +3,7 @@ package de.siphalor.tweed5.data.hjson;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;
@ApiStatus.Internal
@Value
@@ -12,12 +12,10 @@ public class HjsonLexerToken {
HjsonReadPosition begin;
HjsonReadPosition end;
@EqualsAndHashCode.Exclude
@Nullable
CharSequence content;
@Nullable CharSequence content;
@EqualsAndHashCode.Include
@Nullable
public String contentString() {
public @Nullable String contentString() {
return content == null ? null : content.toString();
}

View File

@@ -1,6 +1,8 @@
package de.siphalor.tweed5.data.hjson;
import de.siphalor.tweed5.dataapi.api.*;
import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;
import java.util.*;
import java.util.stream.Collectors;
@@ -10,9 +12,9 @@ public class HjsonReader implements TweedDataReader {
private final Deque<Context> contexts;
private State state = State.BEFORE_VALUE;
private HjsonLexerToken peekedLexerToken;
private @Nullable HjsonLexerToken peekedLexerToken;
private TweedDataToken peekedToken;
private @Nullable TweedDataToken peekedToken;
public HjsonReader(HjsonLexer lexer) {
this.lexer = lexer;
@@ -204,6 +206,7 @@ public class HjsonReader implements TweedDataReader {
};
}
@NullUnmarked
private TweedDataToken createNumberToken(HjsonLexerToken lexerToken) {
assert lexerToken.content() != null;
return new TweedDataToken() {
@@ -318,7 +321,7 @@ public class HjsonReader implements TweedDataReader {
tryLong = 0L;
boolean inFraction = false;
do {
tryLong = Math.addExact(Math.multiplyExact(tryLong, 10L), (long) (codePoint - '0'));
tryLong = Math.addExact(Math.multiplyExact(tryLong, 10L), codePoint - '0');
if (inFraction) {
fractionDigits++;
}
@@ -513,7 +516,7 @@ public class HjsonReader implements TweedDataReader {
@Override
public String readAsString() throws TweedDataReadException {
if (lexerToken.type() == HjsonLexerToken.Type.QUOTELESS_STRING || lexerToken.type() == HjsonLexerToken.Type.MULTILINE_STRING) {
return lexerToken.contentString();
return Objects.requireNonNull(lexerToken.contentString());
} else if (lexerToken.type() == HjsonLexerToken.Type.JSON_STRING) {
return readJsonString(lexerToken.content());
}
@@ -623,6 +626,7 @@ public class HjsonReader implements TweedDataReader {
}
private Context currentContext() {
assert contexts.peek() != null;
return contexts.peek();
}

View File

@@ -4,19 +4,17 @@ import de.siphalor.tweed5.dataapi.api.TweedDataReader;
import de.siphalor.tweed5.dataapi.api.TweedDataVisitor;
import de.siphalor.tweed5.dataapi.api.TweedSerde;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
public class HjsonSerde implements TweedSerde {
@Override
public TweedDataReader createReader(InputStream inputStream) {
return null;
return new HjsonReader(new HjsonLexer(new InputStreamReader(inputStream)));
}
@Override
public TweedDataVisitor createWriter(OutputStream outputStream) throws IOException {
return null;
return new HjsonWriter(new OutputStreamWriter(outputStream), new HjsonWriter.Options());
}
@Override

View File

@@ -3,7 +3,6 @@ package de.siphalor.tweed5.data.hjson;
import de.siphalor.tweed5.dataapi.api.TweedDataWriteException;
import de.siphalor.tweed5.dataapi.api.TweedDataVisitor;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.Writer;
@@ -90,7 +89,7 @@ public class HjsonWriter implements TweedDataVisitor {
}
@Override
public void visitString(@NotNull String value) {
public void visitString(String value) {
beforeValueWrite();
writeStringValue(getValueStringStringType(value), value);
afterValueWrite();

View File

@@ -0,0 +1,4 @@
@NullMarked
package de.siphalor.tweed5.data.hjson;
import org.jspecify.annotations.NullMarked;