minor cleanup to annotation handling in processor
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
f32bb7276f
commit
024fd31a3c
|
@ -309,8 +309,7 @@ public final class Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeElement getTypeElementForFullyQualifiedName(String qualifiedName) {
|
public TypeElement getTypeElementForFullyQualifiedName(String qualifiedName) {
|
||||||
Elements elementUtils = processingEnvironment.getElementUtils();
|
return processingEnvironment.getElementUtils().getTypeElement( qualifiedName );
|
||||||
return elementUtils.getTypeElement( qualifiedName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void markGenerated(Metamodel metamodel) {
|
void markGenerated(Metamodel metamodel) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import javax.annotation.processing.SupportedAnnotationTypes;
|
||||||
import javax.annotation.processing.SupportedOptions;
|
import javax.annotation.processing.SupportedOptions;
|
||||||
import javax.lang.model.SourceVersion;
|
import javax.lang.model.SourceVersion;
|
||||||
import javax.lang.model.element.AnnotationMirror;
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
|
import javax.lang.model.element.AnnotationValue;
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
import javax.lang.model.element.PackageElement;
|
import javax.lang.model.element.PackageElement;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
|
@ -295,9 +296,10 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
final TypeElement typeElement = (TypeElement) element;
|
final TypeElement typeElement = (TypeElement) element;
|
||||||
final AnnotationMirror repository = getAnnotationMirror( element, JD_REPOSITORY );
|
final AnnotationMirror repository = getAnnotationMirror( element, JD_REPOSITORY );
|
||||||
if ( repository != null ) {
|
if ( repository != null ) {
|
||||||
final String provider = (String) getAnnotationValue( repository, "provider" );
|
final AnnotationValue provider = getAnnotationValue( repository, "provider" );
|
||||||
if ( provider == null || provider.isEmpty()
|
if ( provider == null
|
||||||
|| provider.equalsIgnoreCase("hibernate") ) {
|
|| provider.getValue().toString().isEmpty()
|
||||||
|
|| provider.getValue().toString().equalsIgnoreCase("hibernate") ) {
|
||||||
context.logMessage( Diagnostic.Kind.OTHER, "Processing repository class '" + element + "'" );
|
context.logMessage( Diagnostic.Kind.OTHER, "Processing repository class '" + element + "'" );
|
||||||
final AnnotationMetaEntity metaEntity =
|
final AnnotationMetaEntity metaEntity =
|
||||||
AnnotationMetaEntity.create( typeElement, context );
|
AnnotationMetaEntity.create( typeElement, context );
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.List;
|
||||||
import static org.hibernate.processor.util.TypeUtils.containsAnnotation;
|
import static org.hibernate.processor.util.TypeUtils.containsAnnotation;
|
||||||
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
|
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
|
||||||
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
|
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
|
||||||
import static org.hibernate.processor.util.TypeUtils.getAnnotationValueRef;
|
|
||||||
|
|
||||||
public abstract class AnnotationMeta implements Metamodel {
|
public abstract class AnnotationMeta implements Metamodel {
|
||||||
|
|
||||||
|
@ -69,11 +68,11 @@ public abstract class AnnotationMeta implements Metamodel {
|
||||||
private void handleNamedQueryRepeatableAnnotation(String annotationName, boolean checkHql) {
|
private void handleNamedQueryRepeatableAnnotation(String annotationName, boolean checkHql) {
|
||||||
final AnnotationMirror mirror = getAnnotationMirror( getElement(), annotationName );
|
final AnnotationMirror mirror = getAnnotationMirror( getElement(), annotationName );
|
||||||
if ( mirror != null ) {
|
if ( mirror != null ) {
|
||||||
final Object value = getAnnotationValue( mirror, "value" );
|
final AnnotationValue value = getAnnotationValue( mirror, "value" );
|
||||||
if ( value instanceof List ) {
|
if ( value != null ) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final List<? extends AnnotationMirror> values =
|
final List<? extends AnnotationMirror> values =
|
||||||
(List<? extends AnnotationMirror>) value;
|
(List<? extends AnnotationMirror>) value.getValue();
|
||||||
for ( AnnotationMirror annotationMirror : values ) {
|
for ( AnnotationMirror annotationMirror : values ) {
|
||||||
handleNamedQuery( annotationMirror, checkHql );
|
handleNamedQuery( annotationMirror, checkHql );
|
||||||
}
|
}
|
||||||
|
@ -82,11 +81,11 @@ public abstract class AnnotationMeta implements Metamodel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNamedQuery(AnnotationMirror mirror, boolean checkHql) {
|
private void handleNamedQuery(AnnotationMirror mirror, boolean checkHql) {
|
||||||
final Object nameValue = getAnnotationValue( mirror, "name" );
|
final AnnotationValue nameValue = getAnnotationValue( mirror, "name" );
|
||||||
if ( nameValue instanceof String ) {
|
if ( nameValue != null ) {
|
||||||
final String name = nameValue.toString();
|
final String name = nameValue.getValue().toString();
|
||||||
final boolean reportErrors = getContext().checkNamedQuery( name );
|
final boolean reportErrors = getContext().checkNamedQuery( name );
|
||||||
final AnnotationValue value = getAnnotationValueRef( mirror, "query" );
|
final AnnotationValue value = getAnnotationValue( mirror, "query" );
|
||||||
if ( value != null ) {
|
if ( value != null ) {
|
||||||
final Object query = value.getValue();
|
final Object query = value.getValue();
|
||||||
if ( query instanceof String ) {
|
if ( query instanceof String ) {
|
||||||
|
@ -132,11 +131,11 @@ public abstract class AnnotationMeta implements Metamodel {
|
||||||
private void addAuxiliaryMembersForRepeatableAnnotation(String annotationName, String prefix) {
|
private void addAuxiliaryMembersForRepeatableAnnotation(String annotationName, String prefix) {
|
||||||
final AnnotationMirror mirror = getAnnotationMirror( getElement(), annotationName );
|
final AnnotationMirror mirror = getAnnotationMirror( getElement(), annotationName );
|
||||||
if ( mirror != null ) {
|
if ( mirror != null ) {
|
||||||
final Object value = getAnnotationValue( mirror, "value" );
|
final AnnotationValue value = getAnnotationValue( mirror, "value" );
|
||||||
if ( value instanceof List ) {
|
if ( value != null ) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final List<? extends AnnotationMirror> values =
|
final List<? extends AnnotationMirror> values =
|
||||||
(List<? extends AnnotationMirror>) value;
|
(List<? extends AnnotationMirror>) value.getValue();
|
||||||
for ( AnnotationMirror annotationMirror : values ) {
|
for ( AnnotationMirror annotationMirror : values ) {
|
||||||
addAuxiliaryMembersForMirror( annotationMirror, prefix );
|
addAuxiliaryMembersForMirror( annotationMirror, prefix );
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ import static org.hibernate.grammars.hql.HqlLexer.HAVING;
|
||||||
import static org.hibernate.grammars.hql.HqlLexer.IDENTIFIER;
|
import static org.hibernate.grammars.hql.HqlLexer.IDENTIFIER;
|
||||||
import static org.hibernate.grammars.hql.HqlLexer.ORDER;
|
import static org.hibernate.grammars.hql.HqlLexer.ORDER;
|
||||||
import static org.hibernate.grammars.hql.HqlLexer.WHERE;
|
import static org.hibernate.grammars.hql.HqlLexer.WHERE;
|
||||||
import static org.hibernate.internal.util.StringHelper.isEmpty;
|
|
||||||
import static org.hibernate.internal.util.StringHelper.qualify;
|
import static org.hibernate.internal.util.StringHelper.qualify;
|
||||||
import static org.hibernate.processor.annotation.AbstractQueryMethod.isSessionParameter;
|
import static org.hibernate.processor.annotation.AbstractQueryMethod.isSessionParameter;
|
||||||
import static org.hibernate.processor.annotation.AbstractQueryMethod.isSpecialParam;
|
import static org.hibernate.processor.annotation.AbstractQueryMethod.isSpecialParam;
|
||||||
|
@ -89,7 +88,6 @@ import static org.hibernate.processor.util.TypeUtils.determineAnnotationSpecifie
|
||||||
import static org.hibernate.processor.util.TypeUtils.findMappedSuperClass;
|
import static org.hibernate.processor.util.TypeUtils.findMappedSuperClass;
|
||||||
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
|
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
|
||||||
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
|
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
|
||||||
import static org.hibernate.processor.util.TypeUtils.getAnnotationValueRef;
|
|
||||||
import static org.hibernate.processor.util.TypeUtils.hasAnnotation;
|
import static org.hibernate.processor.util.TypeUtils.hasAnnotation;
|
||||||
import static org.hibernate.processor.util.TypeUtils.primitiveClassMatchesKind;
|
import static org.hibernate.processor.util.TypeUtils.primitiveClassMatchesKind;
|
||||||
import static org.hibernate.processor.util.TypeUtils.propertyName;
|
import static org.hibernate.processor.util.TypeUtils.propertyName;
|
||||||
|
@ -500,9 +498,12 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
private @Nullable String dataStore() {
|
private @Nullable String dataStore() {
|
||||||
final AnnotationMirror repo = getAnnotationMirror( element, JD_REPOSITORY );
|
final AnnotationMirror repo = getAnnotationMirror( element, JD_REPOSITORY );
|
||||||
if ( repo != null ) {
|
if ( repo != null ) {
|
||||||
final String dataStore = (String) getAnnotationValue( repo, "dataStore" );
|
final AnnotationValue dataStoreValue = getAnnotationValue( repo, "dataStore" );
|
||||||
if ( dataStore != null && !dataStore.isEmpty() ) {
|
if (dataStoreValue != null) {
|
||||||
return dataStore;
|
final String dataStore = dataStoreValue.getValue().toString();
|
||||||
|
if ( !dataStore.isEmpty() ) {
|
||||||
|
return dataStore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -866,13 +867,13 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateToOneAssociation(Element memberOfClass, AnnotationMirror annotation, TypeMirror type) {
|
private void validateToOneAssociation(Element memberOfClass, AnnotationMirror annotation, TypeMirror type) {
|
||||||
final TypeMirror target = (TypeMirror) getAnnotationValue(annotation, "targetEntity");
|
final AnnotationValue target = getAnnotationValue(annotation, "targetEntity");
|
||||||
validateAssociation(memberOfClass, annotation, target == null ? type : target);
|
validateAssociation(memberOfClass, annotation, target == null ? type : (TypeMirror) target.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateToManyAssociation(Element memberOfClass, AnnotationMirror annotation, TypeMirror type) {
|
private void validateToManyAssociation(Element memberOfClass, AnnotationMirror annotation, TypeMirror type) {
|
||||||
final TypeMirror target = (TypeMirror) getAnnotationValue(annotation, "targetEntity");
|
final AnnotationValue target = getAnnotationValue(annotation, "targetEntity");
|
||||||
validateAssociation(memberOfClass, annotation, target == null ? elementType(type) : target);
|
validateAssociation(memberOfClass, annotation, target == null ? elementType(type) : (TypeMirror) target.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateAssociation(Element memberOfClass, AnnotationMirror annotation, @Nullable TypeMirror typeMirror) {
|
private void validateAssociation(Element memberOfClass, AnnotationMirror annotation, @Nullable TypeMirror typeMirror) {
|
||||||
|
@ -888,8 +889,9 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
final DeclaredType assocDeclaredType = (DeclaredType) typeMirror;
|
final DeclaredType assocDeclaredType = (DeclaredType) typeMirror;
|
||||||
final TypeElement assocTypeElement = (TypeElement) assocDeclaredType.asElement();
|
final TypeElement assocTypeElement = (TypeElement) assocDeclaredType.asElement();
|
||||||
if ( hasAnnotation(assocTypeElement, ENTITY) ) {
|
if ( hasAnnotation(assocTypeElement, ENTITY) ) {
|
||||||
final String mappedBy = (String) getAnnotationValue(annotation, "mappedBy");
|
final AnnotationValue mappedBy = getAnnotationValue(annotation, "mappedBy");
|
||||||
validateBidirectionalMapping(memberOfClass, annotation, mappedBy, assocTypeElement);
|
final String propertyName = mappedBy == null ? null : mappedBy.getValue().toString();
|
||||||
|
validateBidirectionalMapping(memberOfClass, annotation, propertyName, assocTypeElement);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message(memberOfClass, "type '" + assocTypeElement.getSimpleName()
|
message(memberOfClass, "type '" + assocTypeElement.getSimpleName()
|
||||||
|
@ -916,7 +918,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final AnnotationValue annotationVal =
|
final AnnotationValue annotationVal =
|
||||||
castNonNull(getAnnotationValueRef(annotation, "mappedBy"));
|
castNonNull(getAnnotationValue(annotation, "mappedBy"));
|
||||||
for ( Element member : context.getElementUtils().getAllMembers(assocTypeElement) ) {
|
for ( Element member : context.getElementUtils().getAllMembers(assocTypeElement) ) {
|
||||||
if ( propertyName(this, member).contentEquals(mappedBy) ) {
|
if ( propertyName(this, member).contentEquals(mappedBy) ) {
|
||||||
validateBackRef(memberOfClass, annotation, assocTypeElement, member, annotationVal);
|
validateBackRef(memberOfClass, annotation, assocTypeElement, member, annotationVal);
|
||||||
|
@ -1517,7 +1519,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
final List<OrderBy> result = new ArrayList<>();
|
final List<OrderBy> result = new ArrayList<>();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final List<AnnotationValue> list = (List<AnnotationValue>)
|
final List<AnnotationValue> list = (List<AnnotationValue>)
|
||||||
castNonNull( getAnnotationValue( orderByList, "value" ) );
|
castNonNull( getAnnotationValue( orderByList, "value" ) ).getValue();
|
||||||
for ( AnnotationValue element : list ) {
|
for ( AnnotationValue element : list ) {
|
||||||
result.add( orderByExpression( castNonNull( (AnnotationMirror) element.getValue() ), entityType, method ) );
|
result.add( orderByExpression( castNonNull( (AnnotationMirror) element.getValue() ), entityType, method ) );
|
||||||
}
|
}
|
||||||
|
@ -1532,14 +1534,14 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
private OrderBy orderByExpression(AnnotationMirror orderBy, TypeElement entityType, ExecutableElement method) {
|
private OrderBy orderByExpression(AnnotationMirror orderBy, TypeElement entityType, ExecutableElement method) {
|
||||||
final String fieldName = (String) castNonNull( getAnnotationValue(orderBy, "value") );
|
final String fieldName = castNonNull( getAnnotationValue(orderBy, "value") ).getValue().toString();
|
||||||
if ( fieldName.equals("<error>") ) {
|
if ( fieldName.equals("<error>") ) {
|
||||||
throw new ProcessLaterException();
|
throw new ProcessLaterException();
|
||||||
}
|
}
|
||||||
final Boolean descendingOrNull = (Boolean) getAnnotationValue(orderBy, "descending");
|
final AnnotationValue descendingOrNull = getAnnotationValue(orderBy, "descending");
|
||||||
final Boolean ignoreCaseOrNull = (Boolean) getAnnotationValue(orderBy, "ignoreCase");
|
final AnnotationValue ignoreCaseOrNull = getAnnotationValue(orderBy, "ignoreCase");
|
||||||
final boolean descending = descendingOrNull != null && descendingOrNull;
|
final boolean descending = descendingOrNull != null && (Boolean) descendingOrNull.getValue();
|
||||||
final boolean ignoreCase = ignoreCaseOrNull != null && ignoreCaseOrNull;
|
final boolean ignoreCase = ignoreCaseOrNull != null && (Boolean) ignoreCaseOrNull.getValue();
|
||||||
final String path = fieldName
|
final String path = fieldName
|
||||||
.replace('$', '.')
|
.replace('$', '.')
|
||||||
.replace('_', '.'); //Jakarta Data allows _ here
|
.replace('_', '.'); //Jakarta Data allows _ here
|
||||||
|
@ -1632,14 +1634,14 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
return emptyList();
|
return emptyList();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final Object enabledFetchProfiles =
|
final AnnotationValue enabledFetchProfiles =
|
||||||
getAnnotationValue( findAnnotation, "enabledFetchProfiles" );
|
getAnnotationValue( findAnnotation, "enabledFetchProfiles" );
|
||||||
if ( enabledFetchProfiles == null ) {
|
if ( enabledFetchProfiles == null ) {
|
||||||
return emptyList();
|
return emptyList();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final List<AnnotationValue> annotationValues = (List<AnnotationValue>) enabledFetchProfiles;
|
final List<AnnotationValue> annotationValues = (List<AnnotationValue>) enabledFetchProfiles.getValue();
|
||||||
final List<String> result = annotationValues.stream().map(AnnotationValue::toString).collect(toList());
|
final List<String> result = annotationValues.stream().map(AnnotationValue::toString).collect(toList());
|
||||||
if ( result.stream().anyMatch("<error>"::equals) ) {
|
if ( result.stream().anyMatch("<error>"::equals) ) {
|
||||||
throw new ProcessLaterException();
|
throw new ProcessLaterException();
|
||||||
|
@ -1859,9 +1861,9 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
else {
|
else {
|
||||||
final AnnotationMirror idClass = getAnnotationMirror( entityType, ID_CLASS );
|
final AnnotationMirror idClass = getAnnotationMirror( entityType, ID_CLASS );
|
||||||
if ( idClass != null ) {
|
if ( idClass != null ) {
|
||||||
final Object value = getAnnotationValue( idClass, "value" );
|
final AnnotationValue value = getAnnotationValue( idClass, "value" );
|
||||||
if ( value instanceof TypeMirror ) {
|
if ( value != null ) {
|
||||||
if ( context.getTypeUtils().isSameType( param.asType(), (TypeMirror) value ) ) {
|
if ( context.getTypeUtils().isSameType( param.asType(), (TypeMirror) value.getValue() ) ) {
|
||||||
return FieldType.ID;
|
return FieldType.ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2060,7 +2062,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
AnnotationMirror mirror,
|
AnnotationMirror mirror,
|
||||||
boolean isNative) {
|
boolean isNative) {
|
||||||
|
|
||||||
final AnnotationValue value = getAnnotationValueRef( mirror, "value" );
|
final AnnotationValue value = getAnnotationValue( mirror, "value" );
|
||||||
if ( value != null ) {
|
if ( value != null ) {
|
||||||
final Object query = value.getValue();
|
final Object query = value.getValue();
|
||||||
if ( query instanceof String ) {
|
if ( query instanceof String ) {
|
||||||
|
@ -2142,8 +2144,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
if ( annotation == null ) {
|
if ( annotation == null ) {
|
||||||
throw new AssertionFailure("@Entity annotation should not be missing");
|
throw new AssertionFailure("@Entity annotation should not be missing");
|
||||||
}
|
}
|
||||||
final String name = (String) getAnnotationValue(annotation, "name");
|
return entityName(resultType, annotation);
|
||||||
return isEmpty(name) ? resultType.asElement().getSimpleName().toString() : name;
|
|
||||||
}
|
}
|
||||||
else if ( primaryEntity != null ) {
|
else if ( primaryEntity != null ) {
|
||||||
return primaryEntity.getSimpleName().toString();
|
return primaryEntity.getSimpleName().toString();
|
||||||
|
@ -2153,6 +2154,17 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String entityName(DeclaredType resultType, AnnotationMirror annotation) {
|
||||||
|
final AnnotationValue name = getAnnotationValue(annotation, "name");
|
||||||
|
if (name != null) {
|
||||||
|
final String explicitName = name.getValue().toString();
|
||||||
|
if ( !explicitName.isEmpty() ) {
|
||||||
|
return explicitName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultType.asElement().getSimpleName().toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static String addFromClauseIfNecessary(String hql, @Nullable String entityType) {
|
private static String addFromClauseIfNecessary(String hql, @Nullable String entityType) {
|
||||||
if ( entityType == null ) {
|
if ( entityType == null ) {
|
||||||
return hql;
|
return hql;
|
||||||
|
@ -2468,8 +2480,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
final TypeElement typeElement = (TypeElement) declaredType.asElement();
|
final TypeElement typeElement = (TypeElement) declaredType.asElement();
|
||||||
final AnnotationMirror mirror = getAnnotationMirror(typeElement, ENTITY );
|
final AnnotationMirror mirror = getAnnotationMirror(typeElement, ENTITY );
|
||||||
if ( mirror != null ) {
|
if ( mirror != null ) {
|
||||||
final Object value = getAnnotationValue( mirror, "name" );
|
final String entityName = entityName(declaredType, mirror);
|
||||||
final String entityName = value instanceof String ? (String) value : typeElement.getSimpleName().toString();
|
|
||||||
return model.getHibernateEntityName().equals( entityName );
|
return model.getHibernateEntityName().equals( entityName );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2622,7 +2633,9 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
final AnnotationMirror by = getAnnotationMirror( parameter, "jakarta.data.repository.By" );
|
final AnnotationMirror by = getAnnotationMirror( parameter, "jakarta.data.repository.By" );
|
||||||
final AnnotationMirror param = getAnnotationMirror( parameter, "jakarta.data.repository.Param" );
|
final AnnotationMirror param = getAnnotationMirror( parameter, "jakarta.data.repository.Param" );
|
||||||
if ( by != null ) {
|
if ( by != null ) {
|
||||||
final String name = (String) castNonNull(getAnnotationValue(by, "value"));
|
final String name =
|
||||||
|
castNonNull(getAnnotationValue(by, "value"))
|
||||||
|
.getValue().toString();
|
||||||
if ( name.contains("<error>") ) {
|
if ( name.contains("<error>") ) {
|
||||||
throw new ProcessLaterException();
|
throw new ProcessLaterException();
|
||||||
}
|
}
|
||||||
|
@ -2631,7 +2644,9 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
.replace('_', '.');
|
.replace('_', '.');
|
||||||
}
|
}
|
||||||
else if ( param != null ) {
|
else if ( param != null ) {
|
||||||
final String name = (String) castNonNull(getAnnotationValue(param, "value"));
|
final String name =
|
||||||
|
castNonNull(getAnnotationValue(param, "value"))
|
||||||
|
.getValue().toString();
|
||||||
if ( name.contains("<error>") ) {
|
if ( name.contains("<error>") ) {
|
||||||
throw new ProcessLaterException();
|
throw new ProcessLaterException();
|
||||||
}
|
}
|
||||||
|
@ -2669,7 +2684,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
if ( name.contentEquals(Constants.BASIC)
|
if ( name.contentEquals(Constants.BASIC)
|
||||||
|| name.contentEquals(Constants.MANY_TO_ONE)
|
|| name.contentEquals(Constants.MANY_TO_ONE)
|
||||||
|| name.contentEquals(Constants.ONE_TO_ONE)) {
|
|| name.contentEquals(Constants.ONE_TO_ONE)) {
|
||||||
if ( FALSE.equals( getAnnotationValue(mirror, "optional") ) ) {
|
AnnotationValue optional = getAnnotationValue(mirror, "optional");
|
||||||
|
if ( optional != null && optional.getValue().equals(FALSE) ) {
|
||||||
nullable = false;
|
nullable = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
||||||
import static org.hibernate.processor.util.Constants.ELEMENT_COLLECTION;
|
import static org.hibernate.processor.util.Constants.ELEMENT_COLLECTION;
|
||||||
import static org.hibernate.processor.util.Constants.MANY_TO_ANY;
|
import static org.hibernate.processor.util.Constants.MANY_TO_ANY;
|
||||||
import static org.hibernate.processor.util.Constants.MANY_TO_MANY;
|
import static org.hibernate.processor.util.Constants.MANY_TO_MANY;
|
||||||
|
import static org.hibernate.processor.util.Constants.MAP_KEY_CLASS;
|
||||||
import static org.hibernate.processor.util.Constants.ONE_TO_MANY;
|
import static org.hibernate.processor.util.Constants.ONE_TO_MANY;
|
||||||
import static org.hibernate.processor.util.NullnessUtil.castNonNull;
|
import static org.hibernate.processor.util.NullnessUtil.castNonNull;
|
||||||
import static org.hibernate.processor.util.TypeUtils.DEFAULT_ANNOTATION_PARAMETER_NAME;
|
import static org.hibernate.processor.util.TypeUtils.DEFAULT_ANNOTATION_PARAMETER_NAME;
|
||||||
|
@ -160,10 +161,11 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor8<@Nullable
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMapKeyType(DeclaredType declaredType, Element element) {
|
private String getMapKeyType(DeclaredType declaredType, Element element) {
|
||||||
final AnnotationMirror annotationMirror = getAnnotationMirror(element, Constants.MAP_KEY_CLASS );
|
final AnnotationMirror annotationMirror = getAnnotationMirror(element, MAP_KEY_CLASS );
|
||||||
return annotationMirror == null
|
return annotationMirror == null
|
||||||
? getKeyType( declaredType, context )
|
? getKeyType( declaredType, context )
|
||||||
: castNonNull( getAnnotationValue( annotationMirror, DEFAULT_ANNOTATION_PARAMETER_NAME ) ).toString();
|
: castNonNull( getAnnotationValue( annotationMirror, DEFAULT_ANNOTATION_PARAMETER_NAME ) )
|
||||||
|
.getValue().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getElementType(DeclaredType declaredType, @Nullable String targetEntity) {
|
private String getElementType(DeclaredType declaredType, @Nullable String targetEntity) {
|
||||||
|
|
|
@ -232,7 +232,8 @@ public final class TypeUtils {
|
||||||
assert annotationMirror != null;
|
assert annotationMirror != null;
|
||||||
assert qualifiedName != null;
|
assert qualifiedName != null;
|
||||||
final Element element = annotationMirror.getAnnotationType().asElement();
|
final Element element = annotationMirror.getAnnotationType().asElement();
|
||||||
return ((TypeElement) element).getQualifiedName().contentEquals( qualifiedName );
|
final TypeElement typeElement = (TypeElement) element;
|
||||||
|
return typeElement.getQualifiedName().contentEquals( qualifiedName );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -268,24 +269,12 @@ public final class TypeUtils {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable Object getAnnotationValue(AnnotationMirror annotationMirror, String parameterValue) {
|
public static @Nullable AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror, String member) {
|
||||||
assert annotationMirror != null;
|
assert annotationMirror != null;
|
||||||
assert parameterValue != null;
|
assert member != null;
|
||||||
for ( Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry
|
for ( Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry
|
||||||
: annotationMirror.getElementValues().entrySet() ) {
|
: annotationMirror.getElementValues().entrySet() ) {
|
||||||
if ( entry.getKey().getSimpleName().contentEquals( parameterValue ) ) {
|
if ( entry.getKey().getSimpleName().contentEquals(member) ) {
|
||||||
return entry.getValue().getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @Nullable AnnotationValue getAnnotationValueRef(AnnotationMirror annotationMirror, String parameterValue) {
|
|
||||||
assert annotationMirror != null;
|
|
||||||
assert parameterValue != null;
|
|
||||||
for ( Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry
|
|
||||||
: annotationMirror.getElementValues().entrySet() ) {
|
|
||||||
if ( entry.getKey().getSimpleName().contentEquals( parameterValue ) ) {
|
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -485,9 +474,9 @@ public final class TypeUtils {
|
||||||
public static @Nullable AccessType determineAnnotationSpecifiedAccessType(Element element) {
|
public static @Nullable AccessType determineAnnotationSpecifiedAccessType(Element element) {
|
||||||
final AnnotationMirror mirror = getAnnotationMirror( element, ACCESS );
|
final AnnotationMirror mirror = getAnnotationMirror( element, ACCESS );
|
||||||
if ( mirror != null ) {
|
if ( mirror != null ) {
|
||||||
final Object accessType = getAnnotationValue( mirror, DEFAULT_ANNOTATION_PARAMETER_NAME );
|
final AnnotationValue accessType = getAnnotationValue( mirror, DEFAULT_ANNOTATION_PARAMETER_NAME );
|
||||||
if ( accessType instanceof VariableElement) {
|
if ( accessType != null ) {
|
||||||
final VariableElement enumValue = (VariableElement) accessType;
|
final VariableElement enumValue = (VariableElement) accessType.getValue();
|
||||||
final Name enumValueName = enumValue.getSimpleName();
|
final Name enumValueName = enumValue.getSimpleName();
|
||||||
if ( enumValueName.contentEquals(PROPERTY) ) {
|
if ( enumValueName.contentEquals(PROPERTY) ) {
|
||||||
return AccessType.PROPERTY;
|
return AccessType.PROPERTY;
|
||||||
|
@ -558,10 +547,10 @@ public final class TypeUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable String getFullyQualifiedClassNameOfTargetEntity(
|
public static @Nullable String getFullyQualifiedClassNameOfTargetEntity(
|
||||||
AnnotationMirror mirror, String parameterName) {
|
AnnotationMirror mirror, String member) {
|
||||||
final Object parameterValue = getAnnotationValue( mirror, parameterName );
|
final AnnotationValue value = getAnnotationValue( mirror, member);
|
||||||
if ( parameterValue != null ) {
|
if ( value != null ) {
|
||||||
final TypeMirror parameterType = (TypeMirror) parameterValue;
|
final TypeMirror parameterType = (TypeMirror) value.getValue();
|
||||||
if ( parameterType.getKind() != TypeKind.VOID ) {
|
if ( parameterType.getKind() != TypeKind.VOID ) {
|
||||||
return parameterType.toString();
|
return parameterType.toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue