Skip to content

Commit c02fa4e

Browse files
Copilotdondonz
andcommitted
Add JSpecify annotations to 10 classes in graphql.language package
Co-authored-by: dondonz <13839920+dondonz@users.noreply.github.com>
1 parent c60fdf6 commit c02fa4e

11 files changed

Lines changed: 36 additions & 20 deletions

File tree

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package graphql.language;
22

33
import graphql.PublicApi;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
46

57
import java.io.Serializable;
68

79
/**
810
* A single-line comment. These are comments that start with a {@code #} in source documents.
911
*/
1012
@PublicApi
13+
@NullMarked
1114
public class Comment implements Serializable {
1215
public final String content;
13-
public final SourceLocation sourceLocation;
16+
public final @Nullable SourceLocation sourceLocation;
1417

15-
public Comment(String content, SourceLocation sourceLocation) {
18+
public Comment(String content, @Nullable SourceLocation sourceLocation) {
1619
this.content = content;
1720
this.sourceLocation = sourceLocation;
1821
}
@@ -21,7 +24,7 @@ public String getContent() {
2124
return content;
2225
}
2326

24-
public SourceLocation getSourceLocation() {
27+
public @Nullable SourceLocation getSourceLocation() {
2528
return sourceLocation;
2629
}
2730
}

src/main/java/graphql/language/Definition.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33

44
import graphql.PublicApi;
5+
import org.jspecify.annotations.NullMarked;
56

67
@PublicApi
8+
@NullMarked
79
public interface Definition<T extends Definition> extends Node<T> {
810

911
}

src/main/java/graphql/language/IgnoredChar.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package graphql.language;
22

33
import graphql.PublicApi;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.Nullable;
46

57
import java.io.Serializable;
68
import java.util.Objects;
@@ -12,6 +14,7 @@
1214
* This costs more memory but for certain use cases (like editors) this maybe be useful
1315
*/
1416
@PublicApi
17+
@NullMarked
1518
public class IgnoredChar implements Serializable {
1619

1720
public enum IgnoredCharKind {
@@ -51,7 +54,7 @@ public String toString() {
5154
}
5255

5356
@Override
54-
public boolean equals(Object o) {
57+
public boolean equals(@Nullable Object o) {
5558
if (this == o) {
5659
return true;
5760
}

src/main/java/graphql/language/IgnoredChars.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.ImmutableList;
44
import graphql.PublicApi;
55
import graphql.collect.ImmutableKit;
6+
import org.jspecify.annotations.NullMarked;
67

78
import java.io.Serializable;
89
import java.util.List;
@@ -14,6 +15,7 @@
1415
* This costs more memory but for certain use cases (like editors) this maybe be useful
1516
*/
1617
@PublicApi
18+
@NullMarked
1719
public class IgnoredChars implements Serializable {
1820

1921
private final ImmutableList<IgnoredChar> left;

src/main/java/graphql/language/Node.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import graphql.PublicApi;
55
import graphql.util.TraversalControl;
66
import graphql.util.TraverserContext;
7+
import org.jspecify.annotations.NullMarked;
78
import org.jspecify.annotations.Nullable;
89

910
import java.io.Serializable;
@@ -21,6 +22,7 @@
2122
* Every Node is immutable
2223
*/
2324
@PublicApi
25+
@NullMarked
2426
public interface Node<T extends Node> extends Serializable {
2527

2628
/**

src/main/java/graphql/language/NodeChildrenContainer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package graphql.language;
22

33
import graphql.PublicApi;
4+
import org.jspecify.annotations.NullMarked;
5+
import org.jspecify.annotations.NullUnmarked;
6+
import org.jspecify.annotations.Nullable;
47

58
import java.util.ArrayList;
69
import java.util.LinkedHashMap;
@@ -15,6 +18,7 @@
1518
* Container of children of a {@link Node}.
1619
*/
1720
@PublicApi
21+
@NullMarked
1822
public class NodeChildrenContainer {
1923

2024
private final Map<String, List<Node>> children = new LinkedHashMap<>();
@@ -27,7 +31,7 @@ public <T extends Node> List<T> getChildren(String key) {
2731
return (List<T>) children.getOrDefault(key, emptyList());
2832
}
2933

30-
public <T extends Node> T getChildOrNull(String key) {
34+
public <T extends Node> @Nullable T getChildOrNull(String key) {
3135
List<? extends Node> result = children.getOrDefault(key, emptyList());
3236
if (result.size() > 1) {
3337
throw new IllegalStateException("children " + key + " is not a single value");
@@ -61,6 +65,7 @@ public boolean isEmpty() {
6165
return this.children.isEmpty();
6266
}
6367

68+
@NullUnmarked
6469
public static class Builder {
6570
private final Map<String, List<Node>> children = new LinkedHashMap<>();
6671

src/main/java/graphql/language/NodeVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import graphql.PublicApi;
44
import graphql.util.TraversalControl;
55
import graphql.util.TraverserContext;
6+
import org.jspecify.annotations.NullMarked;
67

78
/**
89
* Used by {@link NodeTraverser} to visit {@link Node}.
910
*/
1011
@PublicApi
12+
@NullMarked
1113
public interface NodeVisitor {
1214
TraversalControl visitArgument(Argument node, TraverserContext<Node> data);
1315

src/main/java/graphql/language/NodeVisitorStub.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import graphql.PublicApi;
44
import graphql.util.TraversalControl;
55
import graphql.util.TraverserContext;
6+
import org.jspecify.annotations.NullMarked;
67

78
/**
89
* Convenient implementation of {@link NodeVisitor} for easy subclassing methods handling different types of Nodes in one method.
910
*/
1011
@PublicApi
12+
@NullMarked
1113
public class NodeVisitorStub implements NodeVisitor {
1214
@Override
1315
public TraversalControl visitArgument(Argument node, TraverserContext<Node> context) {

src/main/java/graphql/language/SourceLocation.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@
77
import graphql.schema.GraphQLSchemaElement;
88
import graphql.schema.GraphQLTypeUtil;
99
import graphql.schema.idl.SchemaGenerator;
10+
import org.jspecify.annotations.NullMarked;
11+
import org.jspecify.annotations.Nullable;
1012

1113
import java.io.Serializable;
1214
import java.util.Objects;
1315

1416
@PublicApi
17+
@NullMarked
1518
public class SourceLocation implements Serializable {
1619

1720
public static final SourceLocation EMPTY = new SourceLocation(-1, -1);
1821

1922
private final int line;
2023
private final int column;
21-
private final String sourceName;
24+
private final @Nullable String sourceName;
2225

2326
public SourceLocation(int line, int column) {
2427
this(line, column, null);
2528
}
2629

27-
public SourceLocation(int line, int column, String sourceName) {
30+
public SourceLocation(int line, int column, @Nullable String sourceName) {
2831
this.line = line;
2932
this.column = column;
3033
this.sourceName = sourceName;
@@ -38,12 +41,12 @@ public int getColumn() {
3841
return column;
3942
}
4043

41-
public String getSourceName() {
44+
public @Nullable String getSourceName() {
4245
return sourceName;
4346
}
4447

4548
@Override
46-
public boolean equals(Object o) {
49+
public boolean equals(@Nullable Object o) {
4750
if (this == o) {
4851
return true;
4952
}
@@ -91,7 +94,7 @@ public String toString() {
9194
*
9295
* @return the source location if available or null if it's not.
9396
*/
94-
public static SourceLocation getLocation(GraphQLSchemaElement schemaElement) {
97+
public static @Nullable SourceLocation getLocation(GraphQLSchemaElement schemaElement) {
9598
if (schemaElement instanceof GraphQLModifiedType) {
9699
schemaElement = GraphQLTypeUtil.unwrapAllAs((GraphQLModifiedType) schemaElement);
97100
}

src/main/java/graphql/language/Type.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33

44
import graphql.PublicApi;
5+
import org.jspecify.annotations.NullMarked;
56

67
@PublicApi
8+
@NullMarked
79
public interface Type<T extends Type> extends Node<T> {
810

911
}

0 commit comments

Comments
 (0)