Repository navigation
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
Changes from 9 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 |
|---|---|---|
|
|
@@ -166,7 +166,10 @@ public void visitField(QueryVisitorFieldEnvironment env) { | |
| } | ||
|
|
||
| private GraphQLObjectType getRootTypeFromOperation(OperationDefinition operationDefinition) { | ||
| switch (operationDefinition.getOperation()) { | ||
| OperationDefinition.Operation op = operationDefinition.getOperation() != null | ||
| ? operationDefinition.getOperation() | ||
| : OperationDefinition.Operation.QUERY; | ||
| switch (op) { | ||
|
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. Some follow on changes after adding nullability annotations |
||
| case MUTATION: | ||
| return assertNotNull(schema.getMutationType()); | ||
| case QUERY: | ||
|
|
||
| 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; | ||
|
|
||
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