HHH-17772 support Jakarta Data @By and @Param

This commit is contained in:
Gavin King 2024-02-23 12:53:38 +01:00
parent 5be9463364
commit aed8244dae
1 changed files with 17 additions and 3 deletions

View File

@ -1020,7 +1020,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
} }
context.message( param, context.message( param,
"no matching field named '" "no matching field named '"
+ param.getSimpleName().toString().replace('$', '.') + parameterName( param ).replace('$', '.')
+ "' in entity class '" + entityType + "'", + "' in entity class '" + entityType + "'",
Diagnostic.Kind.ERROR ); Diagnostic.Kind.ERROR );
return null; return null;
@ -1048,7 +1048,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
} }
private @Nullable Element memberMatchingParameter(TypeElement entityType, VariableElement param) { private @Nullable Element memberMatchingParameter(TypeElement entityType, VariableElement param) {
final StringTokenizer tokens = new StringTokenizer( param.getSimpleName().toString(), "$" ); final StringTokenizer tokens = new StringTokenizer( parameterName( param ), "$" );
return memberMatchingParameter( entityType, param, tokens ); return memberMatchingParameter( entityType, param, tokens );
} }
@ -1531,10 +1531,24 @@ public class AnnotationMetaEntity extends AnnotationMeta {
private static List<String> parameterNames(ExecutableElement method) { private static List<String> parameterNames(ExecutableElement method) {
return method.getParameters().stream() return method.getParameters().stream()
.map(param -> param.getSimpleName().toString()) .map(AnnotationMetaEntity::parameterName)
.collect(toList()); .collect(toList());
} }
private static String parameterName(VariableElement parameter) {
final AnnotationMirror by = getAnnotationMirror( parameter, "jakarta.data.repository.By" );
final AnnotationMirror param = getAnnotationMirror( parameter, "jakarta.data.repository.Param" );
if ( by != null ) {
return (String) castNonNull( getAnnotationValue( by, "value" ) );
}
else if ( param != null ) {
return (String) castNonNull( getAnnotationValue( param, "value" ) );
}
else {
return parameter.getSimpleName().toString();
}
}
private static boolean isNullable(Element member) { private static boolean isNullable(Element member) {
switch ( member.getKind() ) { switch ( member.getKind() ) {
case METHOD: case METHOD: