Exemplo n.º 1
0
  @Override
  protected ItdTypeDetailsProvidingMetadataItem getMetadata(
      final String metadataIdentificationString,
      final JavaType aspectName,
      final PhysicalTypeMetadata governorPhysicalTypeMetadata,
      final String itdFilename) {
    // Acquire bean info (we need getters details, specifically)
    final JavaType javaType = JsonMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = JsonMetadata.getPath(metadataIdentificationString);

    // We need to parse the annotation, if it is not present we will simply
    // get the default annotation values
    final JsonAnnotationValues annotationValues =
        new JsonAnnotationValues(governorPhysicalTypeMetadata);

    String plural = javaType.getSimpleTypeName() + "s";
    final PluralMetadata pluralMetadata =
        (PluralMetadata) getMetadataService().get(PluralMetadata.createIdentifier(javaType, path));
    if (pluralMetadata != null) {
      plural = pluralMetadata.getPlural();
    }

    return new JsonMetadata(
        metadataIdentificationString,
        aspectName,
        governorPhysicalTypeMetadata,
        plural,
        annotationValues);
  }
 private MethodMetadataBuilder getCreateMethod(String declaredById, JavaType targetType) {
   InvocableMemberBodyBuilder invocableMemberBodyBuilder =
       InvocableMemberBodyBuilder.getInstance();
   invocableMemberBodyBuilder.append("return new " + targetType.getSimpleTypeName() + "();");
   MethodMetadataBuilder createMethodBuilder =
       new MethodMetadataBuilder(
           declaredById,
           Modifier.PUBLIC,
           new JavaSymbolName("create"),
           targetType,
           invocableMemberBodyBuilder);
   JavaType wildEntityType =
       new JavaType(
           targetType.getFullyQualifiedTypeName(),
           0,
           DataType.VARIABLE,
           JavaType.WILDCARD_EXTENDS,
           null);
   JavaType classParameterType =
       new JavaType(
           JavaType.CLASS.getFullyQualifiedTypeName(),
           0,
           DataType.TYPE,
           null,
           Arrays.asList(wildEntityType));
   createMethodBuilder.addParameter("clazz", classParameterType);
   return createMethodBuilder;
 }
Exemplo n.º 3
0
 public static JavaType convertPrimitiveType(final JavaType type, final boolean convertVoid) {
   if (!convertVoid && JavaType.VOID_PRIMITIVE.equals(type)) {
     return type;
   }
   if (type != null && type.isPrimitive()) {
     return new JavaType(type.getFullyQualifiedTypeName());
   }
   return type;
 }
  /** @return the find all method (may return null) */
  private MethodMetadata getFindAllMethod() {
    if ("".equals(crudAnnotationValues.getFindAllMethod())) {
      return null;
    }

    // Method definition to find or build
    final JavaSymbolName methodName =
        new JavaSymbolName(crudAnnotationValues.getFindAllMethod() + plural);
    final JavaType[] parameterTypes = {};
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    final JavaType returnType =
        new JavaType(
            LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(destination));

    // Locate user-defined method
    final MethodMetadata userMethod = getGovernorMethod(methodName, parameterTypes);
    if (userMethod != null) {
      Assert.isTrue(
          userMethod.getReturnType().equals(returnType),
          "Method '"
              + methodName
              + "' on '"
              + destination
              + "' must return '"
              + returnType.getNameIncludingTypeParameters()
              + "'");
      return userMethod;
    }

    // Create method
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    if (isGaeEnabled) {
      addTransactionalAnnotation(annotations);
    }

    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine(
        "return "
            + ENTITY_MANAGER_METHOD_NAME
            + "().createQuery(\"SELECT o FROM "
            + entityName
            + " o\", "
            + destination.getSimpleTypeName()
            + ".class).getResultList();");

    final MethodMetadataBuilder methodBuilder =
        new MethodMetadataBuilder(
            getId(),
            Modifier.PUBLIC | Modifier.STATIC,
            methodName,
            returnType,
            AnnotatedJavaType.convertFromJavaTypes(parameterTypes),
            parameterNames,
            bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    return methodBuilder.build();
  }
 private void maybeAddImport(
     final TemplateDataDictionary dataDictionary,
     final Set<String> importSet,
     final JavaType type) {
   if (!importSet.contains(type.getFullyQualifiedTypeName())) {
     addImport(dataDictionary, type.getFullyQualifiedTypeName());
     importSet.add(type.getFullyQualifiedTypeName());
   }
 }
Exemplo n.º 6
0
 public String getCollectionRenderer() {
   JavaType arg = OBJECT;
   if (type.getParameters().size() > 0) {
     arg = type.getParameters().get(0);
   }
   return GwtPath.SCAFFOLD_PLACE.packageName(topLevelPackage)
       + ".CollectionRenderer.of("
       + new GwtProxyProperty(topLevelPackage, ptmd, arg).getRenderer()
       + ")";
 }
 /**
  * Sets up the mock {@link RepositoryJpaLocator} and {@link PersistenceMemberLocator} to return a
  * mock repository for our test entity.
  */
 private void setUpMockRepository() {
   final ClassOrInterfaceTypeDetails mockRepositoryDetails =
       mock(ClassOrInterfaceTypeDetails.class);
   final FieldMetadata mockFieldMetadata = mock(FieldMetadata.class);
   final JavaType mockRepositoryType = mock(JavaType.class);
   when(mockRepositoryType.getSimpleTypeName()).thenReturn("ClinicRepo");
   when(mockIdType.getFullyQualifiedTypeName()).thenReturn(Long.class.getName());
   when(mockRepositoryDetails.getName()).thenReturn(mockRepositoryType);
   when(mockFieldMetadata.getFieldType()).thenReturn(mockIdType);
   when(mockRepositoryLocator.getRepositories(mockTargetEntity))
       .thenReturn(Arrays.asList(mockRepositoryDetails));
 }
Exemplo n.º 8
0
 private String getSetEditor() {
   String typeName = OBJECT.getFullyQualifiedTypeName();
   if (type.getParameters().size() > 0) {
     typeName = type.getParameters().get(0).getSimpleTypeName();
   }
   if (typeName.endsWith(GwtType.PROXY.getSuffix())) {
     typeName = typeName.substring(0, typeName.length() - GwtType.PROXY.getSuffix().length());
   }
   return typeName
       + (type.getSimpleTypeName().equals("Set")
           ? GwtType.SET_EDITOR.getSuffix()
           : GwtType.LIST_EDITOR.getSuffix());
 }
Exemplo n.º 9
0
 public String getSetValuePickerMethod() {
   return "\tpublic void "
       + getSetValuePickerMethodName()
       + "(Collection<"
       + (isCollection()
           ? type.getParameters().get(0).getSimpleTypeName()
           : type.getSimpleTypeName())
       + "> values) {\n"
       + "\t\t"
       + getName()
       + ".setAcceptableValues(values);\n"
       + "\t}\n";
 }
Exemplo n.º 10
0
  /**
   * Asserts that the given preferred mapping provided by the user gives rise to the expected folder
   * name and mapping to use in the annotation
   *
   * @param preferredMapping
   * @param expectedFolder
   * @param expectedMapping
   */
  private void assertFolderAndMapping(
      final String preferredMapping, final String expectedFolder, final String expectedMapping) {
    // Set up
    final JavaType mockController = mock(JavaType.class);
    when(mockController.getSimpleTypeName()).thenReturn("FooController");

    // Invoke
    final Pair<String, String> pair =
        JspOperationsImpl.getFolderAndMapping(preferredMapping, mockController);

    // Check
    assertEquals(expectedFolder, pair.getKey());
    assertEquals(expectedMapping, pair.getValue());
  }
Exemplo n.º 11
0
 public String getBinder() {
   if (type.equals(JavaType.DOUBLE_OBJECT)) {
     return "g:DoubleBox";
   }
   if (type.equals(LONG_OBJECT)) {
     return "g:LongBox";
   }
   if (type.equals(JavaType.INT_OBJECT)) {
     return "g:IntegerBox";
   }
   if (type.equals(JavaType.FLOAT_OBJECT)) {
     return "r:FloatBox";
   }
   if (type.equals(JavaType.BYTE_OBJECT)) {
     return "r:ByteBox";
   }
   if (type.equals(JavaType.SHORT_OBJECT)) {
     return "r:ShortBox";
   }
   if (type.equals(JavaType.CHAR_OBJECT)) {
     return "r:CharBox";
   }
   if (type.equals(BIG_DECIMAL)) {
     return "r:BigDecimalBox";
   }
   return isCollection()
       ? "a:" + getSetEditor()
       : isDate()
           ? "d:DateBox"
           : isBoolean() ? "g:CheckBox" : isString() ? "g:TextBox" : "g:ValueListBox";
 }
Exemplo n.º 12
0
  public void injectEmailTemplate(
      final JavaType targetType, final JavaSymbolName fieldName, final boolean async) {
    Assert.notNull(targetType, "Java type required");
    Assert.notNull(fieldName, "Field name required");

    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(AUTOWIRED));

    // Obtain the physical type and its mutable class details
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(targetType);
    ClassOrInterfaceTypeDetails existing = typeLocationService.findClassOrInterface(targetType);
    if (existing == null) {
      log.warning(
          "Aborting: Unable to find metadata for target type '"
              + targetType.getFullyQualifiedTypeName()
              + "'");
      return;
    }
    final ClassOrInterfaceTypeDetailsBuilder classOrInterfaceTypeDetailsBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(existing);

    // Add the MailSender field
    final FieldMetadataBuilder mailSenderFieldBuilder =
        new FieldMetadataBuilder(
            declaredByMetadataId, PRIVATE_TRANSIENT, annotations, fieldName, MAIL_SENDER);
    classOrInterfaceTypeDetailsBuilder.addField(mailSenderFieldBuilder.build());

    // Add the "sendMessage" method
    classOrInterfaceTypeDetailsBuilder.addMethod(
        getSendMethod(fieldName, async, declaredByMetadataId, classOrInterfaceTypeDetailsBuilder));
    typeManagementService.createOrUpdateTypeOnDisk(classOrInterfaceTypeDetailsBuilder.build());
  }
Exemplo n.º 13
0
 public static String getProxyRendererType(
     final JavaPackage topLevelPackage, final JavaType javaType) {
   return GwtType.EDIT_RENDERER.getPath().packageName(topLevelPackage)
       + "."
       + javaType.getSimpleTypeName()
       + "Renderer";
 }
  private void createIdentifierClass(final JavaType identifierType) {
    final List<AnnotationMetadataBuilder> identifierAnnotations =
        new ArrayList<AnnotationMetadataBuilder>();

    final AnnotationMetadataBuilder identifierBuilder =
        new AnnotationMetadataBuilder(ROO_IDENTIFIER);
    identifierBuilder.addBooleanAttribute(DB_MANAGED.getSymbolName(), true);
    identifierAnnotations.add(identifierBuilder);

    // Produce identifier itself
    final String declaredByMetadataId =
        PhysicalTypeIdentifier.createIdentifier(
            identifierType, projectOperations.getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(
            declaredByMetadataId,
            Modifier.PUBLIC | Modifier.FINAL,
            identifierType,
            PhysicalTypeCategory.CLASS);
    cidBuilder.setAnnotations(identifierAnnotations);
    typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());

    shell.flash(
        Level.FINE,
        "Created " + identifierType.getFullyQualifiedTypeName(),
        DbreDatabaseListenerImpl.class.getName());
    shell.flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());
  }
Exemplo n.º 15
0
 /**
  * Returns the {@link #WEB_RECEIVER} Java type, generically typed to the given type.
  *
  * @param genericType (required)
  * @return a non-<code>null</code> type
  */
 public static JavaType getReceiverType(final JavaType genericType) {
   return new JavaType(
       RECEIVER.getFullyQualifiedTypeName(),
       0,
       DataType.TYPE,
       null,
       Collections.singletonList(genericType));
 }
Exemplo n.º 16
0
 public boolean isPrimitive() {
   return type.isPrimitive()
       || isDate()
       || isString()
       || isBoolean()
       || type.equals(JavaType.DOUBLE_OBJECT)
       || type.equals(LONG_OBJECT)
       || type.equals(JavaType.INT_OBJECT)
       || type.equals(JavaType.FLOAT_OBJECT)
       || type.equals(JavaType.BYTE_OBJECT)
       || type.equals(JavaType.SHORT_OBJECT)
       || type.equals(JavaType.CHAR_OBJECT)
       || type.equals(BIG_DECIMAL);
 }
  /** {@inheritDoc} */
  public void annotateType(final JavaType type, final JavaPackage javaPackage) {
    // TODO check for existing controller

    // Use Roo's Assert type for null checks
    Validate.notNull(type, "Java type required");
    Validate.notNull(javaPackage, "Java package required, web mvc all command package required");

    // Obtain ClassOrInterfaceTypeDetails for this java type
    ClassOrInterfaceTypeDetails entityDetails = typeLocationService.getTypeDetails(type);

    // Test if the annotation already exists on the target type
    if (entityDetails != null
        && MemberFindingUtils.getAnnotationOfType(
                entityDetails.getAnnotations(), new JavaType(RooEnvers.class.getName()))
            == null) {
      ClassOrInterfaceTypeDetailsBuilder classOrInterfaceTypeDetailsBuilder =
          new ClassOrInterfaceTypeDetailsBuilder(entityDetails);

      // Create JavaType instance for the add-ons trigger annotation
      JavaType rooEnvers = new JavaType(RooEnvers.class.getName());

      // Create Annotation metadata
      AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(rooEnvers);

      // Add annotation to target type
      classOrInterfaceTypeDetailsBuilder.addAnnotation(annotationBuilder.build());

      // Save changes to disk
      typeManagementService.createOrUpdateTypeOnDisk(classOrInterfaceTypeDetailsBuilder.build());
    }

    // Get details for existing controller
    JavaType typeController =
        new JavaType(
            javaPackage.getFullyQualifiedPackageName()
                + "."
                + type.getSimpleTypeName()
                + "Controller");
    ClassOrInterfaceTypeDetails typeControllerDetails =
        typeLocationService.getTypeDetails(typeController);

    // Add annotation @RooEnversController to existing controller
    ClassOrInterfaceTypeDetailsBuilder classOrInterfaceTypeDetailsBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(typeControllerDetails);
    JavaType rooEnversController =
        new JavaType("de.eightbitboy.roo.envers.controller.RooEnversController");

    final List<AnnotationAttributeValue<?>> rooEnversControllerAttributes =
        new ArrayList<AnnotationAttributeValue<?>>();
    rooEnversControllerAttributes.add(new ClassAttributeValue(new JavaSymbolName("type"), type));

    AnnotationMetadataBuilder annotationBuilder =
        new AnnotationMetadataBuilder(rooEnversController, rooEnversControllerAttributes);
    classOrInterfaceTypeDetailsBuilder.addAnnotation(annotationBuilder.build());

    typeManagementService.createOrUpdateTypeOnDisk(classOrInterfaceTypeDetailsBuilder.build());
  }
Exemplo n.º 18
0
 /**
  * Returns the accessor name for the given field name and field type.
  *
  * @param fieldName the field name used to determine the accessor name
  * @param fieldType the field type
  * @return the accessor method name
  */
 public static JavaSymbolName getAccessorMethodName(
     final JavaSymbolName fieldName, final JavaType fieldType) {
   Validate.notNull(fieldName, "Field name required");
   Validate.notNull(fieldType, "Field type required");
   final String capitalizedFieldName = StringUtils.capitalize(fieldName.getSymbolName());
   return fieldType.equals(JavaType.BOOLEAN_PRIMITIVE)
       ? new JavaSymbolName("is" + capitalizedFieldName)
       : new JavaSymbolName("get" + capitalizedFieldName);
 }
Exemplo n.º 19
0
 private JavaType getCollectionImplementation(final JavaType javaType) {
   if (javaType.equals(SET)) {
     return new JavaType(
         HASH_SET.getFullyQualifiedTypeName(),
         javaType.getArray(),
         javaType.getDataType(),
         javaType.getArgName(),
         javaType.getParameters());
   }
   if (javaType.equals(LIST)) {
     return new JavaType(
         ARRAY_LIST.getFullyQualifiedTypeName(),
         javaType.getArray(),
         javaType.getDataType(),
         javaType.getArgName(),
         javaType.getParameters());
   }
   return javaType;
 }
Exemplo n.º 20
0
 public boolean isProxy() {
   return ptmd != null
       && !isDate()
       && !isString()
       && !isPrimitive()
       && !isEnum()
       && !isCollection()
       && !isEmbeddable()
       && !type.equals(OBJECT);
 }
  /**
   * Creates a new DBRE-managed entity from the given table
   *
   * @param javaType the name of the entity to be created (required)
   * @param table the table from which to create the entity (required)
   * @param activeRecord whether to create "active record" CRUD methods in the new entity
   * @return the newly created entity
   */
  private ClassOrInterfaceTypeDetails createNewManagedEntityFromTable(
      final JavaType javaType, final Table table, final boolean activeRecord) {
    // Create type annotations for new entity
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(ROO_JAVA_BEAN));
    annotations.add(new AnnotationMetadataBuilder(ROO_TO_STRING));

    // Find primary key from db metadata and add identifier attributes to
    // @RooJpaEntity
    final AnnotationMetadataBuilder jpaAnnotationBuilder =
        new AnnotationMetadataBuilder(activeRecord ? ROO_JPA_ACTIVE_RECORD : ROO_JPA_ENTITY);
    manageIdentifier(javaType, jpaAnnotationBuilder, new HashSet<JavaSymbolName>(), table);

    if (!hasVersionField(table)) {
      jpaAnnotationBuilder.addStringAttribute(VERSION_FIELD, "");
    }
    if (table.isDisableGeneratedIdentifiers()) {
      jpaAnnotationBuilder.addStringAttribute(SEQUENCE_NAME_FIELD, "");
    }

    jpaAnnotationBuilder.addStringAttribute("table", table.getName());
    if (!DbreModelService.NO_SCHEMA_REQUIRED.equals(table.getSchema().getName())) {
      jpaAnnotationBuilder.addStringAttribute("schema", table.getSchema().getName());
    }

    annotations.add(jpaAnnotationBuilder);

    // Add @RooDbManaged
    annotations.add(getRooDbManagedAnnotation());

    final JavaType superclass = OBJECT;
    final List<JavaType> extendsTypes = new ArrayList<JavaType>();
    extendsTypes.add(superclass);

    // Create entity class
    final String declaredByMetadataId =
        PhysicalTypeIdentifier.createIdentifier(
            javaType, projectOperations.getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA));
    final ClassOrInterfaceTypeDetailsBuilder cidBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(
            declaredByMetadataId, Modifier.PUBLIC, javaType, PhysicalTypeCategory.CLASS);
    cidBuilder.setExtendsTypes(extendsTypes);
    cidBuilder.setAnnotations(annotations);

    final ClassOrInterfaceTypeDetails entity = cidBuilder.build();
    typeManagementService.createOrUpdateTypeOnDisk(entity);

    shell.flash(
        Level.FINE,
        "Created " + javaType.getFullyQualifiedTypeName(),
        DbreDatabaseListenerImpl.class.getName());
    shell.flash(Level.FINE, "", DbreDatabaseListenerImpl.class.getName());

    return entity;
  }
 private MethodMetadataBuilder getIdMethod(
     String declaredById, JavaType targetType, MethodMetadata idAccessor) {
   InvocableMemberBodyBuilder invocableMemberBodyBuilder =
       InvocableMemberBodyBuilder.getInstance();
   invocableMemberBodyBuilder.append(
       "return "
           + StringUtils.uncapitalize(targetType.getSimpleTypeName())
           + "."
           + idAccessor.getMethodName()
           + "();");
   MethodMetadataBuilder getIdMethod =
       new MethodMetadataBuilder(
           declaredById,
           Modifier.PUBLIC,
           new JavaSymbolName("getId"),
           GwtUtils.convertPrimitiveType(idAccessor.getReturnType(), true),
           invocableMemberBodyBuilder);
   getIdMethod.addParameter(StringUtils.uncapitalize(targetType.getSimpleTypeName()), targetType);
   return getIdMethod;
 }
  @Override
  public boolean isNullRequiredVisibleForFieldNumber(ShellContext shellContext) {

    // Check if `notNull`is specified
    String notNullParam = shellContext.getParameters().get("notNull");
    if (notNullParam != null) {
      return false;
    }

    // Check if type is primitive
    String typeValue = shellContext.getParameters().get("type");
    if (StringUtils.isNotBlank(typeValue)) {
      JavaType numberType =
          getJavaTypeConverter().convertFromText(typeValue, JavaType.class, "java-number");
      if (numberType.isPrimitive()) {
        return false;
      }
    }
    return true;
  }
 private TemplateDataDictionary buildStandardDataDictionary(
     final GwtType type, final String moduleName) {
   final JavaType javaType = new JavaType(getFullyQualifiedTypeName(type, moduleName));
   final TemplateDataDictionary dataDictionary = TemplateDictionary.create();
   for (final GwtType reference : type.getReferences()) {
     addReference(dataDictionary, reference, moduleName);
   }
   dataDictionary.setVariable("className", javaType.getSimpleTypeName());
   dataDictionary.setVariable("packageName", javaType.getPackage().getFullyQualifiedPackageName());
   dataDictionary.setVariable(
       "placePackage",
       GwtPath.SCAFFOLD_PLACE.packageName(projectOperations.getTopLevelPackage(moduleName)));
   dataDictionary.setVariable(
       "sharedScaffoldPackage",
       GwtPath.SHARED_SCAFFOLD.packageName(projectOperations.getTopLevelPackage(moduleName)));
   dataDictionary.setVariable(
       "sharedGaePackage",
       GwtPath.SHARED_GAE.packageName(projectOperations.getTopLevelPackage(moduleName)));
   return dataDictionary;
 }
 private MethodMetadataBuilder getVersionMethod(
     String declaredById, JavaType targetType, MethodMetadata versionAccessor) {
   InvocableMemberBodyBuilder invocableMemberBodyBuilder =
       InvocableMemberBodyBuilder.getInstance();
   invocableMemberBodyBuilder.append(
       "return "
           + StringUtils.uncapitalize(targetType.getSimpleTypeName())
           + "."
           + versionAccessor.getMethodName()
           + "();");
   MethodMetadataBuilder getIdMethodBuilder =
       new MethodMetadataBuilder(
           declaredById,
           Modifier.PUBLIC,
           new JavaSymbolName("getVersion"),
           JavaType.OBJECT,
           invocableMemberBodyBuilder);
   getIdMethodBuilder.addParameter(
       StringUtils.uncapitalize(targetType.getSimpleTypeName()), targetType);
   return getIdMethodBuilder;
 }
Exemplo n.º 26
0
 public static JavaType convertGovernorTypeNameIntoKeyTypeName(
     final JavaType governorType, final GwtType type, final ProjectMetadata projectMetadata) {
   String destinationPackage = type.getPath().packageName(projectMetadata);
   String typeName;
   if (type.isMirrorType()) {
     String simple = governorType.getSimpleTypeName();
     typeName = destinationPackage + "." + simple + type.getSuffix();
   } else {
     typeName = destinationPackage + "." + type.getTemplate();
   }
   return new JavaType(typeName);
 }
Exemplo n.º 27
0
  public String getFormatter() {
    if (isCollectionOfProxy()) {
      return getCollectionRenderer() + ".render";
    } else if (isDate()) {
      return getDateTimeFormat() + ".format";
    } else if (type.equals(JavaType.INT_OBJECT)
        || type.equals(JavaType.FLOAT_OBJECT)
        || type.equals(JavaType.DOUBLE_OBJECT)
        || type.equals(BIG_INTEGER)
        || type.equals(BIG_DECIMAL)) {
      String formatter = "String.valueOf";
      if (annotations == null || annotations.isEmpty()) {
        return formatter;
      }

      AnnotationMetadata annotation =
          MemberFindingUtils.getAnnotationOfType(annotations, NUMBER_FORMAT);
      if (annotation != null) {
        AnnotationAttributeValue<?> attr = annotation.getAttribute(new JavaSymbolName("style"));
        if (attr != null) {
          String style = attr.getValue().toString();
          if ("org.springframework.format.annotation.NumberFormat.Style.CURRENCY".equals(style)) {
            formatter = "NumberFormat.getCurrencyFormat().format";
          } else if ("org.springframework.format.annotation.NumberFormat.Style.PERCENT"
              .equals(style)) {
            formatter = "NumberFormat.getPercentFormat().format";
          } else {
            formatter = "NumberFormat.getDecimalFormat().format";
          }
        } else {
          formatter = "NumberFormat.getDecimalFormat().format";
        }
      }
      return formatter;
    } else if (isProxy()) {
      return getProxyRendererType() + ".instance().render";
    } else {
      return "String.valueOf";
    }
  }
Exemplo n.º 28
0
 public String getRenderer() {
   return isCollection()
       ? getCollectionRenderer()
       : isDate()
           ? "new DateTimeFormatRenderer(" + getDateTimeFormat() + ")"
           : isPrimitive() || isEnum() || isEmbeddable() || type.equals(OBJECT)
               ? "new AbstractRenderer<"
                   + getType()
                   + ">() {\n        public String render("
                   + getType()
                   + " obj) {\n          return obj == null ? \"\" : String.valueOf(obj);\n        }\n      }"
               : getProxyRendererType() + ".instance()";
 }
Exemplo n.º 29
0
  public String forEditView() {
    String initializer = "";

    if (isBoolean()) {
      initializer = " = " + getCheckboxSubtype();
    }

    if (isEnum() && !isCollection()) {
      initializer =
          String.format(
              " = new ValueListBox<%s>(%s)", type.getFullyQualifiedTypeName(), getRenderer());
    }

    if (isProxy()) {
      initializer =
          String.format(
              " = new ValueListBox<%1$s>(%2$s.instance(), new com.google.web.bindery.requestfactory.gwt.ui.client.EntityProxyKeyProvider<%1$s>())",
              type.getFullyQualifiedTypeName(), getProxyRendererType());
    }

    return String.format("@UiField %s %s %s", getEditor(), getName(), initializer);
  }
 private boolean isNumberOrDate(JavaType fieldType) {
   return fieldType.equals(JavaType.DOUBLE_OBJECT)
       || fieldType.equals(JavaType.FLOAT_OBJECT)
       || fieldType.equals(JavaType.INT_OBJECT)
       || fieldType.equals(LONG_OBJECT)
       || fieldType.equals(JavaType.SHORT_OBJECT)
       || fieldType.getFullyQualifiedTypeName().equals(Date.class.getName())
       || fieldType.getFullyQualifiedTypeName().equals(Calendar.class.getName());
 }