/** * Returns the first of the given types of annotation on the given class or * interface * * @param cid the class or interface to check (can be <code>null</code>) * @param annotationTypes the types of annotation to look for, in order (can * be <code>null</code>) * @return <code>null</code> if the given type or array of annotations is * <code>null</code>, or none were found */ public static AnnotationMetadata getFirstAnnotation(final ClassOrInterfaceTypeDetails cid, final JavaType... annotationTypes) { if (cid != null && annotationTypes != null) { for (final JavaType annotationType : annotationTypes) { final AnnotationMetadata annotation = MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(), annotationType); if (annotation != null) { return annotation; } } } return null; }
public List<FieldMetadata> getFieldsWithAnnotation(final JavaType annotation) { Validate.notNull(annotation, "Annotation required"); final List<FieldMetadata> result = new ArrayList<FieldMetadata>(); MemberHoldingTypeDetails current = this; while (current != null) { for (final FieldMetadata field : current.getDeclaredFields()) { if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), annotation) != null) { // Found the annotation on this field result.add(field); } } if (current instanceof ClassOrInterfaceTypeDetails) { current = ((ClassOrInterfaceTypeDetails) current).getSuperclass(); } else { current = null; } } return result; }
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; } }
/** * Returns the metadata for the annotation of the given type from within the * given metadata * * @param metadata the metadata to search; can be <code>null</code> * @param annotationType the type of annotation for which to return the * metadata; can be <code>null</code> * @return <code>null</code> if not found * @since 1.2.0 */ public static AnnotationMetadata getAnnotationOfType( final MemberHoldingTypeDetailsMetadataItem<?> metadata, final JavaType annotationType) { if (metadata == null || metadata.getMemberHoldingTypeDetails() == null) { return null; } return getAnnotationOfType(metadata.getMemberHoldingTypeDetails().getAnnotations(), annotationType); }
MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), ROO_PLURAL); if (annotation != null) {
@Override public Object getTagValue(final MemberHoldingTypeDetails type) { final AnnotationMetadata layerAnnotation = MemberFindingUtils.getAnnotationOfType(type.getAnnotations(), layerAnnotationType); if (layerAnnotation == null || layerAnnotation.getAttribute(domainTypesAttribute) == null) { return null; } final AnnotationAttributeValue<?> value = layerAnnotation.getAttribute(domainTypesAttribute); final List<JavaType> domainTypes = new ArrayList<JavaType>(); if (value instanceof ClassAttributeValue) { domainTypes.add(((ClassAttributeValue) value).getValue()); } else if (value instanceof ArrayAttributeValue<?>) { final ArrayAttributeValue<?> castValue = (ArrayAttributeValue<?>) value; for (final AnnotationAttributeValue<?> val : castValue.getValue()) { if (val instanceof ClassAttributeValue) { domainTypes.add(((ClassAttributeValue) val).getValue()); } } } return domainTypes; } }
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); }
destination.getFullyQualifiedTypeName()); Validate.notNull( MemberFindingUtils.getAnnotationOfType(candidate.getAnnotations(), AUTOWIRED), "Field '%s' on '%s' must be @Autowired", collaboratingFieldName, destination.getFullyQualifiedTypeName());
.getDeclaredByMetadataId()); final boolean hasAnnotation = MemberFindingUtils.getAnnotationOfType(declaredFieldAnnotationDetails.getField() .getAnnotations(), declaredFieldAnnotationDetails.getFieldAnnotation() .getAnnotationType()) != null;
MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), SIZE); if (sizeAnnotation != null && sizeAnnotation.getAttribute(MAX_SYMBOL) != null) { final Integer maxValue = (Integer) sizeAnnotation.getAttribute(MAX_SYMBOL).getValue(); MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), DIGITS); final AnnotationMetadata decimalMinAnnotation = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), DECIMAL_MIN); final AnnotationMetadata decimalMaxAnnotation = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), DECIMAL_MAX);
if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), PAST) != null) { builder.getImportRegistrationResolver().addImport(DATE); initializer = "new Date(new Date().getTime() - 10000000L)"; } else if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), FUTURE) != null) { builder.getImportRegistrationResolver().addImport(DATE); initializer = "new Date(new Date().getTime() + 10000000L)"; if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), PAST) != null) { initializer = calendarString + " - 1)"; } else if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), FUTURE) != null) { initializer = calendarString + " + 1)"; } else { if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), VALIDATOR_CONSTRAINTS_EMAIL) != null || fieldName.toLowerCase().contains("email")) { initializer = "\"foo\" + " + INDEX_VAR + " + \"@bar.com\""; MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), SIZE); if (sizeAnnotation != null) { final AnnotationAttributeValue<?> maxValue = sizeAnnotation.getAttribute(MAX_SYMBOL);
MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), MIN); final AnnotationMetadata maxAnnotation = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), MAX); if (minAnnotation != null && maxAnnotation == null) { final Number minValue = (Number) minAnnotation.getAttribute(VALUE).getValue();
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; } }
/** * * This method returns all available maps Controllers * * @param typeLocationService * @return */ public static List<JavaType> getAllMapsControllers( TypeLocationService typeLocationService) { List<JavaType> controllers = new ArrayList<JavaType>(); for (JavaType mapViewer : typeLocationService .findTypesWithAnnotation(MAP_VIEWER_ANNOTATION)) { Validate.notNull(mapViewer, "@GvNIXMapViewer required"); ClassOrInterfaceTypeDetails mapViewerController = typeLocationService .getTypeDetails(mapViewer); // Getting RequestMapping annotations final AnnotationMetadata requestMappingAnnotation = MemberFindingUtils .getAnnotationOfType(mapViewerController.getAnnotations(), SpringJavaType.REQUEST_MAPPING); Validate.notNull(mapViewer, String.format( "Error on %s getting @RequestMapping value", mapViewer)); controllers.add(mapViewer); } return controllers; }
public List<FieldMetadata> getFieldsWithAnnotation(final JavaType annotation) { Validate.notNull(annotation, "Annotation required"); final List<FieldMetadata> result = new ArrayList<FieldMetadata>(); MemberHoldingTypeDetails current = this; while (current != null) { for (final FieldMetadata field : current.getDeclaredFields()) { if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(), annotation) != null) { // Found the annotation on this field result.add(field); } } if (current instanceof ClassOrInterfaceTypeDetails) { current = ((ClassOrInterfaceTypeDetails) current).getSuperclass(); } else { current = null; } } return result; }
/** * Indicates whether the annotation introduced via this field. * * @para field to be check annotations * @param annotation to be check if exists * @return true if annotation exists into field, false otherwise */ public boolean hasAnnotation(FieldMetadata field, String annotation) { // Get field annotation of GvNIXXmlElementField type AnnotationMetadata annot = MemberFindingUtils.getAnnotationOfType( field.getAnnotations(), new JavaType(annotation)); if (annot == null) { return false; } return true; }
/** * Returns the metadata for the annotation of the given type from within the * given metadata * * @param metadata the metadata to search; can be <code>null</code> * @param annotationType the type of annotation for which to return the * metadata; can be <code>null</code> * @return <code>null</code> if not found * @since 1.2.0 */ public static AnnotationMetadata getAnnotationOfType( final MemberHoldingTypeDetailsMetadataItem<?> metadata, final JavaType annotationType) { if (metadata == null || metadata.getMemberHoldingTypeDetails() == null) { return null; } return getAnnotationOfType(metadata.getMemberHoldingTypeDetails().getAnnotations(), annotationType); }
/** * Get controller path from GvNIXMapViewer annotated controllers * * @param controller * @return */ private String getControllerPathFromViewerController(JavaType controller) { final ClassOrInterfaceTypeDetails cidController = getTypeLocationService() .getTypeDetails(controller); Validate.notNull(cidController, "The type specified, '%s', doesn't exist", cidController); // Only for @GvNIXMapViewer annotated controllers final AnnotationMetadata controllerAnnotation = MemberFindingUtils .getAnnotationOfType(cidController.getAnnotations(), new JavaType(GvNIXMapViewer.class.getName())); Validate.isTrue(controllerAnnotation != null, "Operation for @GvNIXMapViewer annotated controllers only."); String controllerPath = (String) cidController .getAnnotation(SpringJavaType.REQUEST_MAPPING) .getAttribute(VALUE).getValue(); controllerPath = controllerPath.replaceAll("/", "").trim(); return controllerPath; }
@Override public Object getTagValue(final MemberHoldingTypeDetails type) { final AnnotationMetadata layerAnnotation = MemberFindingUtils.getAnnotationOfType(type.getAnnotations(), layerAnnotationType); if (layerAnnotation == null || layerAnnotation.getAttribute(domainTypesAttribute) == null) { return null; } final AnnotationAttributeValue<?> value = layerAnnotation.getAttribute(domainTypesAttribute); final List<JavaType> domainTypes = new ArrayList<JavaType>(); if (value instanceof ClassAttributeValue) { domainTypes.add(((ClassAttributeValue) value).getValue()); } else if (value instanceof ArrayAttributeValue<?>) { final ArrayAttributeValue<?> castValue = (ArrayAttributeValue<?>) value; for (final AnnotationAttributeValue<?> val : castValue.getValue()) { if (val instanceof ClassAttributeValue) { domainTypes.add(((ClassAttributeValue) val).getValue()); } } } return domainTypes; } }
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); }