File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
main/java/graphql/annotations/processor/util
test/java/graphql/annotations Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 1818
1919import java .lang .reflect .Constructor ;
2020import java .lang .reflect .InvocationTargetException ;
21+ import java .lang .reflect .Method ;
22+ import java .lang .reflect .Modifier ;
2123
2224/**
2325 * A package level helper in calling reflective methods and turning them into
2628public class ReflectionKit {
2729 public static <T > T newInstance (Class <T > clazz ) throws GraphQLAnnotationsException {
2830 try {
31+ try {
32+ Method getInstance = clazz .getMethod ("getInstance" , new Class <?>[0 ]);
33+ if (Modifier .isStatic (getInstance .getModifiers ()) && clazz .isAssignableFrom (getInstance .getReturnType ())) {
34+ return (T ) getInstance .invoke (null );
35+ }
36+ } catch (NoSuchMethodException e ) {
37+ // ignore, just call the constructor
38+ }
2939 return clazz .newInstance ();
30- } catch (InstantiationException | IllegalAccessException e ) {
40+ } catch (InstantiationException | InvocationTargetException | IllegalAccessException e ) {
3141 throw new GraphQLAnnotationsException ("Unable to instantiate class : " + clazz , e );
3242 }
3343 }
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ public void noResolver() {
6969
7070 public static class Resolver implements TypeResolver {
7171
72+ public static Resolver getInstance () {
73+ return new Resolver ();
74+ }
75+
7276 @ Override
7377 public GraphQLObjectType getType (TypeResolutionEnvironment env ) {
7478 try {
You can’t perform that action at this time.
0 commit comments