HHH-14529 Clarify that most fields are final in JPAOverriddenAnnotationReader

This commit is contained in:
Yoann Rodière 2021-03-24 17:38:30 +01:00
parent 2907c95cbd
commit f92275f6c2
1 changed files with 14 additions and 10 deletions

View File

@ -238,12 +238,12 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
annotationToXml.put( ConstructorResult.class, "constructor-result" ); annotationToXml.put( ConstructorResult.class, "constructor-result" );
} }
private XMLContext xmlContext; private final XMLContext xmlContext;
private final ClassLoaderAccess classLoaderAccess; private final ClassLoaderAccess classLoaderAccess;
private final AnnotatedElement element; private final AnnotatedElement element;
private String className; private final String className;
private String propertyName; private final String propertyName;
private PropertyType propertyType; private final PropertyType propertyType;
private transient Annotation[] annotations; private transient Annotation[] annotations;
private transient Map<Class, Annotation> annotationsMap; private transient Map<Class, Annotation> annotationsMap;
private transient List<Element> elementsForProperty; private transient List<Element> elementsForProperty;
@ -263,6 +263,8 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
if ( el instanceof Class ) { if ( el instanceof Class ) {
Class clazz = (Class) el; Class clazz = (Class) el;
className = clazz.getName(); className = clazz.getName();
propertyName = null;
propertyType = null;
} }
else if ( el instanceof Field ) { else if ( el instanceof Field ) {
Field field = (Field) el; Field field = (Field) el;
@ -282,18 +284,18 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
else if ( el instanceof Method ) { else if ( el instanceof Method ) {
Method method = (Method) el; Method method = (Method) el;
className = method.getDeclaringClass().getName(); className = method.getDeclaringClass().getName();
propertyName = method.getName(); String methodName = method.getName();
// YUCK! The null here is the 'boundType', we'd rather get the TypeEnvironment() // YUCK! The null here is the 'boundType', we'd rather get the TypeEnvironment()
if ( ReflectionUtil.isProperty( method, null, PersistentAttributeFilter.INSTANCE ) ) { if ( ReflectionUtil.isProperty( method, null, PersistentAttributeFilter.INSTANCE ) ) {
if ( propertyName.startsWith( "get" ) ) { if ( methodName.startsWith( "get" ) ) {
propertyName = Introspector.decapitalize( propertyName.substring( "get".length() ) ); propertyName = Introspector.decapitalize( methodName.substring( "get".length() ) );
} }
else if ( propertyName.startsWith( "is" ) ) { else if ( methodName.startsWith( "is" ) ) {
propertyName = Introspector.decapitalize( propertyName.substring( "is".length() ) ); propertyName = Introspector.decapitalize( methodName.substring( "is".length() ) );
} }
else { else {
throw new RuntimeException( "Method " + propertyName + " is not a property getter" ); throw new RuntimeException( "Method " + methodName + " is not a property getter" );
} }
propertyType = PropertyType.PROPERTY; propertyType = PropertyType.PROPERTY;
try { try {
@ -304,12 +306,14 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
} }
} }
else { else {
propertyName = methodName;
propertyType = PropertyType.METHOD; propertyType = PropertyType.METHOD;
} }
} }
else { else {
className = null; className = null;
propertyName = null; propertyName = null;
propertyType = null;
} }
} }