11/**
22 * Copyright 2016 Yurii Rashkovskii
3- *
3+ * <p>
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
7+ * <p>
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ * <p>
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2727import java .util .Map ;
2828
2929import static graphql .annotations .processor .util .NamingKit .toGraphqlName ;
30- import static graphql .annotations .processor .util .PrefixesUtil .createPrefix ;
30+ import static graphql .annotations .processor .util .PrefixesUtil .addPrefixToPropertyName ;
3131import static graphql .annotations .processor .util .ReflectionKit .constructNewInstance ;
3232import static graphql .annotations .processor .util .ReflectionKit .newInstance ;
3333
@@ -137,33 +137,30 @@ private Object buildArg(Type p, GraphQLType graphQLType, Object arg) {
137137 }
138138
139139 private Object getGraphQLFieldValue (Object source , String fieldName ) throws IllegalAccessException , NoSuchFieldException , InvocationTargetException {
140- Method method = getMethod (source .getClass (), fieldName , "" );
141- Method getMethod = getMethod (source .getClass (), fieldName , "get" );
142- Method isMethod = getMethod (source .getClass (), fieldName , "is" );
143- if (method != null ) {
144- return method .invoke (source );
145- } else if (getMethod != null ) {
146- return getMethod .invoke (source );
147- } else if (isMethod != null ) {
148- return isMethod .invoke (source );
149- } else {
150- Field field = getField (source .getClass (), fieldName );
151- if (field != null ) {
152- field .setAccessible (true );
153- return field .get (source );
154- } else {
155- throw new NoSuchFieldException ("No GraphQL field found" );
140+ String [] orderedPrefixes = new String []{"" , "get" , "is" };
141+ for (String orderedPrefix : orderedPrefixes ) {
142+ Method method = getMethod (source .getClass (), fieldName , orderedPrefix );
143+ if (method != null ) {
144+ return method .invoke (source );
156145 }
157146 }
147+
148+ Field field = getField (source .getClass (), fieldName );
149+ if (field != null ) {
150+ field .setAccessible (true );
151+ return field .get (source );
152+ } else {
153+ throw new NoSuchFieldException ("No GraphQL field found" );
154+ }
158155 }
159156
160157 private Method getMethod (Class <?> clazz , String name , String prefix ) {
161- String prefixedName = createPrefix (prefix , name );
158+ String prefixedName = addPrefixToPropertyName (prefix , name );
162159 Method method = null ;
163160 while (clazz != null && method == null ) {
164161 try {
165162 method = clazz .getDeclaredMethod (prefixedName );
166- } catch (Exception e ) {
163+ } catch (Exception ignored ) {
167164 }
168165 clazz = clazz .getSuperclass ();
169166 }
@@ -176,7 +173,7 @@ private Field getField(Class<?> clazz, String name) {
176173 while (clazz != null && field == null ) {
177174 try {
178175 field = clazz .getDeclaredField (name );
179- } catch (Exception e ) {
176+ } catch (Exception ignored ) {
180177 }
181178 clazz = clazz .getSuperclass ();
182179 }
0 commit comments