public final List<AnnotationMetadata> buildAnnotations() { final List<AnnotationMetadata> result = new ArrayList<AnnotationMetadata>(); for (final AnnotationMetadataBuilder annotationBuilder : annotations) { result.add(annotationBuilder.build()); } return result; }
/** * Returns the metadata for the existing annotation, with no attribute * values * * @param annotationType the fully-qualified name of the annotation type * (required) * @return a non-<code>null</code> instance * @since 1.2.0 */ public static AnnotationMetadata getInstance(final String annotationType) { return new AnnotationMetadataBuilder(annotationType).build(); }
/** * Returns the metadata for the existing annotation, with no attribute * values * * @param annotationType the annotation type (required) * @return a non-<code>null</code> instance * @since 1.2.0 */ public static AnnotationMetadata getInstance(final Class<?> annotationType) { return new AnnotationMetadataBuilder(annotationType).build(); }
public static AnnotationMetadata getInstance(final JavaType annotationType) { return new AnnotationMetadataBuilder(annotationType).build(); }
public boolean updateTypeAnnotation(final AnnotationMetadataBuilder annotationBuilder) { return updateTypeAnnotation(annotationBuilder.build()); } }
@Override public AnnotationMetadata build() { final AnnotationMetadataBuilder annotationMetadataBuilder = new AnnotationMetadataBuilder(annotationType, attributeValues); final AnnotationMetadata md = annotationMetadataBuilder.build(); md.setCommentStructure(commentStructure); return md; }
private AnnotationMetadata getEmbeddableAnnotation() { if (governorTypeDetails.getAnnotation(EMBEDDABLE) != null) { return null; } final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(EMBEDDABLE); return annotationBuilder.build(); }
/** * Returns the metadata for an annotation of the given type if the governor * does not already have one. * * @param annotationType the type of annotation to generate (required) * @return <code>null</code> if the governor already has that annotation */ protected AnnotationMetadata getTypeAnnotation(final JavaType annotationType) { if (governorTypeDetails.getAnnotation(annotationType) != null) { return null; } return new AnnotationMetadataBuilder(annotationType).build(); }
/** * Generates the Springlets `@EntityFormat` annotation to be applied to the projection * * @return AnnotationMetadata */ private AnnotationMetadata getEntityFormatAnnotation() { String expressionAttribute = this.annotationValues.getFormatExpression(); String messageAttribute = this.annotationValues.getFormatMessage(); final AnnotationMetadataBuilder entityFormatBuilder = new AnnotationMetadataBuilder(SpringletsJavaType.SPRINGLETS_ENTITY_FORMAT); // Check for each attribute individually if (StringUtils.isNotBlank(expressionAttribute)) { entityFormatBuilder.addStringAttribute("value", expressionAttribute); } if (StringUtils.isNotBlank(messageAttribute)) { entityFormatBuilder.addStringAttribute("message", messageAttribute); } return entityFormatBuilder.build(); }
/** * Generates the Springlets `@EntityFormat` annotation to be applied to the dto * * @return AnnotationMetadata */ private AnnotationMetadata getEntityFormatAnnotation() { String expressionAttribute = this.annotationValues.getFormatExpression(); String messageAttribute = this.annotationValues.getFormatMessage(); final AnnotationMetadataBuilder entityFormatBuilder = new AnnotationMetadataBuilder(SpringletsJavaType.SPRINGLETS_ENTITY_FORMAT); // Check for each attribute individually if (StringUtils.isNotBlank(expressionAttribute)) { entityFormatBuilder.addStringAttribute("value", expressionAttribute); } if (StringUtils.isNotBlank(messageAttribute)) { entityFormatBuilder.addStringAttribute("message", messageAttribute); } return entityFormatBuilder.build(); }
/** * Generates the JPA @Table annotation to be applied to the entity * * @param annotationValues * @return */ private AnnotationMetadata getTableAnnotation() { final AnnotationMetadata tableAnnotation = getTypeAnnotation(TABLE); if (tableAnnotation == null) { return null; } final String catalog = annotationValues.getCatalog(); final String schema = annotationValues.getSchema(); final String table = annotationValues.getTable(); if (StringUtils.isNotBlank(table) || StringUtils.isNotBlank(schema) || StringUtils.isNotBlank(catalog)) { final AnnotationMetadataBuilder tableBuilder = new AnnotationMetadataBuilder(tableAnnotation); if (StringUtils.isNotBlank(catalog)) { tableBuilder.addStringAttribute("catalog", catalog); } if (StringUtils.isNotBlank(schema)) { tableBuilder.addStringAttribute("schema", schema); } if (StringUtils.isNotBlank(table)) { tableBuilder.addStringAttribute("name", table); } return tableBuilder.build(); } return null; }
/** * Generates the JPA @Entity annotation to be applied to the entity * * @return */ private AnnotationMetadata getEntityAnnotation() { AnnotationMetadata entityAnnotation = getTypeAnnotation(ENTITY); if (entityAnnotation == null) { return null; } if (StringUtils.isNotBlank(annotationValues.getEntityName())) { final AnnotationMetadataBuilder entityBuilder = new AnnotationMetadataBuilder(entityAnnotation); entityBuilder.addStringAttribute("name", annotationValues.getEntityName()); entityAnnotation = entityBuilder.build(); } return entityAnnotation; }
preauthorizeAnnotation.addStringAttribute("value", entry.getValue()); DeclaredMethodAnnotationDetails preauthorizeAnnotationInGetterMethod = new DeclaredMethodAnnotationDetails(entry.getKey(), preauthorizeAnnotation.build()); builder.addMethodAnnotation(preauthorizeAnnotationInGetterMethod);
/** * Generates the Springlets `@EntityFormat` annotation to be applied to the entity * * @return AnnotationMetadata */ private AnnotationMetadata getEntityFormatAnnotation() { AnnotationMetadata entityFormatAnnotation = getTypeAnnotation(SpringletsJavaType.SPRINGLETS_ENTITY_FORMAT); if (entityFormatAnnotation == null) { return null; } String expressionAttribute = this.annotationValues.getEntityFormatExpression(); String messageAttribute = this.annotationValues.getEntityFormatMessage(); final AnnotationMetadataBuilder entityFormatBuilder = new AnnotationMetadataBuilder(entityFormatAnnotation); // Check for each attribute individually if (StringUtils.isNotBlank(expressionAttribute)) { entityFormatBuilder.addStringAttribute("value", expressionAttribute); } if (StringUtils.isNotBlank(messageAttribute)) { entityFormatBuilder.addStringAttribute("message", messageAttribute); } entityFormatAnnotation = entityFormatBuilder.build(); return entityFormatAnnotation; }
/** * Returns the JPA @Inheritance annotation to be applied to the entity, if * applicable * * @param annotationValues the values of the {@link RooJpaEntity} annotation * (required) * @return <code>null</code> if it's already present or not required */ private AnnotationMetadata getInheritanceAnnotation() { if (governorTypeDetails.getAnnotation(INHERITANCE) != null) { return null; } if (StringUtils.isNotBlank(annotationValues.getInheritanceType())) { final AnnotationMetadataBuilder inheritanceBuilder = new AnnotationMetadataBuilder(INHERITANCE); inheritanceBuilder.addEnumAttribute("strategy", new EnumDetails(INHERITANCE_TYPE, new JavaSymbolName(annotationValues.getInheritanceType()))); return inheritanceBuilder.build(); } return null; }
private void processGaeAnnotations(final FieldMetadata field) { for (final AnnotationMetadata annotation : field.getAnnotations()) { if (annotation.getAnnotationType().equals(ONE_TO_ONE) || annotation.getAnnotationType().equals(MANY_TO_ONE) || annotation.getAnnotationType().equals(ONE_TO_MANY) || annotation.getAnnotationType().equals(MANY_TO_MANY)) { builder.addFieldAnnotation(new DeclaredFieldAnnotationDetails(field, new AnnotationMetadataBuilder(annotation.getAnnotationType()).build(), true)); builder.addFieldAnnotation(new DeclaredFieldAnnotationDetails(field, new AnnotationMetadataBuilder(TRANSIENT).build())); break; } } }
public void addEqualsAndHashCodeMethods(final JavaType javaType, final boolean appendSuper, final Set<String> excludeFields) { // Add @RooEquals annotation to class if not yet present final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(javaType); if (cid == null || cid.getTypeAnnotation(ROO_EQUALS) != null) { return; } final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_EQUALS); if (appendSuper) { annotationBuilder.addBooleanAttribute("appendSuper", appendSuper); } if (!CollectionUtils.isEmpty(excludeFields)) { final List<StringAttributeValue> attributes = new ArrayList<StringAttributeValue>(); for (final String excludeField : excludeFields) { attributes.add(new StringAttributeValue(new JavaSymbolName("value"), excludeField)); } annotationBuilder.addAttribute(new ArrayAttributeValue<StringAttributeValue>( new JavaSymbolName("excludeFields"), attributes)); } final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(cid); cidBuilder.addAnnotation(annotationBuilder.build()); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); } }
@Override public void addJpaAuditToEntity(JavaType entity, String createdDateColumn, String modifiedDateColumn, String createdByColumn, String modifiedByColumn) { // Getting entity details ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(entityDetails); // Add audit fields cidBuilder.addField(getCreatedDateField(entityDetails, createdDateColumn)); cidBuilder.addField(getModifiedDateField(entityDetails, modifiedDateColumn)); cidBuilder.addField(getCreatedByField(entityDetails, createdByColumn)); cidBuilder.addField(getModifiedByField(entityDetails, modifiedByColumn)); // Add @RooJpaAudit annotation if needed if (entityDetails.getAnnotation(RooJavaType.ROO_JPA_AUDIT) == null) { cidBuilder.addAnnotation(new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_AUDIT).build()); } // Write changes on disk getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); }
/** * Obtains a method annotated with @After for doing the test class teardown phase * after finishing each test. * * @return {@link MethodMetadataBuilder} */ private MethodMetadataBuilder getCleanMethod() { final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.newLine(); bodyBuilder.appendFormalLine("// Clean needed after executing each test method"); bodyBuilder.appendFormalLine("// To be implemented by developer"); bodyBuilder.newLine(); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, new JavaSymbolName("clean"), JavaType.VOID_PRIMITIVE, bodyBuilder); // Add @After methodBuilder.addAnnotation(new AnnotationMetadataBuilder(AFTER).build()); // Add comment CommentStructure comment = new CommentStructure(); JavadocComment javaDocComment = new JavadocComment( "This method will be automatically executed after each test method for freeing resources allocated with @Before annotated method."); comment.addComment(javaDocComment, CommentLocation.BEGINNING); methodBuilder.setCommentStructure(comment); return methodBuilder; }
public static ConstructorMetadata getConstructor(String declaredByMetadataId, FieldMetadata serviceField, FieldMetadata conversionServiceField) { InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); // Generating constructor ConstructorMetadataBuilder constructor = new ConstructorMetadataBuilder(declaredByMetadataId); constructor.setModifier(Modifier.PUBLIC); constructor.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED)); // add Service to constructor String serviceFieldName = serviceField.getFieldName().getSymbolName(); AnnotatedJavaType serviceParameter = new AnnotatedJavaType(serviceField.getFieldType(), new AnnotationMetadataBuilder( SpringJavaType.LAZY).build()); constructor.addParameterName(serviceField.getFieldName()); constructor.addParameterType(serviceParameter); // Generating body bodyBuilder.appendFormalLine("this.%1$s = %1$s;", serviceFieldName); // add Conversion service to constructor String conversionServiceFieldName = conversionServiceField.getFieldName().getSymbolName(); constructor.addParameter(conversionServiceFieldName, conversionServiceField.getFieldType()); // Generating body bodyBuilder.appendFormalLine("this.%1$s = %1$s;", conversionServiceFieldName); // Adding body constructor.setBodyBuilder(bodyBuilder); return constructor.build(); }