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

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

Introduction

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

Prototype

JMethod findMethod(String name, JType[] paramTypes);

Source Link

Usage

From source file:com.github.ludorival.dao.gwt.rebind.EntityManagerGenerator.java

License:Apache License

private boolean isHidden(JMethod method, JClassType interfaz) {
    if (interfaz == null)
        return false;
    return interfaz.findMethod(method.getName(), method.getParameterTypes()) != null;
}

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

License:Apache License

public AutoBeanFactoryModel(TreeLogger logger, JClassType factoryType) throws UnableToCompleteException {
    this.logger = logger;
    oracle = factoryType.getOracle();/* w  w w  .  ja  v  a 2s .com*/
    autoBeanInterface = oracle.findType(AutoBean.class.getCanonicalName()).isGenericType();
    autoBeanFactoryInterface = oracle.findType(AutoBeanFactory.class.getCanonicalName()).isInterface();

    /*
     * We want to allow the user to override some of the useful Object methods,
     * so we'll extract them here.
     */
    JClassType objectType = oracle.getJavaLangObject();
    objectMethods = Arrays.asList(objectType.findMethod("equals", new JType[] { objectType }),
            objectType.findMethod("hashCode", EMPTY_JTYPE), objectType.findMethod("toString", EMPTY_JTYPE));

    // Process annotations
    {
        Category categoryAnnotation = factoryType.getAnnotation(Category.class);
        if (categoryAnnotation != null) {
            categoryTypes = new ArrayList<JClassType>(categoryAnnotation.value().length);
            processClassArrayAnnotation(categoryAnnotation.value(), categoryTypes);
        } else {
            categoryTypes = null;
        }

        noWrapTypes = new ArrayList<JClassType>();
        noWrapTypes.add(oracle.findType(AutoBean.class.getCanonicalName()));
        NoWrap noWrapAnnotation = factoryType.getAnnotation(NoWrap.class);
        if (noWrapAnnotation != null) {
            processClassArrayAnnotation(noWrapAnnotation.value(), noWrapTypes);
        }

        ExtraEnums extraEnumsAnnotation = factoryType.getAnnotation(ExtraEnums.class);
        if (extraEnumsAnnotation != null) {
            for (Class<?> clazz : extraEnumsAnnotation.value()) {
                JEnumType asEnum = oracle.findType(clazz.getCanonicalName()).isEnum();
                assert asEnum != null;
                for (JEnumConstant value : asEnum.getEnumConstants()) {
                    allEnumConstants.put(value, AutoBeanMethod.getEnumName(value));
                }
            }
        }
    }

    for (JMethod method : factoryType.getOverridableMethods()) {
        if (method.getEnclosingType().equals(autoBeanFactoryInterface)) {
            // Ignore methods in AutoBeanFactory
            continue;
        }

        JClassType returnType = method.getReturnType().isInterface();
        if (returnType == null) {
            poison("The return type of method %s is a primitive type", method.getName());
            continue;
        }

        // AutoBean<FooIntf> blah() --> beanType = FooIntf
        JClassType beanType = ModelUtils.findParameterizationOf(autoBeanInterface, returnType)[0];
        if (beanType.isInterface() == null) {
            poison("The %s parameterization is not an interface", beanType.getQualifiedSourceName());
            continue;
        }

        // AutoBean<FooIntf> blah(FooIntfSub foo) --> toWrap = FooIntfSub
        JClassType toWrap;
        if (method.getParameters().length == 0) {
            toWrap = null;
        } else if (method.getParameters().length == 1) {
            toWrap = method.getParameters()[0].getType().isClassOrInterface();
            if (!beanType.isAssignableFrom(toWrap)) {
                poison("The %s parameterization %s is not assignable from the delegate" + " type %s",
                        autoBeanInterface.getSimpleSourceName(), toWrap.getQualifiedSourceName());
                continue;
            }
        } else {
            poison("Unexpecetd parameters in method %s", method.getName());
            continue;
        }

        AutoBeanType autoBeanType = getAutoBeanType(beanType);

        // Must wrap things that aren't simple interfaces
        if (!autoBeanType.isSimpleBean() && toWrap == null) {
            if (categoryTypes != null) {
                poison("The %s parameterization is not simple and the following"
                        + " methods did not have static implementations:", beanType.getQualifiedSourceName());
                for (AutoBeanMethod missing : autoBeanType.getMethods()) {
                    if (missing.getAction().equals(JBeanMethod.CALL) && missing.getStaticImpl() == null) {
                        poison(missing.getMethod().getReadableDeclaration());
                    }
                }
            } else {
                poison("The %s parameterization is not simple, but the %s method"
                        + " does not provide a delegate", beanType.getQualifiedSourceName(), method.getName());
            }
            continue;
        }

        AutoBeanFactoryMethod.Builder builder = new AutoBeanFactoryMethod.Builder();
        builder.setAutoBeanType(autoBeanType);
        builder.setMethod(method);
        methods.add(builder.build());
    }

    while (!toCalculate.isEmpty()) {
        Set<JClassType> examine = toCalculate;
        toCalculate = new LinkedHashSet<JClassType>();
        for (JClassType beanType : examine) {
            getAutoBeanType(beanType);
        }
    }

    if (poisoned) {
        die("Unable to complete due to previous errors");
    }
}

From source file:com.guit.rebind.binder.GuitBinderGenerator.java

License:Apache License

/**
 * Retrieves the handler associated with the event.
 * /*ww w  . j  av a 2 s . co  m*/
 * @throws UnableToCompleteException
 */
protected JClassType getHandlerForEvent(JClassType eventType) throws UnableToCompleteException {
    return eventType.findMethod("getAssociatedType", new JType[0]).getReturnType().isParameterized()
            .getTypeArgs()[0];
}

From source file:com.gwtent.gen.GenUtils.java

License:Apache License

/**
 * Find a method, if not found in current classType, then find it in super class.
 * @param classType//  ww w.j a v  a  2s .  co  m
 * @param name
 * @param paramTypes
 * @return
 */
public static JMethod findMethod(JClassType classType, String name, JType[] paramTypes) {
    JMethod result = null;
    JClassType parent = classType;
    while (parent != null) {
        result = parent.findMethod(name, paramTypes);
        if (result != null)
            return result;

        parent = parent.getSuperclass();
    }

    return null;
}

From source file:com.gwtplatform.mvp.rebind.ProxyEventMethod.java

License:Apache License

private void ensureStaticGetTypeMethodExists(JClassType eventType) throws UnableToCompleteException {
    JMethod getTypeMethod = eventType.findMethod("getType", new JType[0]);
    if (getTypeMethod == null || !getTypeMethod.isStatic() || getTypeMethod.getParameters().length != 0) {
        logger.log(TreeLogger.ERROR, getErrorPrefix(eventType.getName())
                + ", but this event class does not have a static getType method with no parameters.");
        throw new UnableToCompleteException();
    }/*from w  w w . java  2s.  c om*/

    JClassType getTypeReturnType = getTypeMethod.getReturnType().isClassOrInterface();
    if (getTypeReturnType == null || !classCollection.gwtEventTypeClass.isAssignableFrom(getTypeReturnType)) {
        logger.log(TreeLogger.ERROR,
                getErrorPrefix(eventType.getName())
                        + ", but this event class getType() method does not return on object of type "
                        + ClassCollection.gwtEventTypeClassName);
        throw new UnableToCompleteException();
    }
}

From source file:com.hiramchirino.restygwt.rebind.JsonEncoderDecoderClassCreator.java

License:Apache License

/**
 * checks whether a getter or setter exists on the specified 
 * type or any of its super classes excluding Object.
 * /*from  w ww . jav a 2  s .  co  m*/
 * @param type
 * @param field
 * @param fieldName
 * @param isSetter
 * @return
 */
private boolean exists(JClassType type, JField field, String fieldName, boolean isSetter) {
    JType[] args = null;
    if (isSetter) {
        args = new JType[] { field.getType() };
    } else {
        args = new JType[] {};
    }

    if (null != type.findMethod(fieldName, args)) {
        return true;
    } else {
        try {
            JType objectType = find(Object.class);
            JClassType superType = type.getSuperclass();
            if (!objectType.equals(superType)) {
                return exists(superType, field, fieldName, isSetter);
            }
        } catch (UnableToCompleteException e) {
            //do nothing
        }
    }
    return false;
}

From source file:com.mvp4g.rebind.config.Mvp4gConfiguration.java

License:Apache License

void validateChildModules() throws InvalidMvp4gConfigurationException {

    Map<String, List<EventElement>> childModuleMap = new HashMap<String, List<EventElement>>();
    Map<JClassType, List<EventElement>> broadcastMap = new HashMap<JClassType, List<EventElement>>();

    // Add presenter that handles event
    List<EventElement> eventList = null;
    List<String> modulesToLoad;
    String broadcast;/*from w ww .j a v a  2  s  .c om*/
    JClassType type;
    for (EventElement event : events) {
        modulesToLoad = event.getForwardToModules();
        broadcast = event.getBroadcastTo();
        if (modulesToLoad != null) {
            for (String childModule : modulesToLoad) {
                eventList = childModuleMap.get(childModule);
                if (eventList == null) {
                    eventList = new ArrayList<EventElement>();
                    childModuleMap.put(childModule, eventList);
                }
                eventList.add(event);
            }
        }
        if (broadcast != null) {
            type = getType(event, broadcast);
            eventList = broadcastMap.get(type);
            if (eventList == null) {
                eventList = new ArrayList<EventElement>();
                broadcastMap.put(type, eventList);
            }
            eventList.add(event);
        }
    }

    JClassType moduleSuperClass = getType(null, Mvp4gModule.class.getCanonicalName());
    JClassType moduleType = null;

    String eventName = null;
    EventElement eventElt = null;
    String[] eventObjClasses = null;
    String childModuleClass = null;
    JClassType childEventBus = null;
    JClassType startPresenterType = null;
    JClassType startViewType = null;
    String startPresenterClass = null;
    JGenericType presenterGenType = getType(null, PresenterInterface.class.getCanonicalName()).isGenericType();
    JType[] noParam = new JType[0];
    for (ChildModuleElement childModule : childModules) {
        eventList = childModuleMap.remove(childModule.getName());
        childModuleClass = childModule.getClassName();
        moduleType = getType(childModule, childModuleClass);
        if (findPossibleModuleBroadcast(broadcastMap, childModule, moduleType) || (eventList != null)) {
            if (!moduleType.isAssignableTo(moduleSuperClass)) {
                throw new InvalidClassException(childModule, Mvp4gModule.class.getCanonicalName());
            }

            childEventBus = othersEventBusClassMap.get(childModuleClass);

            if (childEventBus != null && childEventBus.getAnnotation(Events.class).historyOnStart()) {
                throw new InvalidMvp4gConfigurationException(String
                        .format(Mvp4gConfiguration.HISTORY_ON_START_ONLY_FOR_ROOT, childEventBus.getName()));
            }

            if (childModule.isAutoDisplay()) {
                eventName = childModule.getEventToDisplayView();
                if ((eventName == null) || (eventName.length() == 0)) {
                    String error = String.format(MISSING_ATTRIBUTE, module.getQualifiedSourceName(),
                            childModule.getClassName());
                    throw new InvalidMvp4gConfigurationException(error);
                }
                // verify event exists
                eventElt = getElement(eventName, events, childModule);
                eventObjClasses = eventElt.getEventObjectClass();
                if ((eventObjClasses == null) || (eventObjClasses.length != 1)) {
                    throw new InvalidMvp4gConfigurationException(
                            String.format(WRONG_NUMBER_ATT, eventElt.getType()));
                }

                startPresenterClass = childEventBus.getAnnotation(Events.class).startPresenter()
                        .getCanonicalName();

                if (startPresenterClass.equals(NoStartPresenter.class.getCanonicalName())) {
                    throw new InvalidMvp4gConfigurationException(
                            String.format(NO_START_PRESENTER, childModule.getClassName()));
                }

                startPresenterType = oracle.findType(startPresenterClass)
                        .asParameterizationOf(presenterGenType);
                startViewType = (JClassType) startPresenterType.findMethod("getView", noParam).getReturnType();
                if (!startViewType.isAssignableTo(getType(eventElt, eventObjClasses[0]))) {
                    throw new InvalidMvp4gConfigurationException(String.format(WRONG_CHILD_LOAD_EVENT_OBJ,
                            childModule.getClassName(), eventElt.getType(),
                            startViewType.getQualifiedSourceName(), eventObjClasses[0]));
                }
            }
        } else {
            // this object is not used, could be used by one of the child
            // module so display a warning
            logger.log(Type.WARN,
                    String.format(CHILD_MODULE_NOT_USED, module.getName(), childModule.getName()));
        }
    }

    List<ChildModuleElement> siblings = getSiblings();
    List<String> siblingsToLoad;
    String siblingClassName;
    for (ChildModuleElement sibling : siblings) {
        siblingClassName = sibling.getClassName();
        eventList = childModuleMap.remove(siblingClassName);
        findPossibleSiblingBroadcast(broadcastMap, sibling);
        if (eventList != null) {
            for (EventElement event : eventList) {
                siblingsToLoad = event.getSiblingsToLoad();
                modulesToLoad = event.getForwardToModules();
                if (!siblingsToLoad.contains(siblingClassName)) {
                    siblingsToLoad.add(siblingClassName);
                }
                modulesToLoad.remove(siblingClassName);
            }
        }
    }

    ChildModuleElement currentModule = moduleParentEventBusClassMap.get(module.getQualifiedSourceName());
    if (currentModule != null) {
        String parentModuleClassName = currentModule.getParentModuleClass();
        findPossibleParentBroadcast(broadcastMap, currentModule, parentModuleClassName);
        Iterator<String> it = childModuleMap.keySet().iterator();
        String trueStr = Boolean.TRUE.toString();
        if (it.hasNext()) {
            String moduleName = it.next();
            if (parentModuleClassName.equals(moduleName)) {
                eventList = childModuleMap.remove(moduleName);
                for (EventElement event : eventList) {
                    event.getForwardToModules().remove(parentModuleClassName);
                    event.setForwardToParent(trueStr);
                }
            }
        }
    }

    // Missing child modules
    if (!childModuleMap.isEmpty()) {
        String next = childModuleMap.keySet().iterator().next();
        throw new InvalidMvp4gConfigurationException(
                String.format(UNKNOWN_MODULE, childModuleMap.get(next).get(0).getName(), next));
    }

}

From source file:com.smartgwt.rebind.BeanValueType.java

License:Open Source License

public BeanValueType(JType valueType, TypeOracle oracle) {
    this.valueType = valueType;
    this.oracle = oracle;

    JClassType classType = valueType.isClass();
    if (classType != null) {
        jsObjConstructor = classType// w  w  w  . j  a  va2s . c om
                .findConstructor(new JType[] { findType(com.google.gwt.core.client.JavaScriptObject.class) });

        isAbstract = classType.isAbstract();

        JMethod getRef = classType.findMethod("getOrCreateRef",
                new JType[] { findType(com.google.gwt.core.client.JavaScriptObject.class) });
        hasGetOrCreateRef = getRef != null && getRef.isStatic();
    }

    initializeBeanValueType();
    assert beanValueType != null;
    assert genericType != null;

    // If the constructor doesn't take an empty array, then check if it
    // wants a class literal (it's one or the other, or neither).
    if (!constructorTakesEmptyArray) {
        JConstructor noArgConstructor = beanValueType.findConstructor(new JType[] {});
        constructorTakesClassLiteral = noArgConstructor == null;
    }
}

From source file:com.totsp.gwt.freezedry.rebind.CustomFieldSerializerValidator.java

License:Apache License

/**
 * Returns a list of error messages associated with the custom field
 * serializer./*from  ww w.  j  a  va  2  s  .co m*/
 * 
 * @param streamReaderClass
 *          {@link com.google.gwt.user.client.rpc.SerializationStreamReader SerializationStreamReader}
 * @param streamWriterClass
 *          {@link com.google.gwt.user.client.rpc.SerializationStreamWriter SerializationStreamWriter}
 * @param serializer the class which performs the serialization
 * @param serializee the class being serialized
 * @return list of error messages, if any, associated with the custom field
 *         serializer
 */
public static List /* <String> */ validate(JClassType streamReaderClass, JClassType streamWriterClass,
        JClassType serializer, JClassType serializee) {
    List /* <String> */ reasons = new ArrayList/* <String> */();

    JMethod deserialize = serializer.findMethod("deserialize", new JType[] { streamReaderClass, serializee });
    if (!isValidCustomFieldSerializerMethod(deserialize, JPrimitiveType.VOID)) {
        reasons.add(
                MessageFormat.format(NO_DESERIALIZE_METHOD, new String[] { serializer.getQualifiedSourceName(),
                        streamReaderClass.getQualifiedSourceName(), serializee.getQualifiedSourceName() }));
    }

    JMethod serialize = serializer.findMethod("serialize", new JType[] { streamWriterClass, serializee });
    if (!isValidCustomFieldSerializerMethod(serialize, JPrimitiveType.VOID)) {
        reasons.add(
                MessageFormat.format(NO_SERIALIZE_METHOD, new String[] { serializer.getQualifiedSourceName(),
                        streamWriterClass.getQualifiedSourceName(), serializee.getQualifiedSourceName() }));
    }

    if (!serializee.isDefaultInstantiable()) {
        JMethod instantiate = serializer.findMethod("instantiate", new JType[] { streamReaderClass });
        if (!isValidCustomFieldSerializerMethod(instantiate, serializee)) {
            reasons.add(MessageFormat.format(NO_INSTANTIATE_METHOD,
                    new String[] { serializer.getQualifiedSourceName(), serializee.getQualifiedSourceName(),
                            streamReaderClass.getQualifiedSourceName() }));
        }
    }

    return reasons;
}

From source file:com.vaadin.server.widgetsetutils.metadata.ConnectorBundle.java

License:Apache License

private static Map<JType, JClassType> findCustomSerializers(TypeOracle oracle) throws NotFoundException {
    Map<JType, JClassType> serializers = new HashMap<JType, JClassType>();

    JClassType serializerInterface = oracle.findType(JSONSerializer.class.getName());
    JType[] deserializeParamTypes = new JType[] {
            oracle.findType(com.vaadin.client.metadata.Type.class.getName()),
            oracle.findType(JsonValue.class.getName()),
            oracle.findType(ApplicationConnection.class.getName()) };
    String deserializeMethodName = "deserialize";
    // Just test that the method exists
    serializerInterface.getMethod(deserializeMethodName, deserializeParamTypes);

    for (JClassType serializer : serializerInterface.getSubtypes()) {
        JMethod deserializeMethod = serializer.findMethod(deserializeMethodName, deserializeParamTypes);
        if (deserializeMethod == null) {
            continue;
        }//from   ww  w. ja  v a  2  s .co  m
        JType returnType = deserializeMethod.getReturnType();

        serializers.put(returnType, serializer);
    }
    return serializers;
}