Calls a static method.
@param nativeClass The java class.
@param method The method to call.
@param returnType The return type.
@param args The method arguments.
@param <T> Return type.
@return Return value.
503082
@Nullable
    protected static <T> T jsiiStaticCall(final Class<?> nativeClass, final String method, final Class<T> returnType, @Nullable final Object... args) {
        String fqn = engine.loadModuleForClass(nativeClass);
        return JsiiObjectMapper.treeToValue(engine.getClient()
                                                  .callStaticMethod(fqn, method, JsiiObjectMapper.valueToTree(args)),
                                            returnType);
    }
655696
protected JSONArray callMethod(String method, Object ... args) throws Exception {
        return new QueryBuilder().retrieveResult(storedId).call(method, args).storeResult("LAST_" + getStoredId()).execute();
    }
952364
public static void callMethod(final Object obj, final String methodName, final Object... args) {
		try {
			callMethod(obj, methodName, false, args);
		} catch (InvocationTargetException e) {
			JK.throww(e);
		}
	}
803543
protected <T> T invokeJavascriptReturnValue(String function, Class<T> returnType) {
        Object returnObject = invokeJavascript(function);
        if (returnObject instanceof JSObject) {
            try {
                Constructor<T> constructor = returnType.getConstructor(JSObject.class);
                return constructor.newInstance((JSObject) returnObject);
            } catch (Exception ex) {
                throw new IllegalStateException(ex);
            }
        } else {
            return (T) returnObject;
        }
    }
411525
public static TypeName extractReturnType(final SQLiteModelMethod method) {
		SQLiteEntity daoEntity = method.getParent().getEntity();
		// if true, field must be associate to ben attributes
		TypeName returnTypeName = method.getReturnClass();
		TypeName result = null;

		if (TypeUtility.isTypeIncludedIn(returnTypeName, Void.class, Void.TYPE)) {
			// return VOID (in the parameters must be a listener)

			// case OnReadBeanListener
			Pair<String, TypeName> foundElement = SqlBuilderHelper.searchInEachParameter(method,
					new SqlBuilderHelper.OnParameterListener() {

						@Override
						public boolean onParameter(Pair<String, TypeName> item) {
							return (item.value1 instanceof ParameterizedTypeName && TypeUtility.isEquals(
									((ParameterizedTypeName) item.value1).rawType, OnReadBeanListener.class.getName()));
						}
					});

			if (foundElement != null) {
				result = ((ParameterizedTypeName) foundElement.value1).typeArguments.get(0);
			}
		} else if (TypeUtility.isTypeIncludedIn(returnTypeName, Cursor.class)) {
			// return Cursor (no listener)
			result = null;
		} else if (returnTypeName instanceof ParameterizedTypeName) {
			ParameterizedTypeName returnParameterizedTypeName = (ParameterizedTypeName) returnTypeName;
			ClassName returnParameterizedClassName = returnParameterizedTypeName.rawType;

			// return List (no listener)
			AssertKripton.assertTrueOrInvalidMethodSignException(returnParameterizedTypeName.typeArguments.size() == 1,
					method, "return type %s is not supported", returnTypeName);
			TypeName elementName = returnParameterizedTypeName.typeArguments.get(0);

			Class<?> wrapperClazz = null;
			try {
				wrapperClazz = Class.forName(returnParameterizedClassName.toString());
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
				throw (new KriptonClassNotFoundException(e));
			}
			if (PagedResultImpl.class.isAssignableFrom(wrapperClazz)
					|| Collection.class.isAssignableFrom(wrapperClazz)) {
				if (SQLTransformer.isSupportedJDKType(elementName) || TypeUtility.isByteArray(elementName)) {
					// scalar list
					result = null;
				} else {
					result = elementName;
				}

			} else {
				result = null;
			}

		} else if (TypeUtility.isEquals(returnTypeName, daoEntity)) {
			// return one element (no listener)
			result = null;
		} else if (SQLTransformer.isSupportedJDKType(returnTypeName) || TypeUtility.isByteArray(returnTypeName)) {
			// return single value string, int, long, short, double, float,
			// String (no listener)
			result = null;
		} else {
			result = returnTypeName;
		}

		if (result == null || TypeUtility.isEquals(result, daoEntity)) {
			return null;
		} else {
			return result;
		}
	}
894240
public static <T> Object callMethod(Object obj,
                                        Class<T> c,
                                        String name,
                                        Class<?>[] classes,
                                        Object[] args) {
        try {
            Method m = getMethod(c, name, classes);
            return m.invoke(obj, args);
        } catch(InvocationTargetException e) {
            throw getCause(e);
        } catch(IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }
853836
static <T extends Annotation> T findAnnotation(Method method, Class<T> clazz) {
		T annotation = AnnotationUtils.findAnnotation(method, clazz);
		if (annotation == null) {
			try {
				annotation = AnnotationUtils.findAnnotation(method.getDeclaringClass()
						.getMethod(method.getName(), method.getParameterTypes()), clazz);
			}
			catch (NoSuchMethodException | SecurityException ex) {
				if (log.isDebugEnabled()) {
					log.debug("Exception occurred while tyring to find the annotation",
							ex);
				}
			}
		}
		return annotation;
	}
1318444
public static Method[] candidateMethods(Method[] methods, Class<?>[] argTypes) {
        return candidates(methods, collectSignatures(methods), collectVarArgs(methods), argTypes);
    }
1042418
static Method findMethod(Class<?> clazz, String methodName,
            Class<?>[] paramTypes, Object[] paramValues) {

        if (clazz == null || methodName == null) {
            throw new MethodNotFoundException(
                    message(null, "util.method.notfound", clazz, methodName,
                    paramString(paramTypes)));
        }

        if (paramTypes == null) {
            paramTypes = getTypesFromValues(paramValues);
        }

        Method[] methods = clazz.getMethods();

        List<Wrapper> wrappers = Wrapper.wrap(clazz, methods, methodName);

        Wrapper result = findWrapper(
                clazz, wrappers, methodName, paramTypes, paramValues);

        if (result == null) {
            return null;
        }
        return getMethod(clazz, (Method) result.unWrap());
    }
893066
@SuppressWarnings( "unchecked" )
    public static <T> Class<T> returnedClass(Class<?> type)
    {
        ParameterizedType parameterizedType = (ParameterizedType) type.getGenericSuperclass();
        return (Class<T>) parameterizedType.getActualTypeArguments()[0];
    }
1136444
private static boolean validateReturnType(Method method, Class<?> expected) {
    Class<?> returnType = method.getReturnType();
    if (returnType == void.class) {
      return false;
    }
    if (returnType != expected) {
      String expectedType = "'" + expected.getName() + "'";
      if (expected != void.class) {
        expectedType = "'void' or " + expectedType;
      }
      throw new IllegalStateException(method.getDeclaringClass().getName()
          + "."
          + method.getName()
          + " must have return type of "
          + expectedType);
    }
    return true;
  }
568009
public static Object invoke(Class<?> returnType, String className, String methodName) {
    // If we have an explicit implementation for this method, invoke it
    if (STUB_METHODS.containsKey(new ClassAndMethod(className, methodName))) {
      return STUB_METHODS.get(new ClassAndMethod(className, methodName)).invoke();
    }

    // Otherwise return an appropriate basic type
    if (returnType == String.class) {
      return "";
    } else if (returnType == Boolean.class) {
      return false;
    } else if (returnType == Byte.class) {
      return (byte) 0;
    } else if (returnType == Character.class) {
      return (char) 0;
    } else if (returnType == Double.class) {
      return (double) 0;
    } else if (returnType == Integer.class) {
      return (int) 0;
    } else if (returnType == Float.class) {
      return (float) 0;
    } else if (returnType == Long.class) {
      return (long) 0;
    } else if (returnType == Short.class) {
      return (short) 0;
    } else {
      return Mockito.mock(returnType, new ReturnsCustomMocks());
    }
  }
1096805
private static TypeName annotatedReturnType(ExecutableElement method) {
    TypeMirror returnType = method.getReturnType();
    List<AnnotationSpec> annotations =
        returnType.getAnnotationMirrors().stream()
            .map(AnnotationSpec::get)
            .collect(toList());
    return TypeName.get(returnType).annotated(annotations);
  }
1117147
public static void validateReturnType(Method method, Class<? extends Annotation> annotationType,
                                          Class<?> expectedReturnType) {
        if (!method.getReturnType().equals(expectedReturnType)) {
            throw new BeanCreationException("Method " + method.getName() + " annotated with @"
                  + annotationType.getName() + " must have a return type of "
                  + expectedReturnType.getName());
        }
    }
350583
public static <T> T invoke(String className, String methodName, Object[] args) {
		return invoke(className, methodName, false, args);
	}
858803
private static Class<?> findTypeFromGenericInArguments(final InvocationOnMock invocation, final TypeVariable returnType) {
        final Type[] parameterTypes = invocation.getMethod().getGenericParameterTypes();
        for (int i = 0; i < parameterTypes.length; i++) {
            Type argType = parameterTypes[i];
            if (returnType.equals(argType)) {
                Object argument = invocation.getArgument(i);

                if (argument == null) {
                    return null;
                }

                return argument.getClass();
            }
            if (argType instanceof GenericArrayType) {
                argType = ((GenericArrayType) argType).getGenericComponentType();
                if (returnType.equals(argType)) {
                    return invocation.getArgument(i).getClass();
                }
            }
        }
        return null;
    }
270911
@SuppressWarnings("unchecked")
    protected <T> T cast(Object arg, Class<T> type) {
        if (arg == null) {
            throw new NullPointerException("Argument is null");
        }
        if (!type.isInstance(arg)) {
            throw FormatException.illegalFormat(getFormatName(), arg.getClass());
        }
        return (T) arg;
    }