/** * Returns cardinality value based on JPA field annotations * * @param field * @return ONE_TO_MANY, MANY_TO_MANY, ONE_TO_ONE or null */ private Cardinality getFieldCardinality(final AnnotationMetadata fieldJpaAnnotation) { Cardinality cardinality = null; if (JpaJavaType.ONE_TO_MANY.equals(fieldJpaAnnotation.getAnnotationType())) { cardinality = Cardinality.ONE_TO_MANY; } else if (JpaJavaType.MANY_TO_MANY.equals(fieldJpaAnnotation.getAnnotationType())) { cardinality = Cardinality.MANY_TO_MANY; } else if (JpaJavaType.ONE_TO_ONE.equals(fieldJpaAnnotation.getAnnotationType())) { cardinality = Cardinality.ONE_TO_ONE; } return cardinality; }
/** * Locates the metadata for an annotation of the specified type from within * the given list. * * @param annotations the set of annotations to search (may be * <code>null</code>) * @param annotationType the annotation to locate (may be <code>null</code>) * @return the annotation, or <code>null</code> if not found */ public static AnnotationMetadata getAnnotationOfType( final List<? extends AnnotationMetadata> annotations, final JavaType annotationType) { if (annotations == null) { return null; } for (final AnnotationMetadata annotation : annotations) { if (annotation.getAnnotationType().equals(annotationType)) { return annotation; } } return null; }
public AnnotationMetadata getAnnotation(final JavaType type) { Validate.notNull(type, "Annotation type to locate required"); for (final AnnotationMetadata md : getAnnotations()) { if (md.getAnnotationType().equals(type)) { return md; } } return null; }
/** * Returns the first annotation of the given field that matches any of this * matcher's target annotations * * @param field the field whose annotations are to be checked (required) * @return */ private AnnotationMetadata getMatchingAnnotation(final FieldMetadata field) { for (final AnnotationMetadata fieldAnnotation : field.getAnnotations()) { for (final AnnotationMetadata matchingAnnotation : annotations) { if (fieldAnnotation.getAnnotationType().getFullyQualifiedTypeName() .equals(matchingAnnotation.getAnnotationType().getFullyQualifiedTypeName())) { return fieldAnnotation; } } } return null; }
public List<MemberHoldingTypeDetails> matches( final List<MemberHoldingTypeDetails> memberHoldingTypeDetailsList) { final Map<String, MemberHoldingTypeDetails> matched = new HashMap<String, MemberHoldingTypeDetails>(); for (final MemberHoldingTypeDetails memberHoldingTypeDetails : memberHoldingTypeDetailsList) { for (final AnnotationMetadata annotationMetadata : memberHoldingTypeDetails.getAnnotations()) { for (final JavaType annotationTypeToMatchOn : annotationTypesToMatchOn) { if (annotationMetadata.getAnnotationType().equals(annotationTypeToMatchOn)) { matched.put(memberHoldingTypeDetails.getDeclaredByMetadataId(), memberHoldingTypeDetails); } } } } return new ArrayList<MemberHoldingTypeDetails>(matched.values()); } }
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; } }
if (!annotationToMidMap.containsKey(annotationMetadata.getAnnotationType())) { annotationToMidMap.put(annotationMetadata.getAnnotationType(), new HashSet<String>()); previousAnnotations.add(annotationMetadata.getAnnotationType()); annotationToMidMap.get(annotationMetadata.getAnnotationType()).add( cid.getDeclaredByMetadataId());
if (resolver.isFullyQualifiedFormRequiredAfterAutoImport(annotation.getAnnotationType())) { sb.append(annotation.getAnnotationType().getFullyQualifiedTypeName()); } else { sb.append(annotation.getAnnotationType().getSimpleTypeName()); sb.append(annotation.getAnnotationType().getFullyQualifiedTypeName());
/** * Constructor for using an existing {@link AnnotationMetadata} as a * baseline for building a new instance. * * @param existing required */ public AnnotationMetadataBuilder(final AnnotationMetadata existing) { Validate.notNull(existing); annotationType = existing.getAnnotationType(); for (final JavaSymbolName attributeName : existing.getAttributeNames()) { attributeValues.put(attributeName.getSymbolName(), existing.getAttribute(attributeName)); } this.setCommentStructure(existing.getCommentStructure()); }
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; } } }
/** * Constructor must contain {@link FieldMetadata} of existing field (may * already contain field annotations) and a list of new Annotations which * should be introduced by an AspectJ ITD. The added annotations can not * already be present in {@link FieldMetadata}. * * @param field FieldMetadata of existing field (may not be null) * @param fieldAnnotation Annotation to be added to field via an ITD (may * not be null) * @param removeAnnotation if true, will cause the specified annotation to * be REMOVED via AspectJ's "-" syntax (usually would be false) */ public DeclaredFieldAnnotationDetails(final FieldMetadata field, final AnnotationMetadata fieldAnnotation, final boolean removeAnnotation) { Validate.notNull(field, "Field metadata required"); Validate.notNull(fieldAnnotation, "Field annotation required"); if (removeAnnotation) { Validate .isTrue( fieldAnnotation.getAttributeNames().isEmpty(), "Field annotation '@%s' (on target field %s.%s) must not have any attributes when requesting its removal", fieldAnnotation.getAnnotationType().getSimpleTypeName(), field.getFieldType() .getFullyQualifiedTypeName(), field.getFieldName().getSymbolName()); } this.field = field; this.fieldAnnotation = fieldAnnotation; this.removeAnnotation = removeAnnotation; }
getDeclaredTypeAnnotation(annotation.getAnnotationType()); new AnnotationMetadataBuilder(annotation.getAnnotationType(), new ArrayList<AnnotationAttributeValue<?>>(replacementAttributeValues.values())); addAnnotation(replacement); new AnnotationMetadataBuilder(annotation.getAnnotationType(), new ArrayList<AnnotationAttributeValue<?>>(replacementAttributeValues.values())); annotations.remove(existingBuilder);
public void addMethodAnnotation( final DeclaredMethodAnnotationDetails declaredMethodAnnotationDetails) { if (declaredMethodAnnotationDetails == null) { return; } final boolean hasAnnotation = MemberFindingUtils.getAnnotationOfType(declaredMethodAnnotationDetails.getMethodMetadata() .getAnnotations(), declaredMethodAnnotationDetails.getMethodAnnotation() .getAnnotationType()) != null; Validate.isTrue(!hasAnnotation, "Method annotation '@%s' is already present on the target field '%s' (ITD target '%s')", declaredMethodAnnotationDetails.getMethodAnnotation().getAnnotationType() .getSimpleTypeName(), declaredMethodAnnotationDetails.getMethodMetadata() .getMethodName().getSymbolName(), aspect.getFullyQualifiedTypeName()); methodAnnotations.add(declaredMethodAnnotationDetails); }
private String getSuffix(final List<MemberHoldingTypeDetails> memberHoldingTypeDetailsList, final boolean singular, final Map<String, String> pluralMap) { final ClassOrInterfaceTypeDetails cid = getMostConcreteClassOrInterfaceTypeDetails(memberHoldingTypeDetailsList); if (singular) { return cid.getName().getSimpleTypeName(); } String plural = pluralMap.get(cid.getDeclaredByMetadataId()); for (final AnnotationMetadata annotationMetadata : cid.getAnnotations()) { if (annotationMetadata.getAnnotationType().getFullyQualifiedTypeName() .equals(ROO_PLURAL.getFullyQualifiedTypeName())) { final AnnotationAttributeValue<?> annotationAttributeValue = annotationMetadata.getAttribute(new JavaSymbolName("value")); if (annotationAttributeValue != null) { plural = annotationAttributeValue.getValue().toString(); } break; } } if (StringUtils.isNotBlank(plural)) { plural = StringUtils.capitalize(plural); } return plural; }
private JavaSymbolName getUserDefinedMethod( final List<MemberHoldingTypeDetails> memberHoldingTypeDetailsList, final Map<String, String> pluralMap) { if (catalystAnnotationType == null || userDefinedNameAttribute == null) { return null; } final String suffix = suffixPlural || suffixSingular ? getSuffix(memberHoldingTypeDetailsList, suffixSingular, pluralMap) : ""; final ClassOrInterfaceTypeDetails cid = getMostConcreteClassOrInterfaceTypeDetails(memberHoldingTypeDetailsList); for (final AnnotationMetadata annotationMetadata : cid.getAnnotations()) { if (annotationMetadata.getAnnotationType().getFullyQualifiedTypeName() .equals(catalystAnnotationType.getFullyQualifiedTypeName())) { final AnnotationAttributeValue<?> annotationAttributeValue = annotationMetadata.getAttribute(userDefinedNameAttribute); if (annotationAttributeValue != null && StringUtils.isNotBlank(annotationAttributeValue.getValue().toString())) { return new JavaSymbolName(annotationAttributeValue.getValue().toString() + suffix); } break; } } return defaultName == null ? null : new JavaSymbolName(defaultName + suffix); }
MemberFindingUtils.getAnnotationOfType(declaredFieldAnnotationDetails.getField() .getAnnotations(), declaredFieldAnnotationDetails.getFieldAnnotation() .getAnnotationType()) != null; if (!declaredFieldAnnotationDetails.isRemoveAnnotation()) { Validate !hasAnnotation, "Field annotation '@%s' is already present on the target field '%s.%s' (ITD target '%s')", declaredFieldAnnotationDetails.getFieldAnnotation().getAnnotationType() .getSimpleTypeName(), declaredBy.getFullyQualifiedTypeName(), declaredFieldAnnotationDetails.getField().getFieldName().getSymbolName(), hasAnnotation, "Field annotation '@%s' cannot be removed as it is not present on the target field '%s.%s' (ITD target '%s')", declaredFieldAnnotationDetails.getFieldAnnotation().getAnnotationType() .getSimpleTypeName(), declaredBy.getFullyQualifiedTypeName(), declaredFieldAnnotationDetails.getField().getFieldName().getSymbolName(),
if (annotation.getAnnotationType().equals(SpringJavaType.ENABLE_JMS)) { annotationNotExists = false; break;
if (annotationMetadata.getAnnotationType().equals(TRANSIENT)) { return null;
if (annotation.getAnnotationType().getFullyQualifiedTypeName().startsWith("javax.validation")) { jsr303Required = true; break;
annotationExpr = new MarkerAnnotationExpr(JavaParserUtils.getNameExpr(nestedAnnotation .getAnnotationType().getSimpleTypeName())); } else if (castValue.getValue().getAttributeNames().size() == 1 && (castValue.getValue().getAttributeNames().get(0) == null || "value".equals(castValue annotationExpr = new SingleMemberAnnotationExpr(JavaParserUtils.getNameExpr(nestedAnnotation .getAnnotationType().getSimpleTypeName()), convert( nestedAnnotation.getAttribute(nestedAnnotation.getAttributeNames().get(0)), compilationUnitServices).getValue()); .getAnnotationType().getSimpleTypeName()), memberValuePairs); compilationUnitServices.getImports(), nestedAnnotation.getAnnotationType());