static private JAnnotationUse findAnnotation(Collection<JAnnotationUse> annotations, Class<?> clazz){ String fullName = clazz.getName(); for(JAnnotationUse annotation : annotations){ JClass type = annotation.getAnnotationClass(); if(checkType(type, fullName)){ return annotation; } } return null; }
/** * Returns the annotation for the given field. This method has side effect as it initailizes the lazy list of * annotations on the given {@code annotatable}. */ public static JAnnotationUse getAnnotation(JAnnotatable annotatable, JClass annotationClass) { for (JAnnotationUse annotation : annotatable.annotations()) { if (annotation.getAnnotationClass().equals(annotationClass)) { return annotation; } } return null; }
/** * Returns the annotation for the given field. This method has side effect as it initailizes the lazy list of * annotations on the given {@code annotatable}. */ public static JAnnotationUse getAnnotation(JAnnotatable annotatable, JClass annotationClass) { for (JAnnotationUse annotation : annotatable.annotations()) { if (annotation.getAnnotationClass().equals(annotationClass)) { return annotation; } } return null; }
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); } } }
if (annotationClass.equals(annotation.getAnnotationClass())) { annotationUse = annotation;
@Override protected JVar paramQueryForm(ApiParameterMetadata paramMetaData, CodeModelHelper.JExtMethod generatableType, ApiActionMetadata endpointMetadata) { JVar paramQueryForm = super.paramQueryForm(paramMetaData, generatableType, endpointMetadata); // name of request/header/path parameter needs to be set for feign // client even when it matches method parameter name // if name is already set this will not override it Collection<JAnnotationUse> annotations = paramQueryForm.annotations(); for (JAnnotationUse annotation : annotations) { JClass annotationClass = annotation.getAnnotationClass(); if (ANNOTATIONS_TO_OVERRIDE.contains(annotationClass.fullName())) { annotation.param("name", paramMetaData.getName()); } } return paramQueryForm; }
@Override protected void onClass(final ClassOutline classOutline) { String namespace = null; for (final JAnnotationUse annot : classOutline.implClass.annotations()) { final String fullName = annot.getAnnotationClass().fullName(); if (xmlTypeName.equals(fullName)) { final JAnnotationValue value = annot.getAnnotationMembers().get("namespace"); if (value != null) { final StringWriter w = new StringWriter(); value.generate(new JFormatter(w)); namespace = w.toString(); namespace = namespace.substring(1, namespace.length() - 1); // remove quotes } } else if (xmlRootEltName.equals(fullName)) { namespace = null; break; } } if (null == namespace) { return; } classOutline.implClass.annotate(XmlRootElement.class) .param("namespace", namespace) .param("name", toXml(classOutline.implClass.name())); } }
.namespace(annotation.getAnnotationClass()._package().name()) .name(annotation.getAnnotationClass().name());
/** * 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; }
public void annotate(JCodeModel codeModel, JAnnotatable annotatable, XAnnotation<?> xannotation) { final JClass annotationClass = codeModel.ref(xannotation .getAnnotationClass()); JAnnotationUse annotationUse = null; for (JAnnotationUse annotation : annotatable.annotations()) { if (annotationClass.equals(annotation.getAnnotationClass())) { annotationUse = annotation; } } if (annotationUse == null) { annotationUse = annotatable.annotate(annotationClass); } final XAnnotationFieldVisitor<?> visitor = createAnnotationFieldVisitor( codeModel, annotationUse); for (XAnnotationField<?> field : xannotation.getFieldsList()) { field.accept(visitor); } }
for (JMethod method : objectFactory.methods()) { for (JAnnotationUse annotationUse : method.annotations()) { if (XmlElementDecl.class.getName().equals(annotationUse.getAnnotationClass().fullName())) {
if (annot.getAnnotationClass().fullName().equals(JsonSubTypes.class.getCanonicalName())) { annotationValues = (JAnnotationArrayMember)annot.getAnnotationMembers().get("value"); break;