HHH-16515 - Get rid of nullness suppression in jpamodelgen TypeUtils
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
7ff76bf6eb
commit
d325a5e90d
|
@ -0,0 +1,11 @@
|
||||||
|
// Checkerframework stubs for javax.lang
|
||||||
|
|
||||||
|
package javax.lang.model.util;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
public interface Types {
|
||||||
|
public WildcardType getWildcardType(
|
||||||
|
@Nullable TypeMirror extendsBound,
|
||||||
|
@Nullable TypeMirror superBound);
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
import javax.lang.model.element.AnnotationMirror;
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
import javax.lang.model.element.AnnotationValue;
|
import javax.lang.model.element.AnnotationValue;
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
|
@ -124,16 +125,15 @@ public final class TypeUtils {
|
||||||
return mirror == null ? "?" : mirror.toString();
|
return mirror == null ? "?" : mirror.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable TypeMirror lowerBound(TypeMirror bound) {
|
private static @Nullable TypeMirror lowerBound(@Nullable TypeMirror bound) {
|
||||||
return bound.getKind() == TypeKind.NULL ? null : bound;
|
return bound == null || bound.getKind() == TypeKind.NULL ? null : bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable TypeMirror upperBound(TypeMirror bound) {
|
private static @Nullable TypeMirror upperBound(@Nullable TypeMirror bound) {
|
||||||
return bound.getKind() == TypeKind.DECLARED && bound.toString().equals("java.lang.Object") ? null : bound;
|
return bound == null || (bound.getKind() == TypeKind.DECLARED && bound.toString().equals("java.lang.Object")) ? null : bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nullness")
|
public static @Nullable TypeMirror extractClosestRealType(TypeMirror type, Context context) {
|
||||||
public static TypeMirror extractClosestRealType(TypeMirror type, Context context) {
|
|
||||||
if ( type == null ) {
|
if ( type == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -153,10 +153,17 @@ public final class TypeUtils {
|
||||||
case DECLARED:
|
case DECLARED:
|
||||||
final DeclaredType declaredType = (DeclaredType) type;
|
final DeclaredType declaredType = (DeclaredType) type;
|
||||||
final TypeElement typeElement = (TypeElement) declaredType.asElement();
|
final TypeElement typeElement = (TypeElement) declaredType.asElement();
|
||||||
return context.getTypeUtils().getDeclaredType( typeElement,
|
return context.getTypeUtils().getDeclaredType(
|
||||||
|
typeElement,
|
||||||
declaredType.getTypeArguments().stream()
|
declaredType.getTypeArguments().stream()
|
||||||
.map( arg -> extractClosestRealType( arg, context ) )
|
.map( new Function<TypeMirror, TypeMirror>() {
|
||||||
.toArray( TypeMirror[]::new ) );
|
@Override
|
||||||
|
public @Nullable TypeMirror apply(TypeMirror arg) {
|
||||||
|
return extractClosestRealType( arg, context );
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
.toArray( TypeMirror[]::new )
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return context.getTypeUtils().erasure( type );
|
return context.getTypeUtils().erasure( type );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue