List of usage examples for com.google.gwt.core.ext.typeinfo JClassType getMethod
JMethod getMethod(String name, JType[] paramTypes) throws NotFoundException;
From source file:cc.alcina.framework.entity.gwtsynth.ClientReflectionGenerator.java
License:Apache License
public Set<Annotation> getSuperclassAnnotationsForMethod(JMethod m) { if (superMethodAnnotationMap.containsKey(m)) { return superMethodAnnotationMap.get(m); }// w w w . j a v a 2 s . c o m Map<Class, Annotation> uniqueMap = new HashMap<Class, Annotation>(); JClassType c = m.getEnclosingType(); Set<? extends JClassType> flattenedSupertypeHierarchy = c.getFlattenedSupertypeHierarchy(); for (JClassType jct : flattenedSupertypeHierarchy) { try { JMethod m2 = jct.getMethod(m.getName(), m.getParameterTypes()); for (Annotation a : getVisibleAnnotations(m2, visibleAnnotationClasses)) { if (!uniqueMap.containsKey(a.annotationType())) { uniqueMap.put(a.annotationType(), a); } } } catch (Exception e) { } } HashSet values = new HashSet(uniqueMap.values()); superMethodAnnotationMap.put(m, values); return values; }
From source file:com.github.gilbertotorrezan.gwtviews.rebind.PresenterGenerator.java
License:Open Source License
private String getInjectorMethod(TreeLogger logger, JClassType injector, String injectorMethod, String className) throws UnableToCompleteException { if (injectorMethod != null && !injectorMethod.isEmpty()) { try {/*from ww w . j a va 2 s . c om*/ injector.getMethod(injectorMethod, new JType[0]); } catch (NotFoundException e) { logger.log(Type.WARN, "The injector method \"" + injectorMethod + "\" was not found on class " + injector.getQualifiedSourceName()); //a compiler error will be trigged if the method really doesn't exist } return injectorMethod; } else { String methodName = null; JMethod[] methods = injector.getInheritableMethods(); for (JMethod method : methods) { JType returnType = method.getReturnType(); if (returnType.getQualifiedSourceName().equals(className)) { if (methodName != null) { logger.log(Type.ERROR, "The injector " + injector.getName() + " has more than one method with " + className + " as return type. Use the \"injectorMethod\" property to specify which one should be used."); throw new UnableToCompleteException(); } methodName = method.getName(); } } if (methodName == null) { logger.log(Type.INFO, "The injector " + injector.getName() + " has no methods with " + className + " as return type. The View will not be injected."); return null; } return methodName; } }
From source file:com.github.ludorival.dao.gwt.rebind.EntityManagerGenerator.java
License:Apache License
private JMethod getSetter(JClassType type, String getterSetter, JType argType) { if (type == null) return null; JMethod method = null;/* w ww . j a v a 2 s. c o m*/ try { method = type.getMethod("set" + getterSetter, new JType[] { argType }); } catch (Exception e) { JClassType superType = type.getSuperclass(); return getSetter(superType, getterSetter, argType); } return method; }
From source file:com.google.speedtracer.generators.BuildInfoGenerator.java
License:Apache License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { if (!typeName.equals(BUILD_INFO_QN)) { logger.log(TreeLogger.ERROR, "The type passed to GWT.create() must be " + BUILD_INFO_QN); throw new UnableToCompleteException(); }/*from ww w.j a v a 2 s . c o m*/ final TypeOracle typeOracle = context.getTypeOracle(); JClassType typeClass; try { typeClass = typeOracle.getType(typeName); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "Unable to find type: " + typeName); throw new UnableToCompleteException(); } JMethod revisionMethod; try { revisionMethod = typeClass.getMethod("getBuildRevision", new JType[0]); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, typeName + " does not have a method: int " + REVISION_METHOD_NAME + "()"); throw new UnableToCompleteException(); } JMethod timeMethod; try { timeMethod = typeClass.getMethod(TIME_METHOD_NAME, new JType[0]); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, typeName + " does not have a method: int " + TIME_METHOD_NAME + "()"); throw new UnableToCompleteException(); } return emitImplClass(logger, context, typeClass, revisionMethod, timeMethod); }
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; }/* ww w . j av a 2 s .c o m*/ JType returnType = deserializeMethod.getReturnType(); serializers.put(returnType, serializer); } return serializers; }
From source file:fr.onevu.gwt.uibinder.rebind.AbstractFieldWriter.java
License:Apache License
protected JMethod findMethod(JClassType type, String methodName) { // TODO Move this and getClassHierarchyBreadthFirst to JClassType for (JClassType nextType : UiBinderWriter.getClassHierarchyBreadthFirst(type)) { try {/*from w w w .j a v a2 s . co m*/ return nextType.getMethod(methodName, new JType[0]); } catch (NotFoundException e) { /* try parent */ } } return null; }
From source file:gwtBlocks.generators.BeanBindingModelGenerator.java
License:Apache License
private JMethod getMethod(JClassType classType, String methodName, JType[] args) throws UnableToCompleteException { try {//from w w w .j av a 2 s.co m return classType.getMethod(methodName, args); } catch (NotFoundException e) { if (classType.getSuperclass() != null) return getMethod(classType.getSuperclass(), methodName, args); else { _logger.log(TreeLogger.ERROR, "Method not found. Unable to find method " + methodName + " in " + classType + ". Check if property models conform to the naming conventions.", e); throw new UnableToCompleteException(); } } }
From source file:org.cruxframework.crux.core.utils.JClassUtils.java
License:Apache License
/** * /* www . j av a 2 s . c o m*/ * @param propertyName * @param baseClass * @return */ public static String getSetterMethod(String propertyName, JClassType baseClass, JType propertyType) { if (propertyName == null || propertyName.length() == 0) { return null; } String result = "" + Character.toUpperCase(propertyName.charAt(0)); result += propertyName.substring(1); if (propertyName.length() > 1) { try { baseClass.getMethod("set" + result, new JType[] { propertyType }); result = "set" + result; } catch (Exception e) { if (baseClass.getSuperclass() == null) { result = null; } else { result = getSetterMethod(propertyName, baseClass.getSuperclass(), propertyType); } } } return result; }
From source file:org.cruxframework.crux.core.utils.JClassUtils.java
License:Apache License
/** * Returns <code>true</code> is the given field has an associated public "get" method. * @param clazz/* w ww .j a v a 2 s .c o m*/ * @param field * @return */ public static boolean hasGetMethod(JField field, JClassType clazz) { String getterMethodName = "get" + Character.toUpperCase(field.getName().charAt(0)) + field.getName().substring(1); try { return (clazz.getMethod(getterMethodName, new JType[] {}) != null); } catch (Exception e) { try { getterMethodName = "is" + Character.toUpperCase(field.getName().charAt(0)) + field.getName().substring(1); return (clazz.getMethod(getterMethodName, new JType[] {}) != null); } catch (Exception e1) { if (clazz.getSuperclass() == null) { return false; } else { return hasGetMethod(field, clazz.getSuperclass()); } } } }
From source file:org.cruxframework.crux.core.utils.JClassUtils.java
License:Apache License
/** * Returns <code>true</code> is the given field has an associated public "set" method. * @param field/*from w w w . ja v a 2 s . co m*/ * @param clazz * @return */ public static boolean hasSetMethod(JField field, JClassType clazz) { String setterMethodName = "set" + Character.toUpperCase(field.getName().charAt(0)) + field.getName().substring(1); try { return (clazz.getMethod(setterMethodName, new JType[] { field.getType() }) != null); } catch (Exception e) { if (clazz.getSuperclass() == null) { return false; } else { return hasSetMethod(field, clazz.getSuperclass()); } } }