Skip to content

Commit ea9a015

Browse files
authored
Code health - IDEA suggestions and general tweaks (#767)
1 parent b451796 commit ea9a015

14 files changed

Lines changed: 25 additions & 29 deletions

src/main/java/graphql/analysis/QueryTraversal.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ private GraphQLObjectType getRootType() {
7676
}
7777
}
7878

79+
@SuppressWarnings("unchecked")
7980
public <T> T reducePostOrder(QueryReducer<T> queryReducer, T initialValue) {
8081
// compiler hack to make acc final and mutable :-)
8182
final Object[] acc = {initialValue};
8283
visitPostOrder((env) -> acc[0] = queryReducer.reduceField(env, (T) acc[0]));
8384
return (T) acc[0];
8485
}
8586

87+
@SuppressWarnings("unchecked")
8688
public <T> T reducePreOrder(QueryReducer<T> queryReducer, T initialValue) {
8789
// compiler hack to make acc final and mutable :-)
8890
final Object[] acc = {initialValue};

src/main/java/graphql/execution/AsyncSerialExecutionStrategy.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package graphql.execution;
22

33
import graphql.ExecutionResult;
4-
import graphql.ExecutionResultImpl;
54
import graphql.execution.instrumentation.InstrumentationContext;
65
import graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters;
76
import graphql.language.Field;
87

98
import java.util.ArrayList;
10-
import java.util.LinkedHashMap;
119
import java.util.List;
1210
import java.util.Map;
1311
import java.util.concurrent.CompletableFuture;
@@ -46,7 +44,7 @@ public CompletableFuture<ExecutionResult> execute(ExecutionContext executionCont
4644
BiConsumer<List<ExecutionResult>, Throwable> listThrowableBiConsumer = handleResults(executionContext, fieldNames, overallResult);
4745
resultsFuture.whenComplete(listThrowableBiConsumer);
4846

49-
executionStrategyCtx.onEnd(overallResult,null);
47+
executionStrategyCtx.onEnd(overallResult, null);
5048
return overallResult;
5149
}
5250

src/main/java/graphql/execution/ExecutionContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public Object getContext() {
8888
return context;
8989
}
9090

91+
@SuppressWarnings("unchecked")
9192
public <T> T getRoot() {
92-
//noinspection unchecked
9393
return (T) root;
9494
}
9595

src/main/java/graphql/execution/ExecutionStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,13 @@ protected Object unboxPossibleOptional(Object result) {
413413
*
414414
* @throws java.lang.ClassCastException if its not an Iterable
415415
*/
416+
@SuppressWarnings("unchecked")
416417
protected Iterable<Object> toIterable(Object result) {
417418
if (result.getClass().isArray()) {
418419
return IntStream.range(0, Array.getLength(result))
419420
.mapToObj(i -> Array.get(result, i))
420421
.collect(toList());
421422
}
422-
//noinspection unchecked
423423
return (Iterable<Object>) result;
424424
}
425425

@@ -504,6 +504,7 @@ protected CompletableFuture<ExecutionResult> completeValueForScalar(ExecutionCon
504504
return completedFuture(new ExecutionResultImpl(serialized, null));
505505
}
506506

507+
@SuppressWarnings("SameReturnValue")
507508
private Object handleCoercionProblem(ExecutionContext context, ExecutionStrategyParameters parameters, CoercingSerializeException e) {
508509
SerializationError error = new SerializationError(parameters.path(), e);
509510
log.warn(error.getMessage(), e);

src/main/java/graphql/execution/ValuesResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private Map<String, Argument> argumentMap(List<Argument> arguments) {
137137
}
138138

139139

140+
@SuppressWarnings("unchecked")
140141
private Object coerceValue(VariableDefinition variableDefinition, GraphQLType graphQLType, Object value) {
141142
if (graphQLType instanceof GraphQLNonNull) {
142143
Object returnValue = coerceValue(variableDefinition, ((GraphQLNonNull) graphQLType).getWrappedType(), value);
@@ -158,7 +159,6 @@ private Object coerceValue(VariableDefinition variableDefinition, GraphQLType gr
158159
return coerceValueForList(variableDefinition, (GraphQLList) graphQLType, value);
159160
} else if (graphQLType instanceof GraphQLInputObjectType) {
160161
if (value instanceof Map) {
161-
//noinspection unchecked
162162
return coerceValueForInputObjectType(variableDefinition, (GraphQLInputObjectType) graphQLType, (Map<String, Object>) value);
163163
} else {
164164
throw new CoercingParseValueException("Variables for GraphQLInputObjectType must be an instance of a Map according to the graphql specification. The offending object was a " + value.getClass().getName());

src/main/java/graphql/introspection/Introspection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public enum DirectiveLocation {
335335

336336
.build();
337337

338+
@SuppressWarnings("deprecation") // because graphql spec still has the deprecated fields
338339
public static GraphQLObjectType __Directive = newObject()
339340
.name("__Directive")
340341
.field(newFieldDefinition()

src/main/java/graphql/language/TypeDefinition.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import java.util.List;
5-
import java.util.Map;
65

76
public interface TypeDefinition extends Node, Definition {
87
/**
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package graphql.language;
22

33

4-
import java.util.ArrayList;
5-
import java.util.List;
6-
74
public class TypeExtensionDefinition extends ObjectTypeDefinition {
85
public TypeExtensionDefinition() {
96
super(null);
@@ -16,10 +13,10 @@ public TypeExtensionDefinition(String name) {
1613
@Override
1714
public String toString() {
1815
return "TypeExtensionDefinition{" +
19-
"name='" + getName() + '\'' +
20-
", implements=" + getImplements() +
21-
", directives=" + getDirectives() +
22-
", fieldDefinitions=" + getFieldDefinitions() +
23-
'}';
16+
"name='" + getName() + '\'' +
17+
", implements=" + getImplements() +
18+
", directives=" + getDirectives() +
19+
", fieldDefinitions=" + getFieldDefinitions() +
20+
'}';
2421
}
2522
}

src/main/java/graphql/schema/DataFetchingEnvironmentImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import graphql.Internal;
55
import graphql.execution.ExecutionId;
6-
import graphql.execution.ExecutionPath;
76
import graphql.execution.ExecutionTypeInfo;
87
import graphql.language.Field;
98
import graphql.language.FragmentDefinition;

src/main/java/graphql/schema/GraphQLDirective.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*
1919
* See http://graphql.org/learn/queries/#directives for more details on the concept.
2020
*/
21+
@SuppressWarnings("DeprecatedIsStillUsed") // because the graphql spec still has some of these deprecated fields
2122
@PublicApi
2223
public class GraphQLDirective {
2324

0 commit comments

Comments
 (0)