Skip to content

Commit baa9a0e

Browse files
committed
Make name not nullable
1 parent 75a9170 commit baa9a0e

5 files changed

Lines changed: 82 additions & 94 deletions

File tree

‎src/main/java/graphql/language/EnumTypeDefinition.java‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@
2323

2424
@PublicApi
2525
@NullMarked
26-
public class EnumTypeDefinition extends AbstractDescribedNode<EnumTypeDefinition> implements TypeDefinition<EnumTypeDefinition>, DirectivesContainer<EnumTypeDefinition>, NamedNode<EnumTypeDefinition> {
27-
private final @Nullable String name;
26+
public class EnumTypeDefinition extends AbstractDescribedNode<EnumTypeDefinition> implements
27+
TypeDefinition<EnumTypeDefinition>, DirectivesContainer<EnumTypeDefinition>, NamedNode<EnumTypeDefinition> {
28+
private final String name;
2829
private final ImmutableList<EnumValueDefinition> enumValueDefinitions;
2930
private final NodeUtil.DirectivesHolder directives;
3031

3132
public static final String CHILD_ENUM_VALUE_DEFINITIONS = "enumValueDefinitions";
3233
public static final String CHILD_DIRECTIVES = "directives";
3334

3435
@Internal
35-
protected EnumTypeDefinition(@Nullable String name,
36-
List<EnumValueDefinition> enumValueDefinitions,
37-
List<Directive> directives,
38-
@Nullable Description description,
39-
@Nullable SourceLocation sourceLocation,
40-
List<Comment> comments,
41-
IgnoredChars ignoredChars, Map<String, String> additionalData) {
36+
protected EnumTypeDefinition(String name,
37+
List<EnumValueDefinition> enumValueDefinitions,
38+
List<Directive> directives,
39+
@Nullable Description description,
40+
@Nullable SourceLocation sourceLocation,
41+
List<Comment> comments,
42+
IgnoredChars ignoredChars, Map<String, String> additionalData) {
4243
super(sourceLocation, comments, ignoredChars, additionalData, description);
4344
this.name = name;
4445
this.directives = NodeUtil.DirectivesHolder.of(directives);
@@ -80,7 +81,7 @@ public boolean hasDirective(String directiveName) {
8081

8182
@Override
8283
public String getName() {
83-
return assertNotNull(name, () -> "name cannot be null");
84+
return name;
8485
}
8586

8687
@Override
@@ -103,8 +104,7 @@ public NodeChildrenContainer getNamedChildren() {
103104
public EnumTypeDefinition withNewChildren(NodeChildrenContainer newChildren) {
104105
return transform(builder -> builder
105106
.enumValueDefinitions(newChildren.getChildren(CHILD_ENUM_VALUE_DEFINITIONS))
106-
.directives(newChildren.getChildren(CHILD_DIRECTIVES))
107-
);
107+
.directives(newChildren.getChildren(CHILD_DIRECTIVES)));
108108
}
109109

110110
@Override
@@ -237,9 +237,9 @@ public Builder additionalData(String key, String value) {
237237
return this;
238238
}
239239

240-
241240
public EnumTypeDefinition build() {
242-
return new EnumTypeDefinition(name, enumValueDefinitions, directives, description, sourceLocation, comments, ignoredChars, additionalData);
241+
return new EnumTypeDefinition(assertNotNull(name), enumValueDefinitions, directives, description,
242+
sourceLocation, comments, ignoredChars, additionalData);
243243
}
244244
}
245245
}

‎src/main/java/graphql/language/EnumValueDefinition.java‎

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

3-
43
import com.google.common.collect.ImmutableList;
54
import graphql.Internal;
65
import graphql.PublicApi;
@@ -23,19 +22,20 @@
2322

2423
@PublicApi
2524
@NullMarked
26-
public class EnumValueDefinition extends AbstractDescribedNode<EnumValueDefinition> implements DirectivesContainer<EnumValueDefinition>, NamedNode<EnumValueDefinition> {
27-
private final @Nullable String name;
25+
public class EnumValueDefinition extends AbstractDescribedNode<EnumValueDefinition>
26+
implements DirectivesContainer<EnumValueDefinition>, NamedNode<EnumValueDefinition> {
27+
private final String name;
2828
private final NodeUtil.DirectivesHolder directives;
2929

3030
public static final String CHILD_DIRECTIVES = "directives";
3131

3232
@Internal
33-
protected EnumValueDefinition(@Nullable String name,
34-
List<Directive> directives,
35-
@Nullable Description description,
36-
@Nullable SourceLocation sourceLocation,
37-
List<Comment> comments,
38-
IgnoredChars ignoredChars, Map<String, String> additionalData) {
33+
protected EnumValueDefinition(String name,
34+
List<Directive> directives,
35+
@Nullable Description description,
36+
@Nullable SourceLocation sourceLocation,
37+
List<Comment> comments,
38+
IgnoredChars ignoredChars, Map<String, String> additionalData) {
3939
super(sourceLocation, comments, ignoredChars, additionalData, description);
4040
this.name = name;
4141
this.directives = NodeUtil.DirectivesHolder.of(directives);
@@ -62,7 +62,7 @@ public EnumValueDefinition(String name, List<Directive> directives) {
6262

6363
@Override
6464
public String getName() {
65-
return assertNotNull(name, () -> "name cannot be null");
65+
return name;
6666
}
6767

6868
@Override
@@ -100,8 +100,7 @@ public NodeChildrenContainer getNamedChildren() {
100100
@Override
101101
public EnumValueDefinition withNewChildren(NodeChildrenContainer newChildren) {
102102
return transform(builder -> builder
103-
.directives(newChildren.getChildren(CHILD_DIRECTIVES))
104-
);
103+
.directives(newChildren.getChildren(CHILD_DIRECTIVES)));
105104
}
106105

107106
@Override
@@ -121,7 +120,8 @@ public boolean isEqualTo(@Nullable Node o) {
121120

122121
@Override
123122
public EnumValueDefinition deepCopy() {
124-
return new EnumValueDefinition(name, assertNotNull(deepCopy(directives.getDirectives())), description, getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
123+
return new EnumValueDefinition(name, assertNotNull(deepCopy(directives.getDirectives())), description,
124+
getSourceLocation(), getComments(), getIgnoredChars(), getAdditionalData());
125125
}
126126

127127
@Override
@@ -215,9 +215,9 @@ public Builder additionalData(String key, String value) {
215215
return this;
216216
}
217217

218-
219218
public EnumValueDefinition build() {
220-
return new EnumValueDefinition(name, directives, description, sourceLocation, comments, ignoredChars, additionalData);
219+
return new EnumValueDefinition(assertNotNull(name), directives, description, sourceLocation, comments,
220+
ignoredChars, additionalData);
221221
}
222222
}
223223
}

‎src/main/java/graphql/language/Field.java‎

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

3-
43
import com.google.common.collect.ImmutableList;
54
import com.google.common.collect.ImmutableMap;
65
import graphql.Internal;
@@ -30,9 +29,10 @@
3029
*/
3130
@PublicApi
3231
@NullMarked
33-
public class Field extends AbstractNode<Field> implements Selection<Field>, SelectionSetContainer<Field>, DirectivesContainer<Field>, NamedNode<Field> {
32+
public class Field extends AbstractNode<Field>
33+
implements Selection<Field>, SelectionSetContainer<Field>, DirectivesContainer<Field>, NamedNode<Field> {
3434

35-
private final @Nullable String name;
35+
private final String name;
3636
private final @Nullable String alias;
3737
private final ImmutableList<Argument> arguments;
3838
private final NodeUtil.DirectivesHolder directives;
@@ -42,17 +42,16 @@ public class Field extends AbstractNode<Field> implements Selection<Field>, Sele
4242
public static final String CHILD_DIRECTIVES = "directives";
4343
public static final String CHILD_SELECTION_SET = "selectionSet";
4444

45-
4645
@Internal
47-
protected Field(@Nullable String name,
48-
@Nullable String alias,
49-
List<Argument> arguments,
50-
List<Directive> directives,
51-
@Nullable SelectionSet selectionSet,
52-
@Nullable SourceLocation sourceLocation,
53-
List<Comment> comments,
54-
IgnoredChars ignoredChars,
55-
Map<String, String> additionalData) {
46+
protected Field(String name,
47+
@Nullable String alias,
48+
List<Argument> arguments,
49+
List<Directive> directives,
50+
@Nullable SelectionSet selectionSet,
51+
@Nullable SourceLocation sourceLocation,
52+
List<Comment> comments,
53+
IgnoredChars ignoredChars,
54+
Map<String, String> additionalData) {
5655
super(sourceLocation, comments, ignoredChars, additionalData);
5756
this.name = name;
5857
this.alias = alias;
@@ -61,7 +60,6 @@ protected Field(@Nullable String name,
6160
this.selectionSet = selectionSet;
6261
}
6362

64-
6563
/**
6664
* alternative to using a Builder for convenience
6765
*
@@ -124,24 +122,22 @@ public NodeChildrenContainer getNamedChildren() {
124122

125123
@Override
126124
public Field withNewChildren(NodeChildrenContainer newChildren) {
127-
return transform(builder ->
128-
builder.arguments(newChildren.getChildren(CHILD_ARGUMENTS))
129-
.directives(newChildren.getChildren(CHILD_DIRECTIVES))
130-
.selectionSet(newChildren.getChildOrNull(CHILD_SELECTION_SET))
131-
);
125+
return transform(builder -> builder.arguments(newChildren.getChildren(CHILD_ARGUMENTS))
126+
.directives(newChildren.getChildren(CHILD_DIRECTIVES))
127+
.selectionSet(newChildren.getChildOrNull(CHILD_SELECTION_SET)));
132128
}
133129

134130
@Override
135131
public String getName() {
136-
return assertNotNull(name, () -> "name cannot be null");
132+
return name;
137133
}
138134

139135
public @Nullable String getAlias() {
140136
return alias;
141137
}
142138

143139
public String getResultKey() {
144-
return alias != null ? alias : assertNotNull(name, () -> "name cannot be null");
140+
return alias != null ? alias : name;
145141
}
146142

147143
public List<Argument> getArguments() {
@@ -173,7 +169,6 @@ public boolean hasDirective(String directiveName) {
173169
return selectionSet;
174170
}
175171

176-
177172
@Override
178173
public boolean isEqualTo(@Nullable Node o) {
179174
if (this == o) {
@@ -198,8 +193,7 @@ public Field deepCopy() {
198193
getSourceLocation(),
199194
getComments(),
200195
getIgnoredChars(),
201-
getAdditionalData()
202-
);
196+
getAdditionalData());
203197
}
204198

205199
@Override
@@ -262,7 +256,6 @@ private Builder(Field existing) {
262256
this.additionalData = copyOf(existing.getAdditionalData());
263257
}
264258

265-
266259
public Builder sourceLocation(@Nullable SourceLocation sourceLocation) {
267260
this.sourceLocation = sourceLocation;
268261
return this;
@@ -319,9 +312,9 @@ public Builder additionalData(String key, String value) {
319312
return this;
320313
}
321314

322-
323315
public Field build() {
324-
return new Field(name, alias, arguments, directives, selectionSet, sourceLocation, comments, ignoredChars, additionalData);
316+
return new Field(assertNotNull(name), alias, arguments, directives, selectionSet, sourceLocation, comments,
317+
ignoredChars, additionalData);
325318
}
326319
}
327320
}

‎src/main/java/graphql/language/FieldDefinition.java‎

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

3-
43
import com.google.common.collect.ImmutableList;
54
import graphql.Internal;
65
import graphql.PublicApi;
@@ -24,8 +23,9 @@
2423

2524
@PublicApi
2625
@NullMarked
27-
public class FieldDefinition extends AbstractDescribedNode<FieldDefinition> implements DirectivesContainer<FieldDefinition>, NamedNode<FieldDefinition> {
28-
private final @Nullable String name;
26+
public class FieldDefinition extends AbstractDescribedNode<FieldDefinition>
27+
implements DirectivesContainer<FieldDefinition>, NamedNode<FieldDefinition> {
28+
private final String name;
2929
private final @Nullable Type type;
3030
private final ImmutableList<InputValueDefinition> inputValueDefinitions;
3131
private final NodeUtil.DirectivesHolder directives;
@@ -35,15 +35,15 @@ public class FieldDefinition extends AbstractDescribedNode<FieldDefinition> impl
3535
public static final String CHILD_DIRECTIVES = "directives";
3636

3737
@Internal
38-
protected FieldDefinition(@Nullable String name,
39-
@Nullable Type type,
40-
List<InputValueDefinition> inputValueDefinitions,
41-
List<Directive> directives,
42-
@Nullable Description description,
43-
@Nullable SourceLocation sourceLocation,
44-
List<Comment> comments,
45-
IgnoredChars ignoredChars,
46-
Map<String, String> additionalData) {
38+
protected FieldDefinition(String name,
39+
@Nullable Type type,
40+
List<InputValueDefinition> inputValueDefinitions,
41+
List<Directive> directives,
42+
@Nullable Description description,
43+
@Nullable SourceLocation sourceLocation,
44+
List<Comment> comments,
45+
IgnoredChars ignoredChars,
46+
Map<String, String> additionalData) {
4747
super(sourceLocation, comments, ignoredChars, additionalData, description);
4848
this.name = name;
4949
this.type = type;
@@ -52,7 +52,7 @@ protected FieldDefinition(@Nullable String name,
5252
}
5353

5454
public FieldDefinition(String name,
55-
Type type) {
55+
Type type) {
5656
this(name, type, emptyList(), emptyList(), null, null, emptyList(), IgnoredChars.EMPTY, emptyMap());
5757
}
5858

@@ -62,7 +62,7 @@ public Type getType() {
6262

6363
@Override
6464
public String getName() {
65-
return assertNotNull(name, () -> "name cannot be null");
65+
return name;
6666
}
6767

6868
public List<InputValueDefinition> getInputValueDefinitions() {
@@ -112,8 +112,7 @@ public FieldDefinition withNewChildren(NodeChildrenContainer newChildren) {
112112
return transform(builder -> builder
113113
.type(newChildren.getChildOrNull(CHILD_TYPE))
114114
.inputValueDefinitions(newChildren.getChildren(CHILD_INPUT_VALUE_DEFINITION))
115-
.directives(newChildren.getChildren(CHILD_DIRECTIVES))
116-
);
115+
.directives(newChildren.getChildren(CHILD_DIRECTIVES)));
117116
}
118117

119118
@Override
@@ -194,7 +193,6 @@ private Builder(FieldDefinition existing) {
194193
this.additionalData = new LinkedHashMap<>(existing.getAdditionalData());
195194
}
196195

197-
198196
public Builder sourceLocation(@Nullable SourceLocation sourceLocation) {
199197
this.sourceLocation = sourceLocation;
200198
return this;
@@ -230,7 +228,6 @@ public Builder inputValueDefinition(InputValueDefinition inputValueDefinition) {
230228
return this;
231229
}
232230

233-
234231
@Override
235232
public Builder directives(List<Directive> directives) {
236233
this.directives = ImmutableList.copyOf(directives);
@@ -257,9 +254,9 @@ public Builder additionalData(String key, String value) {
257254
return this;
258255
}
259256

260-
261257
public FieldDefinition build() {
262-
return new FieldDefinition(name, type, inputValueDefinitions, directives, description, sourceLocation, comments, ignoredChars, additionalData);
258+
return new FieldDefinition(assertNotNull(name), type, inputValueDefinitions, directives, description,
259+
sourceLocation, comments, ignoredChars, additionalData);
263260
}
264261
}
265262
}

0 commit comments

Comments
 (0)