Skip to content

Commit abac15b

Browse files
authored
Merge pull request #32 from KyoriPowered/chore/jspecify
migrate nullness annotations to jspecify
2 parents 8e0101d + 479e372 commit abac15b

File tree

17 files changed

+101
-105
lines changed

17 files changed

+101
-105
lines changed

.checkstyle/checkstyle.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101

102102
<!-- https://checkstyle.org/config_imports.html#IllegalImport -->
103103
<module name="IllegalImport">
104+
<property name="illegalClasses" value="org.jetbrains.annotations.Nullable, org.jetbrains.annotations.NotNull"/>
104105
<property name="illegalPkgs" value="sun, jdk, com.sun"/>
105106
</module>
106107

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010

1111
dependencies {
1212
compileOnlyApi(libs.jetbrainsAnnotations)
13+
compileOnlyApi(libs.jspecify)
1314
testImplementation(platform(libs.junit.bom))
1415
testImplementation(libs.junit.api)
1516
testRuntimeOnly(libs.junit.engine)

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ junit = "5.11.4"
88

99
[libraries]
1010
jetbrainsAnnotations = "org.jetbrains:annotations:26.0.2"
11+
jspecify = { module = "org.jspecify:jspecify", version = "1.0.0"}
1112
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
1213
junit-api = { module = "org.junit.jupiter:junit-jupiter-api" }
1314
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
@@ -24,4 +25,4 @@ indra-crossdoc = { id = "net.kyori.indra.crossdoc", version.ref = "indra" }
2425
indra-licenser-spotless = { id = "net.kyori.indra.licenser.spotless", version.ref = "indra" }
2526
indra-publishing-sonatype = { id = "net.kyori.indra.publishing.sonatype", version.ref = "indra" }
2627
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" }
27-
spotless = "com.diffplug.spotless:7.0.2"
28+
spotless = "com.diffplug.spotless:7.0.2"

src/main/java/net/kyori/option/Option.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
import net.kyori.option.value.ValueType;
2727
import org.jetbrains.annotations.ApiStatus;
28-
import org.jetbrains.annotations.NotNull;
29-
import org.jetbrains.annotations.Nullable;
28+
import org.jspecify.annotations.Nullable;
3029

3130
/**
3231
* A representation of a configurable option.
@@ -80,7 +79,7 @@ static <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E>
8079
* @return the flag id
8180
* @since 1.0.0
8281
*/
83-
@NotNull String id();
82+
String id();
8483

8584
/**
8685
* Get the type of the option value.
@@ -90,7 +89,7 @@ static <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E>
9089
* @deprecated for removal since 1.1.0, use {@link #valueType()} instead
9190
*/
9291
@Deprecated
93-
default @NotNull Class<V> type() {
92+
default Class<V> type() {
9493
return this.valueType().type();
9594
}
9695

@@ -100,7 +99,7 @@ static <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E>
10099
* @return the value type
101100
* @since 1.0.0
102101
*/
103-
@NotNull ValueType<V> valueType();
102+
ValueType<V> valueType();
104103

105104
/**
106105
* Get a default value for the option, if any is present.

src/main/java/net/kyori/option/OptionImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,27 @@
2525

2626
import java.util.Objects;
2727
import net.kyori.option.value.ValueType;
28-
import org.jetbrains.annotations.NotNull;
29-
import org.jetbrains.annotations.Nullable;
28+
import org.jspecify.annotations.Nullable;
3029

3130
final class OptionImpl<V> implements Option<V> {
3231

3332
private final String id;
3433
private final ValueType<V> type;
3534
private final @Nullable V defaultValue; // excluded from equality comparisons, it does not form part of the option identity
3635

37-
OptionImpl(final @NotNull String id, final @NotNull ValueType<V> type, final @Nullable V defaultValue) {
36+
OptionImpl(final String id, final ValueType<V> type, final @Nullable V defaultValue) {
3837
this.id = id;
3938
this.type = type;
4039
this.defaultValue = defaultValue;
4140
}
4241

4342
@Override
44-
public @NotNull String id() {
43+
public String id() {
4544
return this.id;
4645
}
4746

4847
@Override
49-
public @NotNull ValueType<V> valueType() {
48+
public ValueType<V> valueType() {
5049
return this.type;
5150
}
5251

src/main/java/net/kyori/option/OptionSchema.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
import java.util.Set;
2727
import org.jetbrains.annotations.ApiStatus;
28-
import org.jetbrains.annotations.NotNull;
29-
import org.jetbrains.annotations.Nullable;
28+
import org.jspecify.annotations.Nullable;
3029

3130
import static java.util.Objects.requireNonNull;
3231

@@ -45,7 +44,7 @@ public interface OptionSchema {
4544
* @return the global schema
4645
* @since 1.1.0
4746
*/
48-
static OptionSchema.@NotNull Mutable globalSchema() {
47+
static OptionSchema.Mutable globalSchema() {
4948
return OptionSchemaImpl.Instances.GLOBAL;
5049
}
5150

@@ -58,7 +57,7 @@ public interface OptionSchema {
5857
* @return the mutable child schema
5958
* @since 1.1.0
6059
*/
61-
static OptionSchema.@NotNull Mutable childSchema(final @NotNull OptionSchema schema) {
60+
static OptionSchema.Mutable childSchema(final OptionSchema schema) {
6261
final OptionSchemaImpl impl;
6362
if (schema instanceof OptionSchemaImpl.MutableImpl) {
6463
impl = (OptionSchemaImpl) ((Mutable) schema).frozenView();
@@ -76,7 +75,7 @@ public interface OptionSchema {
7675
* @return a mutable schema
7776
* @since 1.1.0
7877
*/
79-
static OptionSchema.@NotNull Mutable emptySchema() {
78+
static OptionSchema.Mutable emptySchema() {
8079
return new OptionSchemaImpl(null).new MutableImpl();
8180
}
8281

@@ -86,7 +85,7 @@ public interface OptionSchema {
8685
* @return known options
8786
* @since 1.1.0
8887
*/
89-
@NotNull Set<Option<?>> knownOptions();
88+
Set<Option<?>> knownOptions();
9089

9190
/**
9291
* Return whether the provided option is known within this scheam.
@@ -95,23 +94,23 @@ public interface OptionSchema {
9594
* @return whether the option is known
9695
* @since 1.1.0
9796
*/
98-
boolean has(final @NotNull Option<?> option);
97+
boolean has(final Option<?> option);
9998

10099
/**
101100
* Create a builder for an unversioned option state containing only options within this schema.
102101
*
103102
* @return the builder
104103
* @since 1.1.0
105104
*/
106-
OptionState.@NotNull Builder stateBuilder();
105+
OptionState.Builder stateBuilder();
107106

108107
/**
109108
* Create a builder for a versioned option state containing only values for options within this schema.
110109
*
111110
* @return the builder
112111
* @since 1.1.0
113112
*/
114-
OptionState.@NotNull VersionedBuilder versionedStateBuilder();
113+
OptionState.VersionedBuilder versionedStateBuilder();
115114

116115
/**
117116
* Create an empty option state within this schema.
@@ -138,7 +137,7 @@ interface Mutable extends OptionSchema {
138137
* @return the flag instance
139138
* @since 1.1.0
140139
*/
141-
@NotNull Option<String> stringOption(final @NotNull String id, final @Nullable String defaultValue);
140+
Option<String> stringOption(final String id, final @Nullable String defaultValue);
142141

143142
/**
144143
* Create an option with a boolean value type.
@@ -150,7 +149,7 @@ interface Mutable extends OptionSchema {
150149
* @return the flag instance
151150
* @since 1.1.0
152151
*/
153-
@NotNull Option<Boolean> booleanOption(final @NotNull String id, final boolean defaultValue);
152+
Option<Boolean> booleanOption(final String id, final boolean defaultValue);
154153

155154
/**
156155
* Create an option with an integer value type.
@@ -162,7 +161,7 @@ interface Mutable extends OptionSchema {
162161
* @return the flag instance
163162
* @since 1.1.0
164163
*/
165-
@NotNull Option<Integer> intOption(final @NotNull String id, final int defaultValue);
164+
Option<Integer> intOption(final String id, final int defaultValue);
166165

167166
/**
168167
* Create an option with a double value type.
@@ -174,7 +173,7 @@ interface Mutable extends OptionSchema {
174173
* @return the flag instance
175174
* @since 1.1.0
176175
*/
177-
@NotNull Option<Double> doubleOption(final @NotNull String id, final double defaultValue);
176+
Option<Double> doubleOption(final String id, final double defaultValue);
178177

179178
/**
180179
* Create an option with an enum value type.
@@ -188,7 +187,7 @@ interface Mutable extends OptionSchema {
188187
* @return the flag instance
189188
* @since 1.1.0
190189
*/
191-
<E extends Enum<E>> @NotNull Option<E> enumOption(final @NotNull String id, final @NotNull Class<E> enumClazz, final @Nullable E defaultValue);
190+
<E extends Enum<E>> Option<E> enumOption(final String id, final Class<E> enumClazz, final @Nullable E defaultValue);
192191

193192
/**
194193
* Return a view of this schema which does not allow consumers to register new options.
@@ -198,6 +197,6 @@ interface Mutable extends OptionSchema {
198197
* @return the frozen view of this schema
199198
* @since 1.1.0
200199
*/
201-
@NotNull OptionSchema frozenView();
200+
OptionSchema frozenView();
202201
}
203202
}

src/main/java/net/kyori/option/OptionSchemaImpl.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
import java.util.concurrent.ConcurrentHashMap;
3131
import java.util.concurrent.ConcurrentMap;
3232
import net.kyori.option.value.ValueType;
33-
import org.jetbrains.annotations.NotNull;
34-
import org.jetbrains.annotations.Nullable;
33+
import org.jspecify.annotations.Nullable;
3534

3635
import static java.util.Objects.requireNonNull;
3736

@@ -47,23 +46,23 @@ final class OptionSchemaImpl implements OptionSchema {
4746
}
4847

4948
@Override
50-
public @NotNull Set<Option<?>> knownOptions() {
49+
public Set<Option<?>> knownOptions() {
5150
return Collections.unmodifiableSet(new HashSet<>(this.options.values()));
5251
}
5352

5453
@Override
55-
public boolean has(final @NotNull Option<?> option) {
54+
public boolean has(final Option<?> option) {
5655
final Option<?> own = this.options.get(option.id());
5756
return own != null && own.equals(option);
5857
}
5958

6059
@Override
61-
public OptionState.@NotNull Builder stateBuilder() {
60+
public OptionState.Builder stateBuilder() {
6261
return new OptionStateImpl.BuilderImpl(this);
6362
}
6463

6564
@Override
66-
public OptionState.@NotNull VersionedBuilder versionedStateBuilder() {
65+
public OptionState.VersionedBuilder versionedStateBuilder() {
6766
return new OptionStateImpl.VersionedBuilderImpl(this);
6867
}
6968

@@ -99,54 +98,54 @@ <T> Option<T> register(final String id, final ValueType<T> type, final @Nullable
9998
}
10099

101100
@Override
102-
public @NotNull Option<String> stringOption(final @NotNull String id, final @Nullable String defaultValue) {
101+
public Option<String> stringOption(final String id, final @Nullable String defaultValue) {
103102
return this.register(id, ValueType.stringType(), defaultValue);
104103
}
105104

106105
@Override
107-
public @NotNull Option<Boolean> booleanOption(final @NotNull String id, final boolean defaultValue) {
106+
public Option<Boolean> booleanOption(final String id, final boolean defaultValue) {
108107
return this.register(id, ValueType.booleanType(), defaultValue);
109108
}
110109

111110
@Override
112-
public @NotNull Option<Integer> intOption(final @NotNull String id, final int defaultValue) {
111+
public Option<Integer> intOption(final String id, final int defaultValue) {
113112
return this.register(id, ValueType.integerType(), defaultValue);
114113
}
115114

116115
@Override
117-
public @NotNull Option<Double> doubleOption(final @NotNull String id, final double defaultValue) {
116+
public Option<Double> doubleOption(final String id, final double defaultValue) {
118117
return this.register(id, ValueType.doubleType(), defaultValue);
119118
}
120119

121120
@Override
122-
public @NotNull <E extends Enum<E>> Option<E> enumOption(final @NotNull String id, final @NotNull Class<E> enumClazz, final @Nullable E defaultValue) {
121+
public <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E> enumClazz, final @Nullable E defaultValue) {
123122
return this.register(id, ValueType.enumType(enumClazz), defaultValue);
124123
}
125124

126125
@Override
127-
public @NotNull OptionSchema frozenView() {
126+
public OptionSchema frozenView() {
128127
return OptionSchemaImpl.this;
129128
}
130129

131130
// base scheam methods
132131

133132
@Override
134-
public @NotNull Set<Option<?>> knownOptions() {
133+
public Set<Option<?>> knownOptions() {
135134
return OptionSchemaImpl.this.knownOptions();
136135
}
137136

138137
@Override
139-
public boolean has(final @NotNull Option<?> option) {
138+
public boolean has(final Option<?> option) {
140139
return OptionSchemaImpl.this.has(option);
141140
}
142141

143142
@Override
144-
public OptionState.@NotNull Builder stateBuilder() {
143+
public OptionState.Builder stateBuilder() {
145144
return OptionSchemaImpl.this.stateBuilder();
146145
}
147146

148147
@Override
149-
public OptionState.@NotNull VersionedBuilder versionedStateBuilder() {
148+
public OptionState.VersionedBuilder versionedStateBuilder() {
150149
return OptionSchemaImpl.this.versionedStateBuilder();
151150
}
152151

0 commit comments

Comments
 (0)