eliminate duplicate error messages

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-03-26 17:51:09 +01:00
parent 526ab68264
commit e37ca54981
1 changed files with 13 additions and 8 deletions

View File

@ -367,6 +367,10 @@ public class AnnotationMetaEntity extends AnnotationMeta {
} }
primaryEntity = primaryEntity( lifecycleMethods ); primaryEntity = primaryEntity( lifecycleMethods );
if ( !lifecycleMethods.isEmpty() ) {
validateStatelessSessionType();
}
} }
else { else {
determineAccessTypeForHierarchy( element, context ); determineAccessTypeForHierarchy( element, context );
@ -407,6 +411,14 @@ public class AnnotationMetaEntity extends AnnotationMeta {
initialized = true; initialized = true;
} }
private void validateStatelessSessionType() {
if ( !usingStatelessSession(sessionType) ) {
message( element,
"repository must be backed by a 'StatelessSession'",
Diagnostic.Kind.ERROR );
}
}
private @Nullable TypeElement primaryEntity(List<ExecutableElement> lifecycleMethods) { private @Nullable TypeElement primaryEntity(List<ExecutableElement> lifecycleMethods) {
for (TypeMirror typeMirror : element.getInterfaces()) { for (TypeMirror typeMirror : element.getInterfaces()) {
final DeclaredType declaredType = (DeclaredType) typeMirror; final DeclaredType declaredType = (DeclaredType) typeMirror;
@ -1151,14 +1163,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
private void addLifecycleMethod(ExecutableElement method) { private void addLifecycleMethod(ExecutableElement method) {
final TypeMirror returnType = ununi(method.getReturnType()); final TypeMirror returnType = ununi(method.getReturnType());
if ( !HIB_STATELESS_SESSION.equals(sessionType) if ( method.getParameters().size() != 1 ) {
&& !MUTINY_STATELESS_SESSION.equals(sessionType)
&& !UNI_MUTINY_STATELESS_SESSION.equals(sessionType) ) {
message( method,
"repository must be backed by a 'StatelessSession'",
Diagnostic.Kind.ERROR );
}
else if ( method.getParameters().size() != 1 ) {
message( method, message( method,
"must have exactly one parameter", "must have exactly one parameter",
Diagnostic.Kind.ERROR ); Diagnostic.Kind.ERROR );