Example usage for com.google.gwt.core.ext.typeinfo JMethod isPrivate

List of usage examples for com.google.gwt.core.ext.typeinfo JMethod isPrivate

Introduction

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

Prototype

boolean isPrivate();

Source Link

Usage

From source file:com.didactilab.gwt.phprpc.rebind.PhpTools.java

License:Apache License

public static String getPhpVisibility(JMethod method) {
    if (method.isPrivate())
        return PRIVATE_VISIBILITY;
    else if (method.isProtected())
        return PROTECTED_VISIBILITY;
    else//from w  w w  . j a  v  a2 s .  c  o  m
        return PUBLIC_VISIBILITY;
}

From source file:com.ekuefler.supereventbus.rebind.EventRegistrationWriter.java

License:Apache License

private void checkValidity(JClassType target, JMethod method) throws UnableToCompleteException {
    // General checks for all methods annotated with @Subscribe
    if (method.getParameterTypes().length != 1) {
        logger.log(Type.ERROR,/*  w ww . j a va  2 s  .c  o  m*/
                String.format("Method %s.%s annotated with @Subscribe must take exactly one argument.",
                        target.getName(), method.getName()));
        throw new UnableToCompleteException();
    } else if (method.isPrivate()) {
        logger.log(Type.ERROR, String.format("Method %s.%s annotated with @Subscribe must not be private.",
                target.getName(), method.getName()));
        throw new UnableToCompleteException();
    }

    if (method.getParameterTypes()[0].getQualifiedSourceName().equals(MultiEvent.class.getCanonicalName())) {
        // Checks specific to MultiEvents
        if (method.getParameters()[0].getAnnotation(EventTypes.class) == null) {
            logger.log(Type.ERROR,
                    String.format("MultiEvent in method %s.%s must be annotated with @EventTypes.",
                            target.getName(), method.getName()));
            throw new UnableToCompleteException();
        }

        // Ensure that no type is assignable to another type
        Class<?>[] classes = method.getParameters()[0].getAnnotation(EventTypes.class).value();
        for (Class<?> c1 : classes) {
            for (Class<?> c2 : classes) {
                if (c1 != c2 && c1.isAssignableFrom(c2)) {
                    logger.log(Type.ERROR,
                            String.format("The type %s is redundant with the type %s in method %s.%s.",
                                    c2.getSimpleName(), c1.getSimpleName(), target.getName(),
                                    method.getName()));
                    throw new UnableToCompleteException();
                }
            }
        }
    } else {
        // Checks for non-MultiEvents
        if (method.getParameters()[0].getAnnotation(EventTypes.class) != null) {
            logger.log(Type.ERROR,
                    String.format(
                            "@EventTypes must not be applied to a non-MultiEvent parameter in method %s.%s.",
                            target.getName(), method.getName()));
            throw new UnableToCompleteException();
        }
    }
}

From source file:com.github.nmorel.gwtjackson.rebind.property.PropertyProcessor.java

License:Apache License

private static boolean isGetterAutoDetected(RebindConfiguration configuration,
        PropertyAccessors propertyAccessors, BeanInfo info) {
    if (!propertyAccessors.getGetter().isPresent()) {
        return false;
    }//from  w  ww  . j  a v  a 2  s . c om

    for (Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS) {
        if (propertyAccessors.isAnnotationPresentOnGetter(annotation)) {
            return true;
        }
    }

    JMethod getter = propertyAccessors.getGetter().get();

    String methodName = getter.getName();
    JsonAutoDetect.Visibility visibility;
    if (methodName.startsWith("is") && methodName.length() > 2
            && JPrimitiveType.BOOLEAN.equals(getter.getReturnType().isPrimitive())) {

        // getter method for a boolean
        visibility = info.getIsGetterVisibility();
        if (Visibility.DEFAULT == visibility) {
            visibility = configuration.getDefaultIsGetterVisibility();
        }

    } else if (methodName.startsWith("get") && methodName.length() > 3) {

        visibility = info.getGetterVisibility();
        if (Visibility.DEFAULT == visibility) {
            visibility = configuration.getDefaultGetterVisibility();
        }

    } else {
        // no annotation on method and the method does not follow naming convention
        return false;
    }
    return isAutoDetected(visibility, getter.isPrivate(), getter.isProtected(), getter.isPublic(),
            getter.isDefaultAccess());
}

From source file:com.github.nmorel.gwtjackson.rebind.property.PropertyProcessor.java

License:Apache License

private static boolean isSetterAutoDetected(RebindConfiguration configuration,
        PropertyAccessors propertyAccessors, BeanInfo info) {
    if (!propertyAccessors.getSetter().isPresent()) {
        return false;
    }/*from  ww  w .  j a v a 2 s .c  om*/

    for (Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS) {
        if (propertyAccessors.isAnnotationPresentOnSetter(annotation)) {
            return true;
        }
    }

    JMethod setter = propertyAccessors.getSetter().get();

    String methodName = setter.getName();
    if (!methodName.startsWith("set") || methodName.length() <= 3) {
        // no annotation on method and the method does not follow naming convention
        return false;
    }

    JsonAutoDetect.Visibility visibility = info.getSetterVisibility();
    if (Visibility.DEFAULT == visibility) {
        visibility = configuration.getDefaultSetterVisibility();
    }
    return isAutoDetected(visibility, setter.isPrivate(), setter.isProtected(), setter.isPublic(),
            setter.isDefaultAccess());
}

From source file:com.google.gwt.testing.easygwtmock.rebind.MocksControlGenerator.java

License:Apache License

private Set<String> getMethodNames(String className, TreeLogger logger, TypeOracle typeOracle)
        throws UnableToCompleteException {

    JClassType baseClass = typeOracle.findType(className);
    if (baseClass == null) {
        logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + baseClass + "'", null);
        throw new UnableToCompleteException();
    }//w ww . j  a  v a  2  s. co m

    Set<String> result = new HashSet<String>();
    for (JMethod method : baseClass.getMethods()) {
        if (!method.isPrivate()) {
            result.add(method.getName());
        }
    }

    return result;
}

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

License:Apache License

private List<AutoBeanMethod> computeMethods(JClassType beanType) {
    List<JMethod> toExamine = new ArrayList<JMethod>();
    toExamine.addAll(Arrays.asList(beanType.getInheritableMethods()));
    toExamine.addAll(objectMethods);/*  w w  w .  ja v  a  2s.com*/
    List<AutoBeanMethod> toReturn = new ArrayList<AutoBeanMethod>(toExamine.size());
    for (JMethod method : toExamine) {
        if (method.isPrivate()) {
            // Ignore private methods
            continue;
        }
        AutoBeanMethod.Builder builder = new AutoBeanMethod.Builder();
        builder.setMethod(method);

        // See if this method shouldn't have its return type wrapped
        // TODO: Allow class return types?
        JClassType classReturn = method.getReturnType().isInterface();
        if (classReturn != null) {
            maybeCalculate(classReturn);
            if (noWrapTypes != null) {
                for (JClassType noWrap : noWrapTypes) {
                    if (noWrap.isAssignableFrom(classReturn)) {
                        builder.setNoWrap(true);
                        break;
                    }
                }
            }
        }

        // GET, SET, or CALL
        JBeanMethod action = JBeanMethod.which(method);
        builder.setAction(action);
        if (JBeanMethod.CALL.equals(action)) {
            JMethod staticImpl = findStaticImpl(beanType, method);
            if (staticImpl == null && objectMethods.contains(method)) {
                // Don't complain about lack of implementation for Object methods
                continue;
            }
            builder.setStaticImp(staticImpl);
        }

        AutoBeanMethod toAdd = builder.build();

        // Collect referenced enums
        if (toAdd.hasEnumMap()) {
            allEnumConstants.putAll(toAdd.getEnumMap());
        }

        // See if parameterizations will pull in more types
        if (toAdd.isCollection()) {
            maybeCalculate(toAdd.getElementType());
        } else if (toAdd.isMap()) {
            maybeCalculate(toAdd.getKeyType());
            maybeCalculate(toAdd.getValueType());
        }

        toReturn.add(toAdd);
    }
    return toReturn;
}

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

License:Apache License

protected void validateHandler(JMethod m, String name, String presenterName) throws UnableToCompleteException {
    if (m.isStatic()) {
        error("All event handlers must not be static. Found: %s.%s", presenterName, name);
    }// w  w  w .  ja v  a2s. co m

    if (m.isPrivate()) {
        error("All event handlers must not be private. Found: %s.%s", presenterName, name);
    }

    JPrimitiveType returnTypePrimitive = m.getReturnType().isPrimitive();
    if (returnTypePrimitive == null || !returnTypePrimitive.equals(JPrimitiveType.VOID)) {
        error("All event handlers should return void. Found: %s.%s", presenterName, name);
    }
}

From source file:com.jhickman.web.gwt.gxtuibinder.rebind.GxtHandlerEvaluator.java

License:Apache License

public void run(IndentedWriter writer, FieldManager fieldManager, String uiOwner, OwnerClass ownerClass,
        MortalLogger logger, TypeOracle oracle) throws UnableToCompleteException {

    for (JMethod method : getUiHandlers(ownerClass.getOwnerType())) {
        String boundMethod = method.getName();
        if (method.isPrivate()) {
            logger.die("Method '%s' cannot be private.", boundMethod);
        }/*from  w  ww  .j  a va  2 s.  co m*/

        // Retrieves both event and handler types.
        JParameter[] parameters = method.getParameters();
        if (parameters.length != 1) {
            logger.die("Method '%s' must have a single event parameter defined.", boundMethod);
        }
        JClassType eventType = parameters[0].getType().isClass();

        GxtUiHandler annotation = method.getAnnotation(GxtUiHandler.class);
        String eventTypeName = annotation.eventType().toString();
        if (eventTypeName == null) {
            logger.die("Parameter '%s' cannot be null.", "eventType");
        }

        String handlerVarName = HANDLER_BASE_NAME + (++varCounter);
        writeHandler(writer, uiOwner, handlerVarName, eventType, boundMethod, oracle);

        JClassType events = oracle.findType(GxtClassnameConstants.EVENTS);
        for (String objectName : annotation.uiField()) {
            writer.write("%s.addListener(%s.%s, %s);", objectName, events.getQualifiedSourceName(),
                    eventTypeName, handlerVarName);
        }
    }
}

From source file:de.csenk.gwt.commons.bean.rebind.observe.ObservableBeanModel.java

License:Apache License

/**
 * @param sourceType//from w w  w . ja va 2  s .  c o  m
 * @return
 */
private static Set<ObservableBeanMethodModel> modelMethods(JClassType sourceType) {
    final Set<ObservableBeanMethodModel> methods = Sets.newHashSet();

    for (JMethod method : sourceType.getMethods()) {
        if (method.isPrivate()) {
            continue; // Ignore private methods
        }

        final ObservableBeanMethodModel methodModel = ObservableBeanMethodModel.create(method);
        if (methodModel.getAction() == JBeanMethod.GET || methodModel.getAction() == JBeanMethod.SET) {
            methods.add(methodModel);
        }
    }

    return ImmutableSet.copyOf(methods);
}

From source file:fr.onevu.gwt.uibinder.rebind.HandlerEvaluator.java

License:Apache License

/**
 * Runs the evaluator in the given class according to the valid fields
 * extracted from the template (via attribute ui:field).
 * //www  .  j a  va  2  s  .  c  om
 * @param writer
 *          the writer used to output the results
 * @param fieldManager
 *          the field manager instance
 * @param uiOwner
 *          the name of the class evaluated here that owns the template
 */
public void run(IndentedWriter writer, FieldManager fieldManager, String uiOwner)
        throws UnableToCompleteException {

    // Iterate through all methods defined in the class.
    for (JMethod method : ownerClass.getUiHandlers()) {
        // Evaluate the method.
        String boundMethod = method.getName();
        if (method.isPrivate()) {
            logger.die("Method '%s' cannot be private.", boundMethod);
        }

        // Retrieves both event and handler types.
        JParameter[] parameters = method.getParameters();
        if (parameters.length != 1) {
            logger.die("Method '%s' must have a single event parameter defined.", boundMethod);
        }
        JClassType eventType = parameters[0].getType().isClass();
        if (eventType == null) {
            logger.die("Parameter type is not a class.");
        }

        JClassType handlerType = getHandlerForEvent(eventType);
        if (handlerType == null) {
            logger.die("Parameter '%s' is not an event (subclass of GwtEvent).", eventType.getName());
        }

        // Cool to add the handler in the output.
        String handlerVarName = HANDLER_BASE_NAME + (++varCounter);
        writeHandler(writer, uiOwner, handlerVarName, handlerType, eventType, boundMethod);

        // Adds the handler created above.
        UiHandler annotation = method.getAnnotation(UiHandler.class);
        for (String objectName : annotation.value()) {
            // Is the field object valid?
            FieldWriter fieldWriter = fieldManager.lookup(objectName);
            if (fieldWriter == null) {
                logger.die(("Method '%s' can not be bound. You probably missed ui:field='%s' "
                        + "in the template."), boundMethod, objectName);
            }
            JClassType objectType = fieldWriter.getInstantiableType();
            if (objectType.isGenericType() != null) {
                objectType = tryEnhancingTypeInfo(objectName, objectType);
            }

            // Retrieves the "add handler" method in the object.
            JMethod addHandlerMethodType = getAddHandlerMethodForObject(objectType, handlerType);
            if (addHandlerMethodType == null) {
                logger.die("Field '%s' does not have an 'add%s' method associated.", objectName,
                        handlerType.getName());
            }

            // Cool to tie the handler into the object.
            writeAddHandler(writer, fieldManager, handlerVarName, addHandlerMethodType.getName(), objectName);
        }
    }
}