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

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

Introduction

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

Prototype

boolean isProtected();

Source Link

Usage

From source file:com.ait.ext4j.rebind.BeanModelGenerator.java

License:Apache License

protected void addGetters(JClassType cls, List<JMethod> methods) {
    if (cls == null) {
        return;/*from   w w w. j  a  va 2  s.  c  o m*/
    }
    // ignore methods of Object
    if (cls.isInterface() != null || cls.getSuperclass() != null) {
        addGetters(cls.getSuperclass(), methods);
        for (JMethod m : cls.getMethods()) {
            if (m.isPublic() || m.isProtected()) {
                String name = m.getName();
                if ((name.matches("get.*") || name.matches("is.*")) && m.getParameters().length == 0) {
                    methods.add(m);
                }
            }
        }
    }

}

From source file:com.ait.ext4j.rebind.BeanModelGenerator.java

License:Apache License

protected void addSetters(JClassType cls, List<JMethod> methods) {
    if (cls.getSuperclass() != null) {
        addSetters(cls.getSuperclass(), methods);
    }/*from w w  w  .ja v a  2s .c  o  m*/
    for (JMethod m : cls.getMethods()) {
        if (m.isPublic() || m.isProtected()) {
            String name = m.getName();
            if (name.matches("set.*") && m.getParameters().length == 1) {
                methods.add(m);
            }
        }
    }
}

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. ja v  a  2  s  .  com*/
        return PUBLIC_VISIBILITY;
}

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  ww w .ja va2 s.co  m*/

    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 w  ww .  j av a 2  s  . c o  m*/

    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.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory.java

License:Apache License

private void writeOnStateChangeHandlers(TreeLogger logger, SplittingSourceWriter w, ConnectorBundle bundle)
        throws UnableToCompleteException {
    Map<JClassType, Set<JMethod>> needsOnStateChangeHandler = bundle.getNeedsOnStateChangeHandler();
    for (Entry<JClassType, Set<JMethod>> entry : needsOnStateChangeHandler.entrySet()) {
        JClassType connector = entry.getKey();

        TreeLogger typeLogger = logger.branch(Type.DEBUG,
                "Generating @OnStateChange support for " + connector.getName());

        // Build map to speed up error checking
        HashMap<String, Property> stateProperties = new HashMap<String, Property>();
        JClassType stateType = ConnectorBundle.findInheritedMethod(connector, "getState").getReturnType()
                .isClassOrInterface();//from   w ww .j a va 2  s. com
        for (Property property : bundle.getProperties(stateType)) {
            stateProperties.put(property.getName(), property);
        }

        for (JMethod method : entry.getValue()) {
            TreeLogger methodLogger = typeLogger.branch(Type.DEBUG, "Processing method " + method.getName());

            if (method.isPublic() || method.isProtected()) {
                methodLogger.log(Type.ERROR,
                        "@OnStateChange is only supported for methods with private or default visibility.");
                throw new UnableToCompleteException();
            }

            OnStateChange onStateChange = method.getAnnotation(OnStateChange.class);

            String[] properties = onStateChange.value();

            if (properties.length == 0) {
                methodLogger.log(Type.ERROR, "There are no properties to listen to");
                throw new UnableToCompleteException();
            }

            // Verify that all properties do exist
            for (String propertyName : properties) {
                if (!stateProperties.containsKey(propertyName)) {
                    methodLogger.log(Type.ERROR, "State class has no property named " + propertyName);
                    throw new UnableToCompleteException();
                }
            }

            if (method.getParameters().length != 0) {
                methodLogger.log(Type.ERROR, "Method should accept zero parameters");
                throw new UnableToCompleteException();
            }

            // new OnStateChangeMethod(Class declaringClass, String
            // methodName, String[], properties)
            w.print("store.addOnStateChangeMethod(%s, new %s(", getClassLiteralString(connector),
                    OnStateChangeMethod.class.getName());
            if (!connector.equals(method.getEnclosingType())) {
                w.print("%s, ", getClassLiteralString(method.getEnclosingType()));
            }
            w.print("\"%s\", ", method.getName());

            w.print("new String[] {");
            for (String propertyName : properties) {
                w.print("\"%s\", ", propertyName);
            }
            w.print("}");

            w.println("));");

            w.splitIfNeeded();
        }
    }
}

From source file:cz.muni.ucn.opsi.wui.gwt.rebind.beanModel.BeanModelGenerator.java

License:Open Source License

protected void addGetters(JClassType cls, List<JMethod> methods) {

    // ignore methods of Object
    if (cls.getSuperclass() != null) {
        addGetters(cls.getSuperclass(), methods);
        for (JMethod m : cls.getMethods()) {
            if (m.isPublic() || m.isProtected()) {
                String name = m.getName();
                if ((name.matches("get.*") || name.matches("is.*")) && m.getParameters().length == 0) {
                    methods.add(m);/* w  ww.  j  av  a  2 s  . com*/
                }
            }
        }
    }

}

From source file:org.cruxframework.crux.core.utils.JClassUtils.java

License:Apache License

/**
 * Generates a property get block. First try to get the field directly, then try to use a javabean getter method.
 * @param clazz class where the property will be searched.
 * @param propertyName property name//from  w  w  w .  ja v  a2 s  . co  m
 * @param parentVariable the name of the parent variable to use in generated expression
 * @param allowProtected if this expression allow protected fields and methods access
 * @return an expression in the form {@code <parentVar>.<propertyAccessor>}
 */
public static String getFieldValueGet(JClassType clazz, String propertyName, String parentVariable,
        boolean allowProtected) {
    JMethod jMethod = JClassUtils.getMethod(clazz, JClassUtils.getGetterMethod(propertyName, clazz),
            new JType[] {});
    if (jMethod != null && (jMethod.isPublic() || (allowProtected && jMethod.isProtected()))) {
        return (parentVariable + "." + jMethod.getName() + "()");
    }
    JField field = getField(clazz, propertyName);

    if (field.isPublic() || (allowProtected && field.isProtected())) {
        return parentVariable + "." + field.getName();
    }

    throw new CruxGeneratorException("Property [" + propertyName
            + "] could not be created. It is not visible neither has a getter/setter method.");
}

From source file:rocket.generator.rebind.gwt.JMethodMethodAdapter.java

License:Apache License

protected Visibility createVisibility() {
    Visibility visibility = null;
    while (true) {
        final JMethod method = this.getJMethod();
        if (method.isPrivate()) {
            visibility = Visibility.PRIVATE;
            break;
        }/*from  w  w w.  jav  a2  s  .  co m*/
        if (method.isDefaultAccess()) {
            visibility = Visibility.PACKAGE_PRIVATE;
            break;
        }
        if (method.isProtected()) {
            visibility = Visibility.PROTECTED;
            break;
        }
        if (method.isPublic()) {
            visibility = Visibility.PUBLIC;
            break;
        }
        Checker.fail("Unknown visibility for field " + method);
    }
    return visibility;
}

From source file:ru.fly.shared.bean.BeanGenerator.java

License:Apache License

protected void addField(JClassType cls, Set<String> getters, Set<String> setters) {
    if (cls == null) {
        return;/* www  .  j a  va  2 s .c om*/
    }
    // ignore methods of Object
    if (cls.isInterface() != null || cls.getSuperclass() != null) {
        addField(cls.getSuperclass(), getters, setters);
        for (JMethod m : cls.getMethods()) {
            if (m.isPublic() || m.isProtected()) {
                String name = m.getName();
                if ((name.matches("get.*") || name.matches("is.*")) && m.getParameters().length == 0) {
                    if (name.startsWith("get"))
                        name = name.replaceFirst("get", "");
                    else if (name.startsWith("is"))
                        name = name.replaceFirst("is", "");
                    getters.add(name.substring(0, 1).toLowerCase() + name.substring(1));
                } else if (name.matches("set.*") && m.getParameters().length == 1) {
                    name = name.replaceFirst("set", "");
                    setters.add(name.substring(0, 1).toLowerCase() + name.substring(1));
                }
            }
        }
    }
}