-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add JSpecify annotations to language package nodes - redo (12 more) #4257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b261a43
4df4205
8fb836e
298fea2
82712c7
7a9e810
dd49296
9e31132
1063251
f4e0f1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| import graphql.PublicApi; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * Represents a language node that has a name | ||
|
|
@@ -12,7 +13,7 @@ | |
| public interface NamedNode<T extends NamedNode> extends Node<T> { | ||
|
|
||
| /** | ||
| * @return the name of this node | ||
| * @return the name of this node, or null if this node is anonymous (e.g. an anonymous operation definition) | ||
| */ | ||
| String getName(); | ||
| @Nullable String getName(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has to be nullable because an operation definition might not have a name |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,9 @@ | |
| import graphql.collect.ImmutableKit; | ||
| import graphql.util.TraversalControl; | ||
| import graphql.util.TraverserContext; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.NullUnmarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
|
|
@@ -19,6 +22,7 @@ | |
| import static graphql.language.NodeChildrenContainer.newNodeChildrenContainer; | ||
|
|
||
| @PublicApi | ||
| @NullMarked | ||
| public class ObjectField extends AbstractNode<ObjectField> implements NamedNode<ObjectField> { | ||
|
|
||
| private final String name; | ||
|
|
@@ -27,7 +31,7 @@ public class ObjectField extends AbstractNode<ObjectField> implements NamedNode< | |
| public static final String CHILD_VALUE = "value"; | ||
|
|
||
| @Internal | ||
| protected ObjectField(String name, Value value, SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars, Map<String, String> additionalData) { | ||
| protected ObjectField(String name, Value value, @Nullable SourceLocation sourceLocation, List<Comment> comments, IgnoredChars ignoredChars, Map<String, String> additionalData) { | ||
| super(sourceLocation, comments, ignoredChars, additionalData); | ||
| this.name = assertNotNull(name); | ||
| this.value = assertNotNull(value); | ||
|
|
@@ -72,7 +76,7 @@ public ObjectField withNewChildren(NodeChildrenContainer newChildren) { | |
| } | ||
|
|
||
| @Override | ||
| public boolean isEqualTo(Node o) { | ||
| public boolean isEqualTo(@Nullable Node o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
|
|
@@ -88,7 +92,7 @@ public boolean isEqualTo(Node o) { | |
|
|
||
| @Override | ||
| public ObjectField deepCopy() { | ||
| return new ObjectField(name, deepCopy(this.value), getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData()); | ||
| return new ObjectField(name, assertNotNull(deepCopy(this.value), "value deepCopy should not return null"), getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used to think assertion messages matter but they dont. A stacktrace would lead to this code location - so less code can be better code
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assert is a special one to satisfy the NullAway check The problem is that deepCopy is a generic utility and I can't guarantee that always returns not-nullable result |
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -114,6 +118,7 @@ public ObjectField transform(Consumer<Builder> builderConsumer) { | |
| return builder.build(); | ||
| } | ||
|
|
||
| @NullUnmarked | ||
| public static final class Builder implements NodeBuilder { | ||
| private SourceLocation sourceLocation; | ||
| private String name; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,9 @@ | |
| import graphql.language.NodeUtil.DirectivesHolder; | ||
| import graphql.util.TraversalControl; | ||
| import graphql.util.TraverserContext; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.NullUnmarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashMap; | ||
|
|
@@ -22,13 +25,14 @@ | |
| import static graphql.language.NodeChildrenContainer.newNodeChildrenContainer; | ||
|
|
||
| @PublicApi | ||
| @NullMarked | ||
| public class OperationDefinition extends AbstractNode<OperationDefinition> implements Definition<OperationDefinition>, SelectionSetContainer<OperationDefinition>, DirectivesContainer<OperationDefinition>, NamedNode<OperationDefinition> { | ||
|
|
||
| public enum Operation { | ||
| QUERY, MUTATION, SUBSCRIPTION | ||
| } | ||
|
|
||
| private final String name; | ||
| private final @Nullable String name; | ||
|
|
||
| private final Operation operation; | ||
| private final ImmutableList<VariableDefinition> variableDefinitions; | ||
|
|
@@ -40,12 +44,12 @@ public enum Operation { | |
| public static final String CHILD_SELECTION_SET = "selectionSet"; | ||
|
|
||
| @Internal | ||
| protected OperationDefinition(String name, | ||
| protected OperationDefinition(@Nullable String name, | ||
| Operation operation, | ||
| List<VariableDefinition> variableDefinitions, | ||
| List<Directive> directives, | ||
| SelectionSet selectionSet, | ||
| SourceLocation sourceLocation, | ||
| @Nullable SourceLocation sourceLocation, | ||
| List<Comment> comments, | ||
| IgnoredChars ignoredChars, | ||
| Map<String, String> additionalData) { | ||
|
|
@@ -57,15 +61,6 @@ protected OperationDefinition(String name, | |
| this.selectionSet = selectionSet; | ||
| } | ||
|
|
||
| public OperationDefinition(String name, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These constructors date back to 2018, no longer needed with the builders we have today. I am removing these lines because these parameters should be not-nullable. I would usually first deprecate the methods, then remove, but if I keep them here with a deprecated annotation, the nullability annotations will not be correct.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically a breaking change |
||
| Operation operation) { | ||
| this(name, operation, emptyList(), emptyList(), null, null, emptyList(), IgnoredChars.EMPTY, emptyMap()); | ||
| } | ||
|
|
||
| public OperationDefinition(String name) { | ||
| this(name, null, emptyList(), emptyList(), null, null, emptyList(), IgnoredChars.EMPTY, emptyMap()); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough - cruft must be removed at some point |
||
| @Override | ||
| public List<Node> getChildren() { | ||
| List<Node> result = new ArrayList<>(); | ||
|
|
@@ -93,7 +88,8 @@ public OperationDefinition withNewChildren(NodeChildrenContainer newChildren) { | |
| ); | ||
| } | ||
|
|
||
| public String getName() { | ||
| @Override | ||
| public @Nullable String getName() { | ||
| return name; | ||
| } | ||
|
|
||
|
|
@@ -130,7 +126,7 @@ public SelectionSet getSelectionSet() { | |
| } | ||
|
|
||
| @Override | ||
| public boolean isEqualTo(Node o) { | ||
| public boolean isEqualTo(@Nullable Node o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
|
|
@@ -148,9 +144,9 @@ public boolean isEqualTo(Node o) { | |
| public OperationDefinition deepCopy() { | ||
| return new OperationDefinition(name, | ||
| operation, | ||
| deepCopy(variableDefinitions), | ||
| deepCopy(directives.getDirectives()), | ||
| deepCopy(selectionSet), | ||
| assertNotNull(deepCopy(variableDefinitions), "variableDefinitions deepCopy should not return null"), | ||
| assertNotNull(deepCopy(directives.getDirectives()), "directives deepCopy should not return null"), | ||
| assertNotNull(deepCopy(selectionSet), "selectionSet deepCopy should not return null"), | ||
| getSourceLocation(), | ||
| getComments(), | ||
| getIgnoredChars(), | ||
|
|
@@ -183,11 +179,12 @@ public OperationDefinition transform(Consumer<Builder> builderConsumer) { | |
| return builder.build(); | ||
| } | ||
|
|
||
| @NullUnmarked | ||
| public static final class Builder implements NodeDirectivesBuilder { | ||
| private SourceLocation sourceLocation; | ||
| private ImmutableList<Comment> comments = emptyList(); | ||
| private String name; | ||
| private Operation operation; | ||
| private Operation operation = Operation.QUERY; | ||
| private ImmutableList<VariableDefinition> variableDefinitions = emptyList(); | ||
| private ImmutableList<Directive> directives = emptyList(); | ||
| private SelectionSet selectionSet; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous attempt randomly deleted a constructor parameter which caused that PR to go off the rails. Let's fix that here