Skip to content

Commit 1a06766

Browse files
committed
go go gadget java 25 + jspecify
1 parent cc565d4 commit 1a06766

File tree

14 files changed

+93
-154
lines changed

14 files changed

+93
-154
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/setup-java@v4
2121
with:
2222
distribution: temurin
23-
java-version: 21
23+
java-version: 25
2424

2525
- name: Setup Gradle
2626
uses: gradle/actions/setup-gradle@v4

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ plugins {
44
}
55

66
group = "fish.cichlidmc"
7-
version = "2.0.1"
7+
version = "3.0.0"
88

99
repositories {
1010
mavenCentral()
1111
}
1212

1313
dependencies {
14-
compileOnlyApi(libs.jetbrains.annotations)
14+
compileOnlyApi(libs.jspecify)
1515
testImplementation(libs.bundles.junit)
1616
}
1717

1818
java {
1919
withSourcesJar()
2020
toolchain {
21-
languageVersion = JavaLanguageVersion.of(21)
21+
languageVersion = JavaLanguageVersion.of(25)
2222
}
2323
}
2424

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[versions]
2-
jetbrains-annotations = "24.1.0"
2+
jspecify = "1.0.0"
33
junit = "6.0.1"
44

55
[libraries]
6-
jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" }
6+
jspecify = { module = "org.jspecify:jspecify", version.ref = "jspecify" }
77
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
88
junit-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit" }
99

src/main/java/fish/cichlidmc/tinyjson/JsonException.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
import fish.cichlidmc.tinyjson.value.JsonValue;
44

5-
/**
6-
* Exception that may be thrown when managing JSON. This may be thrown for a parsing error or
7-
* for a deserialization error (such as calling {@link JsonValue#asObject()} on a non-object)
8-
*/
5+
/// Exception that may be thrown when managing JSON. This may be thrown for a parsing error or
6+
/// for a deserialization error (such as calling [JsonValue#asObject()] on a non-object)
97
public final class JsonException extends RuntimeException {
108
public JsonException(String message) {
119
super(message);
1210
}
1311

14-
/**
15-
* Create a new JsonException with the given value as context. The path is added to the message.
16-
* Format: ${path}: ${message}
17-
*/
12+
/// Create a new JsonException with the given value as context. The path is added to the message.
13+
/// Format: ${path}: ${message}
1814
public JsonException(JsonValue value, String message) {
1915
this(value.getPath() + ": " + message);
2016
}

src/main/java/fish/cichlidmc/tinyjson/TinyJson.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package fish.cichlidmc.tinyjson;
22

3+
import fish.cichlidmc.tinyjson.parser.ValueParser;
4+
import fish.cichlidmc.tinyjson.parser.util.ParseInput;
5+
import fish.cichlidmc.tinyjson.value.JsonValue;
6+
37
import java.io.File;
48
import java.io.IOException;
59
import java.io.InputStream;
@@ -14,22 +18,14 @@
1418
import java.nio.file.Files;
1519
import java.nio.file.Path;
1620

17-
import fish.cichlidmc.tinyjson.parser.ValueParser;
18-
import fish.cichlidmc.tinyjson.parser.util.ParseInput;
19-
import fish.cichlidmc.tinyjson.value.JsonValue;
20-
21-
/**
22-
* Primary interface for TinyJson. Provides several methods for parsing JSON from various sources:
23-
* <ul>
24-
* <li>Strings</li>
25-
* <li>Files</li>
26-
* <li>Paths</li>
27-
* <li>URIs</li>
28-
* <li>URLs</li>
29-
* <li>InputStreams</li>
30-
* <li>Readers</li>
31-
* </ul>
32-
*/
21+
/// Primary interface for TinyJson. Provides several methods for parsing JSON from various sources:
22+
/// - Strings
23+
/// - Files
24+
/// - Paths
25+
/// - URIs
26+
/// - URLs
27+
/// - InputStreams
28+
/// - Readers
3329
public final class TinyJson {
3430
private TinyJson() {}
3531

src/main/java/fish/cichlidmc/tinyjson/parser/util/ParseInput.java

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
package fish.cichlidmc.tinyjson.parser.util;
22

3-
import static fish.cichlidmc.tinyjson.parser.util.ParserUtils.CARRIAGE_RETURN;
4-
import static fish.cichlidmc.tinyjson.parser.util.ParserUtils.EOF;
5-
import static fish.cichlidmc.tinyjson.parser.util.ParserUtils.LINE_BREAK;
3+
import fish.cichlidmc.tinyjson.JsonException;
4+
import org.jspecify.annotations.Nullable;
65

76
import java.io.IOException;
87
import java.io.PushbackReader;
98
import java.io.Reader;
109
import java.util.Arrays;
1110
import java.util.function.Function;
1211

13-
import fish.cichlidmc.tinyjson.JsonException;
12+
import static fish.cichlidmc.tinyjson.parser.util.ParserUtils.CARRIAGE_RETURN;
13+
import static fish.cichlidmc.tinyjson.parser.util.ParserUtils.EOF;
14+
import static fish.cichlidmc.tinyjson.parser.util.ParserUtils.LINE_BREAK;
1415

1516
public final class ParseInput {
1617
private final PushbackReader reader;
1718

1819
private int line = 1;
1920
private int col = 1;
2021

21-
// Nullable
22+
@Nullable
2223
private CommentState commentState;
2324

2425
public ParseInput(Reader reader) {
2526
this.reader = new PushbackReader(reader, 64);
2627
}
2728

28-
/**
29-
* Read the next character, incrementing the parser location. Throws if the end of input is reached.
30-
* Line breaks are unified into \n.
31-
*/
29+
/// Read the next character, incrementing the parser location. Throws if the end of input is reached.
30+
/// Line breaks are unified into \n.
3231
public char next() throws IOException {
3332
char next = this.read();
3433
if (next == CARRIAGE_RETURN && this.peek() == LINE_BREAK) {
@@ -53,9 +52,7 @@ private void nextLine() {
5352
this.col = 1;
5453
}
5554

56-
/**
57-
* Skip past all whitespace at the start of the input, including comments.
58-
*/
55+
/// Skip past all whitespace at the start of the input, including comments.
5956
public void skipWhitespace() throws IOException {
6057
while (true) {
6158
int next = this.peek();
@@ -118,17 +115,13 @@ public void skipWhitespace() throws IOException {
118115
}
119116
}
120117

121-
/**
122-
* Read the next non-whitespace character, throwing if EOF is reached.
123-
*/
118+
/// Read the next non-whitespace character, throwing if EOF is reached.
124119
public char peekNonWhitespace() throws IOException {
125120
this.skipWhitespace();
126121
return this.peekOrThrow();
127122
}
128123

129-
/**
130-
* Read the next N characters into an array, throwing if EOF is reached.
131-
*/
124+
/// Read the next N characters into an array, throwing if EOF is reached.
132125
public char[] next(int n) throws IOException {
133126
char[] array = new char[n];
134127
for (int i = 0; i < n; i++) {
@@ -137,9 +130,7 @@ public char[] next(int n) throws IOException {
137130
return array;
138131
}
139132

140-
/**
141-
* Read the next character without consuming it. May be EOF.
142-
*/
133+
/// Read the next character without consuming it. May be EOF.
143134
public int peek() throws IOException {
144135
int next = this.tryRead();
145136
if (next != EOF) {
@@ -148,18 +139,14 @@ public int peek() throws IOException {
148139
return next;
149140
}
150141

151-
/**
152-
* Read the next character without consuming it, throwing if it's EOF.
153-
*/
142+
/// Read the next character without consuming it, throwing if it's EOF.
154143
public char peekOrThrow() throws IOException {
155144
char next = this.read();
156145
this.reader.unread(next);
157146
return next;
158147
}
159148

160-
/**
161-
* Peek the next N characters into an array. May be shorter than expected due to EOF.
162-
*/
149+
/// Peek the next N characters into an array. May be shorter than expected due to EOF.
163150
public char[] peek(int n) throws IOException {
164151
char[] chars = new char[n];
165152
for (int i = 0; i < n; i++) {
@@ -178,9 +165,7 @@ public char[] peek(int n) throws IOException {
178165
return chars;
179166
}
180167

181-
/**
182-
* Try to read the next character. May be EOF.
183-
*/
168+
/// Try to read the next character. May be EOF.
184169
public int tryRead() throws IOException {
185170
return this.reader.read();
186171
}
@@ -189,17 +174,13 @@ public Position pos() {
189174
return new Position(this.line, this.col);
190175
}
191176

192-
/**
193-
* Return a new JsonException to be thrown. Message may contain
194-
* "${pos}" as a placeholder for the current input position.
195-
*/
177+
/// Return a new JsonException to be thrown. Message may contain
178+
/// "${pos}" as a placeholder for the current input position.
196179
public JsonException error(Function<Position, String> messageFactory) {
197180
return new JsonException(messageFactory.apply(this.pos()));
198181
}
199182

200-
/**
201-
* Shortcut for error that just adds 'at ${pos}' to the end.
202-
*/
183+
/// Shortcut for error that just adds 'at ${pos}' to the end.
203184
public JsonException errorAt(String message) {
204185
return this.error(pos -> message + " at " + pos);
205186
}

src/main/java/fish/cichlidmc/tinyjson/value/JsonPrimitive.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
import fish.cichlidmc.tinyjson.value.primitive.JsonNumber;
66
import fish.cichlidmc.tinyjson.value.primitive.JsonString;
77

8-
/**
9-
* A JsonPrimitive is a JsonValue that holds some direct value and not other JsonValues.
10-
*/
8+
/// A JsonPrimitive is a JsonValue that holds some direct value and not other JsonValues.
119
public abstract sealed class JsonPrimitive<T> extends JsonValue permits JsonString, JsonNumber, JsonBool, JsonNull {
12-
/**
13-
* Value held by this JSON value. Always non-null UNLESS this is a JsonNull.
14-
*/
10+
/// Value held by this JSON value. Always non-null UNLESS this is a JsonNull.
1511
public abstract T value();
1612
}

src/main/java/fish/cichlidmc/tinyjson/value/JsonValue.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@
77
import fish.cichlidmc.tinyjson.value.primitive.JsonNull;
88
import fish.cichlidmc.tinyjson.value.primitive.JsonNumber;
99
import fish.cichlidmc.tinyjson.value.primitive.JsonString;
10+
import org.jspecify.annotations.Nullable;
1011

11-
/**
12-
* Parent class to all JSON representations.
13-
* All JsonValues store a path to themselves for identification in errors. This means that one
14-
* JsonValue cannot be shared between multiple JsonObjects or JsonArrays and a copy must be made.
15-
*/
12+
/// Parent class to all JSON representations.
13+
/// All JsonValues store a path to themselves for identification in errors. This means that one
14+
/// JsonValue cannot be shared between multiple JsonObjects or JsonArrays and a copy must be made.
1615
public abstract sealed class JsonValue permits JsonPrimitive, JsonArray, JsonObject {
1716
public static final String ROOT_PATH = "$";
17+
@Nullable
1818
private String path;
1919

20-
/**
21-
* Create a deep copy of this value and all children.
22-
* The path of this value is not preserved, and all children are updated so that the copy is their root.
23-
*/
20+
/// Create a deep copy of this value and all children.
21+
/// The path of this value is not preserved, and all children are updated so that the copy is their root.
2422
public abstract JsonValue copy();
2523

26-
/**
27-
* Create a pretty-printed string representing this JSON value. This string is parseable back into a JsonValue.
28-
*/
24+
/// Create a pretty-printed string representing this JSON value. This string is parseable back into a JsonValue.
2925
@Override
3026
public abstract String toString();
3127

@@ -48,10 +44,8 @@ private JsonException typeError(String type) {
4844
}
4945
}
5046

51-
/**
52-
* internal - do not call this directly. Paths are managed by JsonArray and JsonObject.
53-
*/
54-
public void setPath(String path) {
47+
/// internal - do not call this directly. Paths are managed by JsonArray and JsonObject.
48+
public void setPath(@Nullable String path) {
5549
if (this.hasPath() && path != null) {
5650
throw new IllegalStateException("Cannot override path " + this.path + " with " + path);
5751
}

src/main/java/fish/cichlidmc/tinyjson/value/composite/JsonArray.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package fish.cichlidmc.tinyjson.value.composite;
22

3-
import java.util.ArrayList;
4-
import java.util.Iterator;
5-
import java.util.List;
6-
import java.util.stream.Stream;
7-
83
import fish.cichlidmc.tinyjson.JsonException;
94
import fish.cichlidmc.tinyjson.value.JsonValue;
105
import fish.cichlidmc.tinyjson.value.primitive.JsonBool;
116
import fish.cichlidmc.tinyjson.value.primitive.JsonNull;
127
import fish.cichlidmc.tinyjson.value.primitive.JsonNumber;
138
import fish.cichlidmc.tinyjson.value.primitive.JsonString;
9+
import org.jspecify.annotations.Nullable;
10+
11+
import java.util.ArrayList;
12+
import java.util.Iterator;
13+
import java.util.List;
14+
import java.util.stream.Stream;
1415

1516
public final class JsonArray extends JsonValue implements Iterable<JsonValue> {
1617
private final List<JsonValue> values = new ArrayList<>();
@@ -110,7 +111,7 @@ public String toString() {
110111
}
111112

112113
@Override
113-
public void setPath(String path) {
114+
public void setPath(@Nullable String path) {
114115
super.setPath(path);
115116
for (int i = 0; i < this.size(); i++) {
116117
JsonValue value = this.get(i);
@@ -130,6 +131,7 @@ private String makePath(int i) {
130131

131132
private static final class JsonArrayIterator implements Iterator<JsonValue> {
132133
private final Iterator<JsonValue> wrapped;
134+
@Nullable
133135
private JsonValue lastReturned;
134136

135137
private JsonArrayIterator(Iterator<JsonValue> wrapped) {

0 commit comments

Comments
 (0)