look for primary entity type in indirectly-implemented interfaces

for Jakarta Data TCK work

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-04 11:31:34 +02:00
parent ff0e676825
commit 6b1b8d65ed
1 changed files with 21 additions and 2 deletions

View File

@ -462,7 +462,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
} }
} }
private @Nullable TypeElement primaryEntity(List<ExecutableElement> lifecycleMethods) { private static @Nullable TypeElement primaryEntity(TypeElement element) {
for (TypeMirror typeMirror : element.getInterfaces()) { for (TypeMirror typeMirror : element.getInterfaces()) {
final DeclaredType declaredType = (DeclaredType) typeMirror; final DeclaredType declaredType = (DeclaredType) typeMirror;
final TypeElement typeElement = (TypeElement) declaredType.asElement(); final TypeElement typeElement = (TypeElement) declaredType.asElement();
@ -477,8 +477,27 @@ public class AnnotationMetaEntity extends AnnotationMeta {
return (TypeElement) entityDeclared.asElement(); return (TypeElement) entityDeclared.asElement();
} }
} }
else {
final TypeElement primaryEntity = primaryEntity(typeElement);
if ( primaryEntity != null ) {
return primaryEntity;
} }
TypeElement result = null; }
}
return null;
}
private @Nullable TypeElement primaryEntity(List<ExecutableElement> lifecycleMethods) {
// first see if we are a subtype of DataRepository
// in that case, the first type argument determines
// the primary entity type
TypeElement result = primaryEntity(element);
if ( result != null ) {
return result;
}
// otherwise, we have to check all the lifecycle
// methods and determine if they all agree on the
// entity type; if so, it is the primary
final Types types = context.getTypeUtils(); final Types types = context.getTypeUtils();
for ( ExecutableElement element : lifecycleMethods ) { for ( ExecutableElement element : lifecycleMethods ) {
if ( element.getParameters().size()==1 ) { if ( element.getParameters().size()==1 ) {