예제 #1
0
 Annotation[] extractAnnotations(
     TreeLogger logger,
     JClassType type,
     JMethod ifaceMethod,
     JMethod classMethod,
     GeneratorContext ctx) {
   Map<Class<?>, Annotation> unique = new LinkedHashMap<Class<?>, Annotation>();
   // Prefer annotation on classes before interfaces.
   for (Annotation classAnno : classMethod.getAnnotations()) {
     unique.put(classAnno.annotationType(), classAnno);
   }
   // Transverse supertypes
   JClassType next = type.getSuperclass();
   while (next != null) {
     JMethod method = next.findMethod(ifaceMethod.getName(), ifaceMethod.getParameterTypes());
     if (method != null)
       for (Annotation classAnno : method.getAnnotations()) {
         unique.put(classAnno.annotationType(), classAnno);
       }
     next = next.getSuperclass();
   }
   for (Annotation ifaceAnno : ifaceMethod.getAnnotations()) {
     unique.put(ifaceAnno.annotationType(), ifaceAnno);
   }
   return unique.values().toArray(new Annotation[unique.size()]);
 }
예제 #2
0
  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;
      }
      JType returnType = deserializeMethod.getReturnType();

      serializers.put(returnType, serializer);
    }
    return serializers;
  }
예제 #3
0
  public static JMethod findInheritedMethod(JClassType type, String methodName, JType... params) {

    JClassType currentType = type;
    while (currentType != null) {
      JMethod method = currentType.findMethod(methodName, params);
      if (method != null) {
        return method;
      }
      currentType = currentType.getSuperclass();
    }

    JClassType[] interfaces = type.getImplementedInterfaces();
    for (JClassType iface : interfaces) {
      JMethod method = iface.findMethod(methodName, params);
      if (method != null) {
        return method;
      }
    }

    return null;
  }
예제 #4
0
 /**
  * @param srcWriter
  * @param type
  * @param parentVariable
  * @param added
  * @param iocContainerVariable
  * @param configurations
  */
 private static void injectFields(
     SourcePrinter srcWriter,
     JClassType type,
     String parentVariable,
     Set<String> added,
     String iocContainerVariable,
     Map<String, IocConfig<?>> configurations) {
   for (JField field : type.getFields()) {
     String fieldName = field.getName();
     if (!added.contains(fieldName)) {
       added.add(fieldName);
       JType fieldType = field.getType();
       if ((fieldType.isPrimitive() == null)) {
         String injectionExpression =
             getFieldInjectionExpression(field, iocContainerVariable, configurations);
         if (injectionExpression != null) {
           if (JClassUtils.isPropertyVisibleToWrite(type, field, false)) {
             if (JClassUtils.hasSetMethod(field, type)) {
               String setterMethodName =
                   "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
               JMethod method = type.findMethod(setterMethodName, new JType[] {field.getType()});
               if (method.getAnnotation(Inject.class)
                   == null) // Annotated methods are handled apart
               {
                 srcWriter.println(
                     fieldType.getQualifiedSourceName()
                         + " field_"
                         + fieldName
                         + " = "
                         + injectionExpression
                         + ";");
                 srcWriter.println(
                     parentVariable + "." + setterMethodName + "(field_" + fieldName + ");");
               }
             } else {
               srcWriter.println(
                   parentVariable + "." + fieldName + " = " + injectionExpression + ";");
             }
           } else {
             throw new IoCException(
                 "IoC Error Field ["
                     + field.getName()
                     + "] from class ["
                     + type.getQualifiedSourceName()
                     + "] is not a writeable property.");
           }
         }
       }
     }
   }
 }
 public static JMethod getConcreteTypeMethod(JClassType serializer) {
   return serializer.findMethod("concreteType", new JType[0]);
 }