private JAnnotationUse getAnnotation(final JFieldVar field, final Class<?> annotationType) { for (final JAnnotationUse annotation : field.annotations()) { if (annotationType.getName().equals(annotation.getAnnotationClass().binaryName())) { return annotation; } } return null; } }
private boolean notAnnotated(JFieldVar fieldVar, JClass annotationClass) { for (JAnnotationUse annotationUse : fieldVar.annotations()) if ((annotationUse.getAnnotationClass().toString().equals(annotationClass.toString()))) return false; return true; }
private boolean notAnnotated(JFieldVar fieldVar, JClass annotationClass) { for (JAnnotationUse annotationUse : fieldVar.annotations()) if ((annotationUse.getAnnotationClass().toString().equals(annotationClass.toString()))) return false; return true; }
private void process() { for (final JFieldVar jfield : classOutline.implClass.fields().values()) { final Collection<JAnnotationUse> annotations = jfield.annotations(); for (final JAnnotationUse annotation : annotations) { final String fullclassName = annotation.getAnnotationClass().fullName(); if (isAnnotationEligible(fullclassName) && !fieldsFromAnnotations.contains(fullclassName)) { fieldsFromAnnotations.add(jfield.name()); } } final String checkedValue = jfield.name(); if (!classFields.contains(checkedValue)) { classFields.add(checkedValue); } } }
attrs.add(createOneOfAttribute(namespace, oneOfField, fieldName, field.annotations())); attrs.add(createOneOfAttribute(namespace, field, null, field.annotations()));
/** * Checks if the desired annotation is not a boundary of a primitive type and * Checks if the fieldVar is already annotated with the desired annotation. * * @return true if the fieldVar should be annotated, false if the fieldVar is * already annotated or the value is a default boundary. */ private boolean notAnnotatedAndNotDefaultBoundary(JFieldVar fieldVar, JClass annotationClass, String boundaryValue) { if (isDefaultBoundary(fieldVar.type().name(), annotationClass.fullName(), boundaryValue)) return false; for (JAnnotationUse annotationUse : fieldVar.annotations()) { if ((annotationUse.getAnnotationClass().toString().equals(annotationClass.toString()))) { boolean previousAnnotationRemoved = false; String annotationName = annotationUse.getAnnotationClass().fullName(); if (annotationName.equals(ANNOTATION_DECIMALMIN.fullName())) previousAnnotationRemoved = isMoreSpecificBoundary(fieldVar, boundaryValue, annotationUse, false); else if (annotationName.equals(ANNOTATION_DECIMALMAX.fullName())) previousAnnotationRemoved = isMoreSpecificBoundary(fieldVar, boundaryValue, annotationUse, true); // If the previous field's annotation was removed, the fieldVar // now is not annotated and should be given a new annotation, // i.e. return true. return previousAnnotationRemoved; } } return true; }
/** * Checks if the desired annotation is not a boundary of a primitive type and * Checks if the fieldVar is already annotated with the desired annotation. * * @return true if the fieldVar should be annotated, false if the fieldVar is * already annotated or the value is a default boundary. */ private boolean notAnnotatedAndNotDefaultBoundary(JFieldVar fieldVar, JClass annotationClass, String boundaryValue) { if (isDefaultBoundary(fieldVar.type().name(), annotationClass.fullName(), boundaryValue)) return false; for (JAnnotationUse annotationUse : fieldVar.annotations()) { if ((annotationUse.getAnnotationClass().toString().equals(annotationClass.toString()))) { boolean previousAnnotationRemoved = false; String annotationName = annotationUse.getAnnotationClass().fullName(); if (annotationName.equals(decimalMinAnn.fullName())) previousAnnotationRemoved = isMoreSpecificBoundary(fieldVar, boundaryValue, annotationUse, false); else if (annotationName.equals(decimalMaxAnn.fullName())) previousAnnotationRemoved = isMoreSpecificBoundary(fieldVar, boundaryValue, annotationUse, true); // If the previous field's annotation was removed, the fieldVar // now is not annotated and should be given a new annotation, // i.e. return true. return previousAnnotationRemoved; } } return true; }
/** * A hook method that creates a simple {@code Attribute} for the {@link Dto}, i.e. an {@code Attribute} that is not a * {@link OneOfAttribute}. * <p/> * Called by the {@link #createAttributes(JDefinedClass, APINamespace)} method. Also called by * {@link #createOneOfAttribute(APINamespace, String, Collection)} for creating each alternative of a * {@code OneOfAttribute}. Subclasses may override it to customize the way that {@code Attributes} are created. * * @param namespace The {@code APINamespace} to use for the new {@code Attribute}. * @param field The {@code JFieldVar} to transform into the new {@code Attribute}. * @return The new {@code Attribute} to be added to the {@link Dto}. */ protected Attribute createSimpleAttribute(final APINamespace namespace, final JFieldVar field) { final Type typeModel = createType(namespace, field); final AttributeBuilder attributeBuilder = Attribute.builder() .qualifier(field.name()) .type(typeModel); final Collection<JAnnotationUse> annotations = field.annotations(); if (annotations != null) { for (final JAnnotationUse annotation : annotations) { final AnnotationBuilder annotationBuilder = processFieldAnnotation(annotation); attributeBuilder.annotation(annotationBuilder.build()); } } return attributeBuilder.build(); }
Collection<JAnnotationUse> annotations = fieldVar.annotations();