List of usage examples for com.google.gwt.core.ext.typeinfo JMethod isPublic
boolean isPublic();
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.ja v a 2 s.co 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 ww w . j a v a2s . c om 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.dom_distiller.client.JsTestEntryGenerator.java
License:Open Source License
public static void verifyTestSignature(TreeLogger logger, JClassType classType, JMethod method) throws UnableToCompleteException { if (!method.isPublic()) { logger.log(TreeLogger.ERROR, classType + "." + method.getName() + " should be public."); throw new UnableToCompleteException(); }//from www . j av a2 s . c o m if (method.getParameters().length != 0) { logger.log(TreeLogger.ERROR, classType + "." + method.getName() + " should not have any parameters."); 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; }// w w w . ja va 2 s . c o 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 w w . j a va 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.github.nmorel.gwtjackson.rebind.RebindConfiguration.java
License:Apache License
/** * Search a static method or constructor to instantiate the mapper and return a {@link String} calling it. */// w w w . java 2 s . c om private MapperInstance getInstance(JType mappedType, JClassType classType, boolean isSerializers) { int nbParam = 0; if (null != mappedType.isGenericType() && (!isSerializers || !typeOracle.isEnumSupertype(mappedType))) { nbParam = mappedType.isGenericType().getTypeParameters().length; } // we first look at static method for (JMethod method : classType.getMethods()) { // method must be public static, return the instance type and take no parameters if (method.isStatic() && null != method.getReturnType().isClassOrInterface() && classType.isAssignableTo(method.getReturnType().isClassOrInterface()) && method.getParameters().length == nbParam && method.isPublic()) { MapperType[] parameters = getParameters(mappedType, method, isSerializers); if (null == parameters) { continue; } return new MapperInstance(classType, method, parameters); } } // then we search the default constructor for (JConstructor constructor : classType.getConstructors()) { if (constructor.isPublic() && constructor.getParameters().length == nbParam) { MapperType[] parameters = getParameters(mappedType, constructor, isSerializers); if (null == parameters) { continue; } return new MapperInstance(classType, constructor, parameters); } } logger.log(Type.WARN, "Cannot instantiate the custom serializer/deserializer " + classType.getQualifiedSourceName() + ". It will be ignored"); return null; }
From source file:com.github.nmorel.gwtjackson.rebind.RebindConfiguration.java
License:Apache License
/** * Search a static method or constructor to instantiate the key mapper and return a {@link String} calling it. *///from w w w . j a v a2 s. c o m private MapperInstance getKeyInstance(JType mappedType, JClassType classType, boolean isSerializers) { int nbParam = 0; if (!isSerializers && typeOracle.isEnumSupertype(mappedType)) { nbParam = 1; } // we first look at static method for (JMethod method : classType.getMethods()) { // method must be public static, return the instance type and take no parameters if (method.isStatic() && null != method.getReturnType().isClassOrInterface() && classType.isAssignableTo(method.getReturnType().isClassOrInterface()) && method.getParameters().length == nbParam && method.isPublic()) { MapperType[] parameters = getParameters(mappedType, method, isSerializers); if (null == parameters) { continue; } return new MapperInstance(classType, method, parameters); } } // then we search the default constructor for (JConstructor constructor : classType.getConstructors()) { if (constructor.isPublic() && constructor.getParameters().length == nbParam) { MapperType[] parameters = getParameters(mappedType, constructor, isSerializers); if (null == parameters) { continue; } return new MapperInstance(classType, constructor, parameters); } } logger.log(Type.WARN, "Cannot instantiate the custom key serializer/deserializer " + classType.getQualifiedSourceName() + ". It will be ignored"); return null; }
From source file:com.google.web.bindery.autobean.gwt.rebind.model.AutoBeanFactoryModel.java
License:Apache License
/** * Find <code>Object __intercept(AutoBean<?> bean, Object value);</code> in * the category types./*from w w w.j ava 2 s . c om*/ */ 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 . ja va 2s . 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<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; }
From source file:com.googlecode.gwtx.rebind.PropertyDescriptorsGenerator.java
License:Apache License
/** * Lookup any public method in the type to match JavaBeans accessor convention * @param type/*from w w w. j a va2 s .c o m*/ * @return Collection of javabean properties */ protected Collection<Property> lookupJavaBeanPropertyAccessors(TreeLogger logger, JClassType type) { Map<String, Property> properties = new HashMap<String, Property>(); JMethod[] methods = type.getMethods(); for (JMethod method : methods) { if (!method.isPublic() || method.isStatic()) { continue; } if (method.getName().startsWith("set") && method.getParameters().length == 1) { String name = Introspector.decapitalize(method.getName().substring(3)); String propertyType = null; JParameter[] parameters = method.getParameters(); if (parameters.length == 1) { JParameter parameter = parameters[0]; propertyType = parameter.getType().getErasedType().getQualifiedSourceName(); } else { logger.log(Type.WARN, "Property '" + name + "' has " + parameters.length + " parameters: " + parameters + "!"); continue; } Property property = properties.get(name); if (property == null) { property = new Property(name); properties.put(name, property); } property.setter = method; if (property.propertyType == null) { property.propertyType = propertyType; } else if (!property.propertyType.equals(propertyType)) { logger.log(Type.WARN, "Property '" + name + "' has an invalid setter: " + propertyType + " was expected, " + property.propertyType + " found!"); continue; } } else if (method.getName().startsWith("get") && method.getParameters().length == 0) { String name = Introspector.decapitalize(method.getName().substring(3)); String propertyType = method.getReturnType().getErasedType().getQualifiedSourceName(); Property property = properties.get(name); if (property == null) { property = new Property(name); properties.put(name, property); } property.getter = method; if (property.propertyType == null) { property.propertyType = propertyType; } else if (!property.propertyType.equals(propertyType)) { logger.log(Type.WARN, "Property '" + name + "' has an invalid getter: " + propertyType + " was expected, " + property.propertyType + " found!"); continue; } } else if (method.getName().startsWith("is") && method.getParameters().length == 0) { String name = Introspector.decapitalize(method.getName().substring(2)); String propertyType = method.getReturnType().getErasedType().getQualifiedSourceName(); Property property = properties.get(name); if (property == null) { property = new Property(name); properties.put(name, property); } property.getter = method; if (property.propertyType == null) { property.propertyType = propertyType; } else if (!property.propertyType.equals(propertyType)) { logger.log(Type.WARN, "Property '" + name + "' has an invalid 'is' getter: " + propertyType + " was expected, " + property.propertyType + " found!"); continue; } } } return properties.values(); }