public boolean isEmbeddable() { if (ptmd != null) { List<AnnotationMetadata> annotations = ptmd.getAnnotations(); for (AnnotationMetadata annotation : annotations) { if (annotation.getAnnotationType().equals(EMBEDDABLE)) { return true; } } } return false; }
public boolean isRequestingAnnotatedWith( final AnnotationMetadata annotationMetadata, final String requestingMid) { for (final MemberHoldingTypeDetails memberHoldingTypeDetails : details) { if (MemberFindingUtils.getAnnotationOfType( memberHoldingTypeDetails.getAnnotations(), annotationMetadata.getAnnotationType()) != null) { if (memberHoldingTypeDetails.getDeclaredByMetadataId().equals(requestingMid)) { return true; } } } return false; }
public void addField(final FieldMetadata field) { Assert.notNull(field, "Field metadata not provided"); // Obtain the physical type and ITD mutable details PhysicalTypeMetadata ptm = (PhysicalTypeMetadata) metadataService.get(field.getDeclaredByMetadataId()); Assert.notNull( ptm, "Java source code unavailable for type " + PhysicalTypeIdentifier.getFriendlyName(field.getDeclaredByMetadataId())); PhysicalTypeDetails ptd = ptm.getMemberHoldingTypeDetails(); Assert.notNull( ptd, "Java source code details unavailable for type " + PhysicalTypeIdentifier.getFriendlyName(field.getDeclaredByMetadataId())); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder((ClassOrInterfaceTypeDetails) ptd); // Automatically add JSR 303 (Bean Validation API) support if there is // no current JSR 303 support but a JSR 303 annotation is present boolean jsr303Required = false; for (AnnotationMetadata annotation : field.getAnnotations()) { if (annotation .getAnnotationType() .getFullyQualifiedTypeName() .startsWith("javax.validation")) { jsr303Required = true; break; } } LogicalPath path = PhysicalTypeIdentifier.getPath(cidBuilder.getDeclaredByMetadataId()); if (jsr303Required) { // It's more likely the version below represents a later version // than any specified in the user's own dependency list projectOperations.addDependency( path.getModule(), "javax.validation", "validation-api", "1.0.0.GA"); } cidBuilder.addField(field); createOrUpdateTypeOnDisk(cidBuilder.build()); }
/** * Indicates whether the given entity has the standard annotations applied by Roo, and no others. * * @param entity the entity to check (required) * @return <code>false</code> if any of the standard ones are missing or any extra ones have been * added */ private boolean hasStandardEntityAnnotations(final ClassOrInterfaceTypeDetails entity) { final List<? extends AnnotationMetadata> typeAnnotations = entity.getAnnotations(); // We expect four: RooDbManaged, RooJavaBean, RooToString, and either // RooEntity or RooJpaEntity if (typeAnnotations.size() != 4) { return false; } // There are exactly four - check for any non-standard ones for (final AnnotationMetadata annotation : typeAnnotations) { final JavaType annotationType = annotation.getAnnotationType(); final boolean entityAnnotation = ROO_JPA_ACTIVE_RECORD.equals(annotationType) || ROO_JPA_ENTITY.equals(annotationType); if (!entityAnnotation && !ROO_DB_MANAGED.equals(annotationType) && !ROO_JAVA_BEAN.equals(annotationType) && !ROO_TO_STRING.equals(annotationType)) { return false; } } return true; }
public boolean updateTypeAnnotation( AnnotationMetadata annotation, Set<JavaSymbolName> attributesToDeleteIfPresent) { boolean hasChanged = false; // We are going to build a replacement AnnotationMetadata. // This variable tracks the new attribute values the replacement will hold. Map<JavaSymbolName, AnnotationAttributeValue<?>> replacementAttributeValues = new LinkedHashMap<JavaSymbolName, AnnotationAttributeValue<?>>(); AnnotationMetadataBuilder existingBuilder = MemberFindingUtils.getDeclaredTypeAnnotation(this, annotation.getAnnotationType()); if (existingBuilder == null) { // Not already present, so just go and add it for (JavaSymbolName incomingAttributeName : annotation.getAttributeNames()) { // Do not copy incoming attributes which exist in the attributesToDeleteIfPresent Set if (attributesToDeleteIfPresent == null || !attributesToDeleteIfPresent.contains(incomingAttributeName)) { AnnotationAttributeValue<?> incomingValue = annotation.getAttribute(incomingAttributeName); replacementAttributeValues.put(incomingAttributeName, incomingValue); } } AnnotationMetadataBuilder replacement = new AnnotationMetadataBuilder( annotation.getAnnotationType(), new ArrayList<AnnotationAttributeValue<?>>(replacementAttributeValues.values())); addAnnotation(replacement); return true; } AnnotationMetadata existing = existingBuilder.build(); // Copy the existing attributes into the new attributes for (JavaSymbolName existingAttributeName : existing.getAttributeNames()) { if (attributesToDeleteIfPresent != null && attributesToDeleteIfPresent.contains(existingAttributeName)) { hasChanged = true; } else { AnnotationAttributeValue<?> existingValue = existing.getAttribute(existingAttributeName); replacementAttributeValues.put(existingAttributeName, existingValue); } } // Now we ensure every incoming attribute replaces the existing for (JavaSymbolName incomingAttributeName : annotation.getAttributeNames()) { AnnotationAttributeValue<?> incomingValue = annotation.getAttribute(incomingAttributeName); // Add this attribute to the end of the list if the attribute is not already present if (replacementAttributeValues.keySet().contains(incomingAttributeName)) { // There was already an attribute. Need to determine if this new attribute value is // materially different AnnotationAttributeValue<?> existingValue = replacementAttributeValues.get(incomingAttributeName); Assert.notNull(existingValue, "Existing value should have been provided by earlier loop"); if (!existingValue.equals(incomingValue)) { replacementAttributeValues.put(incomingAttributeName, incomingValue); hasChanged = true; } } else if (attributesToDeleteIfPresent == null || !attributesToDeleteIfPresent.contains(incomingAttributeName)) { // This is a new attribute that does not already exist, so add it to the end of the // replacement attributes replacementAttributeValues.put(incomingAttributeName, incomingValue); hasChanged = true; } } // Were there any material changes? if (!hasChanged) { return false; } // Make a new AnnotationMetadata representing the replacement AnnotationMetadataBuilder replacement = new AnnotationMetadataBuilder( annotation.getAnnotationType(), new ArrayList<AnnotationAttributeValue<?>>(replacementAttributeValues.values())); annotations.remove(existingBuilder); addAnnotation(replacement); return true; }