Example usage for com.google.gwt.core.ext.typeinfo JClassType getOverloads

List of usage examples for com.google.gwt.core.ext.typeinfo JClassType getOverloads

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JClassType getOverloads.

Prototype

JMethod[] getOverloads(String name);

Source Link

Usage

From source file:com.google.web.bindery.autobean.gwt.rebind.model.AutoBeanFactoryModel.java

License:Apache License

/**
 * Find <code>Object __intercept(AutoBean&lt;?> bean, Object value);</code> in
 * the category types.//from w  w w . j a v a  2s.  co m
 */
private JMethod findInterceptor(JClassType beanType) {
    if (categoryTypes == null) {
        return null;
    }
    for (JClassType category : categoryTypes) {
        for (JMethod method : category.getOverloads("__intercept")) {
            // Ignore non-static, non-public methods
            // TODO: Implement visibleFrom() to allow package-protected categories
            if (!method.isStatic() || !method.isPublic()) {
                continue;
            }

            JParameter[] params = method.getParameters();
            if (params.length != 2) {
                continue;
            }
            if (!methodAcceptsAutoBeanAsFirstParam(beanType, method)) {
                continue;
            }
            JClassType value = params[1].getType().isClassOrInterface();
            if (value == null) {
                continue;
            }
            if (!oracle.getJavaLangObject().isAssignableTo(value)) {
                continue;
            }
            return method;
        }
    }
    return null;
}

From source file:com.google.web.bindery.autobean.gwt.rebind.model.AutoBeanFactoryModel.java

License:Apache License

/**
 * Search the category types for a static implementation of an interface
 * method. Given the interface method declaration:
 * /*from w w w.j a v a2  s .c  o m*/
 * <pre>
 * Foo bar(Baz baz);
 * </pre>
 * 
 * this will search the types in {@link #categoryTypes} for the following
 * method:
 * 
 * <pre>
 * public static Foo bar(AutoBean&lt;Intf> bean, Baz baz) {}
 * </pre>
 */
private JMethod findStaticImpl(JClassType beanType, JMethod method) {
    if (categoryTypes == null) {
        return null;
    }

    for (JClassType category : categoryTypes) {
        // One extra argument for the AutoBean
        JParameter[] methodParams = method.getParameters();
        int requiredArgs = methodParams.length + 1;
        overload: for (JMethod overload : category.getOverloads(method.getName())) {
            if (!overload.isStatic() || !overload.isPublic()) {
                // Ignore non-static, non-public methods
                continue;
            }

            JParameter[] overloadParams = overload.getParameters();
            if (overloadParams.length != requiredArgs) {
                continue;
            }

            if (!methodAcceptsAutoBeanAsFirstParam(beanType, overload)) {
                // Ignore if the first parameter is a primitive or not assignable
                continue;
            }

            // Match the rest of the parameters
            for (int i = 1; i < requiredArgs; i++) {
                JType methodType = methodParams[i - 1].getType();
                JType overloadType = overloadParams[i].getType();
                if (methodType.equals(overloadType)) {
                    // Match; exact, the usual case
                } else if (methodType.isClassOrInterface() != null && overloadType.isClassOrInterface() != null
                        && methodType.isClassOrInterface().isAssignableTo(overloadType.isClassOrInterface())) {
                    // Match; assignment-compatible
                } else {
                    // No match, keep looking
                    continue overload;
                }
            }
            return overload;
        }
    }
    return null;
}