Skip to content

Commit

Permalink
Make sure ununi does not throw given a Uni<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage authored and gavinking committed Mar 1, 2024
1 parent ed29057 commit 06136ba
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,9 @@ private String addDaoConstructor(@Nullable ExecutableElement method) {
*/
private static boolean isSessionGetter(ExecutableElement method) {
if ( method.getParameters().isEmpty() ) {
final TypeMirror type = method.getReturnType();
final TypeMirror type = ununi( method.getReturnType() );
if ( type.getKind() == TypeKind.DECLARED ) {
final DeclaredType declaredType = ununi( (DeclaredType) type );
final DeclaredType declaredType = (DeclaredType) type;
final Element element = declaredType.asElement();
if ( element.getKind() == ElementKind.INTERFACE ) {
final Name name = ((TypeElement) element).getQualifiedName();
Expand Down Expand Up @@ -628,13 +628,13 @@ private void addQueryMethods(List<ExecutableElement> queryMethods) {
}

private void addQueryMethod(ExecutableElement method) {
final TypeMirror returnType = method.getReturnType();
final TypeMirror returnType = ununi( method.getReturnType() );
final TypeKind kind = returnType.getKind();
if ( kind == TypeKind.VOID || kind == TypeKind.ARRAY || kind.isPrimitive() ) {
addQueryMethod( method, returnType, null );
}
else if ( kind == TypeKind.DECLARED ) {
final DeclaredType declaredType = ununi( (DeclaredType) returnType );
final DeclaredType declaredType = (DeclaredType) returnType;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
final List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
switch ( typeArguments.size() ) {
Expand Down Expand Up @@ -711,11 +711,16 @@ private boolean validatedQueryReturnType(ExecutableElement method, TypeElement t
}
}

private static DeclaredType ununi(DeclaredType returnType) {
final TypeElement typeElement = (TypeElement) returnType.asElement();
return typeElement.getQualifiedName().contentEquals(Constants.UNI)
? (DeclaredType) returnType.getTypeArguments().get(0)
: returnType;
private static TypeMirror ununi(TypeMirror returnType) {
if ( returnType.getKind() != TypeKind.DECLARED ) {
return returnType;
}
DeclaredType declaredType = (DeclaredType) returnType;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
if ( typeElement.getQualifiedName().contentEquals( Constants.UNI ) ) {
returnType = declaredType.getTypeArguments().get(0);
}
return returnType;
}

private static boolean isLegalRawResultType(String containerTypeName) {
Expand Down Expand Up @@ -853,6 +858,7 @@ private void addFinderMethod(
ExecutableElement method,
@Nullable TypeMirror returnType,
@Nullable TypeElement containerType) {
returnType = returnType != null ? ununi( returnType ) : null;
if ( returnType == null ) {
context.message( method,
"missing return type",
Expand Down Expand Up @@ -881,7 +887,7 @@ else if ( returnType.getKind() == TypeKind.ARRAY ) {
}
}
else if ( returnType.getKind() == TypeKind.DECLARED ) {
final DeclaredType declaredType = ununi( (DeclaredType) returnType );
final DeclaredType declaredType = (DeclaredType) returnType;
final TypeElement entity = (TypeElement) declaredType.asElement();
if ( !containsAnnotation( entity, Constants.ENTITY ) ) {
context.message( method,
Expand Down

0 comments on commit 06136ba

Please sign in to comment.