/** * 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; }
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); }
List<AnnotationMetadata> javaDeclaredAnnotations = classDetails.getAnnotations(); boolean annotationExists = false; for (AnnotationMetadata javaAnnotation : javaDeclaredAnnotations) {
for (AnnotationMetadata annotation : applicationClass.getAnnotations()) { if (annotation.getAnnotationType().equals(SpringJavaType.ENABLE_JMS)) { annotationNotExists = false;
for (final AnnotationMetadata candidate : cid.getAnnotations()) { JavaParserAnnotationMetadataBuilder.addAnnotationToList(compilationUnitServices, annotations, candidate);
/** * 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; }
/** * * 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; }
/** * * This method returns map controller by path * * @param typeLocationService * @return */ public static JavaType getMapControllerByPath(String path, TypeLocationService typeLocationService) { 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)); String requestMappingPath = requestMappingAnnotation .getAttribute("value").getValue().toString(); String currentPath = requestMappingPath.toString().replaceAll("/", ""); if (currentPath.equals(path)) { return mapViewer; } } return null; }
/** * * This method returns all available maps * * @param typeLocationService * @return */ public static List<String> getAllMaps( TypeLocationService typeLocationService) { List<String> paths = new ArrayList<String>(); 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)); String requestMappingPath = requestMappingAnnotation .getAttribute("value").getValue().toString(); String currentPath = requestMappingPath.toString().replaceAll("/", ""); paths.add(currentPath); } return paths; }
public AnnotationMetadata getAnnotation(String annotation, ClassOrInterfaceTypeDetails governorTypeDetails) { JavaType javaType = new JavaType(annotation); for (AnnotationMetadata annotationMetadata : governorTypeDetails .getAnnotations()) { if (annotationMetadata.getAnnotationType().equals(javaType)) { return annotationMetadata; } } return null; }
/** * 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; }
/** * {@inheritDoc} * <p> * Checks if annotation is defined in as DeclaredType. * </p> */ public boolean isAnnotationIntroduced(String annotation, ClassOrInterfaceTypeDetails governorTypeDetails) { JavaType javaType = new JavaType(annotation); boolean isDefined = false; for (AnnotationMetadata annotationMetadata : governorTypeDetails .getAnnotations()) { isDefined = annotationMetadata.getAnnotationType().equals(javaType); if (isDefined) { return isDefined; } } return isDefined; }
.getAnnotationOfType(mapViewerController.getAnnotations(), SpringJavaType.REQUEST_MAPPING);
if (MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(), AUDIT_ANNOTATION_TYPE) == null) {
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; }
/** * Return an instance of the Metadata offered by this add-on */ @Override protected ItdTypeDetailsProvidingMetadataItem getMetadata( String metadataIdentificationString, JavaType aspectName, PhysicalTypeMetadata governorPhysicalTypeMetadata, String itdFilename) { // We know governor type details are non-null and can be safely cast ClassOrInterfaceTypeDetails controllerDetails = (ClassOrInterfaceTypeDetails) governorPhysicalTypeMetadata .getMemberHoldingTypeDetails(); Validate.notNull( controllerDetails, "Governor failed to provide class type details, in violation of superclass contract"); AnnotationMetadata stringTrimmerAnnotation = MemberFindingUtils .getAnnotationOfType(controllerDetails.getAnnotations(), GVNIX_STRING_TRIMMER_BINDER); boolean emptyAsNull = ((BooleanAttributeValue) stringTrimmerAnnotation .getAttribute(new JavaSymbolName("emptyAsNull"))).getValue() .booleanValue(); // Pass dependencies required by the metadata in through its constructor return new StringTrimmerBinderMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, emptyAsNull); }
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); }
final ClassOrInterfaceTypeDetails entity) { final List<? extends AnnotationMetadata> typeAnnotations = entity .getAnnotations();
public void annotateType(final JavaType javaType, final String rootName, final boolean deepSerialize, final boolean iso8601Dates) { Validate.notNull(javaType, "Java type required"); final ClassOrInterfaceTypeDetails cid = typeLocationService .getTypeDetails(javaType); if (cid == null) { throw new IllegalArgumentException("Cannot locate source for '" + javaType.getFullyQualifiedTypeName() + "'"); } if (MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(), RooJavaType.ROO_JSON) == null) { final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder( RooJavaType.ROO_JSON); if (rootName != null && rootName.length() > 0) { annotationBuilder.addStringAttribute("rootName", rootName); } if (deepSerialize) { annotationBuilder.addBooleanAttribute("deepSerialize", true); } if (iso8601Dates) { annotationBuilder.addBooleanAttribute("iso8601Dates", true); } final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder( cid); cidBuilder.addAnnotation(annotationBuilder); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); } }