Java Code Examples for org.codehaus.groovy.runtime.MetaClassHelper#parametersAreCompatible()

The following examples show how to use org.codehaus.groovy.runtime.MetaClassHelper#parametersAreCompatible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaClassImpl.java    From groovy with Apache License 2.0 6 votes vote down vote up
protected static Object doChooseMostSpecificParams(String theClassName, String name, List matchingMethods, Class[] arguments, boolean checkParametersCompatible) {
    long matchesDistance = -1;
    LinkedList matches = new LinkedList();
    for (Object method : matchingMethods) {
        final ParameterTypes parameterTypes = (ParameterTypes) method;
        if (checkParametersCompatible && !MetaClassHelper.parametersAreCompatible(arguments, parameterTypes.getNativeParameterTypes()))
            continue;
        long dist = MetaClassHelper.calculateParameterDistance(arguments, parameterTypes);
        if (dist == 0) return method;
        matchesDistance = handleMatches(matchesDistance, matches, method, dist);
    }

    int size = matches.size();
    if (1 == size) {
        return matches.getFirst();
    }
    if (0 == size) {
        return null;
    }

    //more than one matching method found --> ambiguous!
    throw new GroovyRuntimeException(createErrorMessageForAmbiguity(theClassName, name, arguments, matches));
}
 
Example 2
Source File: ExpandoMetaClass.java    From groovy with Apache License 2.0 5 votes vote down vote up
private Method checkIfMethodExists(Class methodClass, String methodName, Class[] paramTypes, boolean staticMethod) {
    Method foundMethod = null;
    Method[] methods = methodClass.getMethods();
    for (Method method : methods) {
        if (method.getName().equals(methodName) && Modifier.isStatic(method.getModifiers()) == staticMethod) {
            if (MetaClassHelper.parametersAreCompatible(paramTypes, method.getParameterTypes())) {
                foundMethod = method;
                break;
            }
        }
    }
    return foundMethod;
}