/** * Returns the type of the field or throws an {@link IllegalArgumentException} if no field could be found. * * @return * @throws IllegalStateException in case no field with the configured annotation was found. */ public Class<?> getRequiredType() { return getRequiredField().getType(); }
/** * Creates a new {@link ReflectionEntityInformation} inspecting the given domain class for a field carrying the given * annotation. * * @param domainClass must not be {@literal null}. * @param annotation must not be {@literal null}. */ public ReflectionEntityInformation(Class<T> domainClass, final Class<? extends Annotation> annotation) { super(domainClass); Assert.notNull(annotation, "Annotation must not be null!"); AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback(annotation); ReflectionUtils.doWithFields(domainClass, callback); try { this.field = callback.getRequiredField(); } catch (IllegalStateException o_O) { throw new IllegalArgumentException(String.format("Couldn't find field with annotation %s!", annotation), o_O); } ReflectionUtils.makeAccessible(this.field); }
public MybatisReflectionEntityInformation(Class<T> domainClass) { super(domainClass); IdClass idClass = domainClass.getAnnotation(IdClass.class); if (null != idClass) { this.idClass = idClass.value(); } else { for (Class<? extends Annotation> annotation : MybatisPersistentPropertyImpl.ID_ANNOTATIONS) { AnnotationDetectionFieldCallback callback = new AnnotationDetectionFieldCallback( annotation); ReflectionUtils.doWithFields(domainClass, callback); try { this.field = callback.getRequiredField(); } catch (IllegalStateException o_O) { } if (null != this.field) { ReflectionUtils.makeAccessible(this.field); break; } } } }