public static AnnotatedElement getAnnotatedElement(Class<?> beanClass, String propertyName, Class<?> propertyClass) { Field field = getFieldOrNull(beanClass, propertyName); Method method = getGetterOrNull(beanClass, propertyName, propertyClass); if (field == null || field.getAnnotations().length == 0) { return (method != null && method.getAnnotations().length > 0) ? method : EMPTY; } else if (method == null || method.getAnnotations().length == 0) { return field; } else { return new Annotations(field, method); } }
public Annotations(AnnotatedElement... elements) { for (AnnotatedElement element : elements) { addAnnotations(element); } }
@Override public void inspect(Element element, Annotations annotations) { Temporal temporal = element.getAnnotation(Temporal.class); if (temporal != null && element.getAnnotation(ElementCollection.class) == null) { PropertyType propertyType = null; switch (temporal.value()) { case DATE: propertyType = PropertyType.DATE; break; case TIME: propertyType = PropertyType.TIME; break; case TIMESTAMP: propertyType = PropertyType.DATETIME; } annotations.addAnnotation(new QueryTypeImpl(propertyType)); } }
Annotations ann = new Annotations(field); types.put(field.getName(), propertyType); annotations.put(field.getName(), ann); ann = new Annotations(); annotations.put(propertyName, ann); ann.addAnnotations(method);
blockedProperties.add(name); } else if (configuration.isValidField(field)) { Annotations annotations = new Annotations(); configuration.inspect(field, annotations); annotations.addAnnotation(field.getAnnotation(QueryType.class)); annotations.addAnnotation(field.getAnnotation(QueryInit.class)); propertyAnnotations.put(name, annotations); propertyTypes.put(name, field.asType()); Annotations annotations = propertyAnnotations.get(name); if (annotations == null) { annotations = new Annotations(); propertyAnnotations.put(name, annotations); annotations.addAnnotation(method.getAnnotation(QueryType.class)); annotations.addAnnotation(method.getAnnotation(QueryInit.class)); propertyTypes.put(name, method.getReturnType()); TypeMirror fixedType = configuration.getRealType(method);
private Property toProperty(EntityType entityType, String name, TypeMirror type, Annotations annotations) { // type Type propertyType = typeFactory.getType(type, true); if (annotations.isAnnotationPresent(QueryType.class)) { PropertyType propertyTypeAnn = annotations.getAnnotation(QueryType.class).value(); if (propertyTypeAnn != PropertyType.NONE) { TypeCategory typeCategory = TypeCategory.valueOf(annotations.getAnnotation(QueryType.class).value().name()); if (typeCategory == null) { return null; } propertyType = propertyType.as(typeCategory); } else { return null; } } // inits List<String> inits = Collections.emptyList(); if (annotations.isAnnotationPresent(QueryInit.class)) { inits = ImmutableList.copyOf(annotations.getAnnotation(QueryInit.class).value()); } return new Property(entityType, name, propertyType, inits); }
@Override public Annotation[] getDeclaredAnnotations() { return getAnnotations(); }
@Override public Annotation[] getDeclaredAnnotations() { return getAnnotations(); }
public static AnnotatedElement getAnnotatedElement(Class<?> beanClass, String propertyName, Class<?> propertyClass) { Field field = getFieldOrNull(beanClass, propertyName); Method method = getGetterOrNull(beanClass, propertyName, propertyClass); if (field == null || field.getAnnotations().length == 0) { return (method != null && method.getAnnotations().length > 0) ? method : EMPTY; } else if (method == null || method.getAnnotations().length == 0) { return field; } else { return new Annotations(field, method); } }
public Annotations(AnnotatedElement... elements) { for (AnnotatedElement element : elements) { addAnnotations(element); } }
protected AnnotatedElement getAnnotatedElement(Class<?> cl, String propertyName) throws NoSuchMethodException { Field field = ReflectionUtils.getFieldOrNull(cl, propertyName); Method method = ReflectionUtils.getGetterOrNull(cl, propertyName); if (field != null) { if (method != null) { return new Annotations(field, method); } else { return field; } } else if (method != null) { return method; } else { throw new IllegalArgumentException("No property found for " + cl.getName() + "." + propertyName); } }