private Object getPropertyViaGetterUsingPrefix(Object object, String prefix, MethodFinder methodFinder, DataFetchingEnvironment environment) throws NoSuchMethodException { String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); try { Method method = methodFinder.apply(object.getClass(), getterName); if (takesDataFetcherEnvironmentAsOnlyArgument(method)) { return method.invoke(object, environment); } else { return method.invoke(object); } } catch (IllegalAccessException | InvocationTargetException e) { throw new GraphQLException(e); } }
private Method findViaSetAccessible(Class aClass, String methodName) throws NoSuchMethodException { if (!USE_SET_ACCESSIBLE.get()) { throw new FastNoSuchMethodException(methodName); } String key = mkKey(aClass, propertyName); Method method = METHOD_CACHE.get(key); if (method != null) { return method; } Method[] declaredMethods = aClass.getDeclaredMethods(); Optional<Method> m = Arrays.stream(declaredMethods) .filter(mth -> methodName.equals(mth.getName())) .filter(mth -> hasZeroArgs(mth) || takesDataFetcherEnvironmentAsOnlyArgument(mth)) .sorted(mostMethodArgsFirst()) .findFirst(); if (m.isPresent()) { try { // few JVMs actually enforce this but it might happen method = m.get(); method.setAccessible(true); METHOD_CACHE.putIfAbsent(key, method); return method; } catch (SecurityException ignored) { } } throw new FastNoSuchMethodException(methodName); }
private Object getPropertyViaGetterUsingPrefix(Object object, String prefix, MethodFinder methodFinder, DataFetchingEnvironment environment) throws NoSuchMethodException { String getterName = prefix + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); try { Method method = methodFinder.apply(object.getClass(), getterName); if (takesDataFetcherEnvironmentAsOnlyArgument(method)) { return method.invoke(object, environment); } else { return method.invoke(object); } } catch (IllegalAccessException | InvocationTargetException e) { throw new GraphQLException(e); } }
private Method findViaSetAccessible(Class aClass, String methodName) throws NoSuchMethodException { if (!USE_SET_ACCESSIBLE.get()) { throw new FastNoSuchMethodException(methodName); } String key = mkKey(aClass, propertyName); Method method = METHOD_CACHE.get(key); if (method != null) { return method; } Method[] declaredMethods = aClass.getDeclaredMethods(); Optional<Method> m = Arrays.stream(declaredMethods) .filter(mth -> methodName.equals(mth.getName())) .filter(mth -> hasZeroArgs(mth) || takesDataFetcherEnvironmentAsOnlyArgument(mth)) .sorted(mostMethodArgsFirst()) .findFirst(); if (m.isPresent()) { try { // few JVMs actually enforce this but it might happen method = m.get(); method.setAccessible(true); METHOD_CACHE.putIfAbsent(key, method); return method; } catch (SecurityException ignored) { } } throw new FastNoSuchMethodException(methodName); }