From 387949027b99390282257f74b1900e16300c4486 Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Fri, 22 Mar 2024 12:48:26 -0400 Subject: [PATCH] Add TypeMarker static factory method --- .../conjure/java/undertow/lib/TypeMarker.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/TypeMarker.java b/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/TypeMarker.java index 0ce892bde..e9ebc3f37 100644 --- a/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/TypeMarker.java +++ b/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/TypeMarker.java @@ -42,11 +42,24 @@ protected TypeMarker() { genericSuperclass instanceof ParameterizedType, "Class is not parameterized", SafeArg.of("class", genericSuperclass)); - type = ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0]; + Type typeArgument = ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0]; + Preconditions.checkArgument( + !(typeArgument instanceof TypeVariable), + "TypeMarker does not support variable types", + SafeArg.of("typeVariable", typeArgument)); + this.type = typeArgument; + } + + private TypeMarker(Type type) { Preconditions.checkArgument( !(type instanceof TypeVariable), "TypeMarker does not support variable types", SafeArg.of("typeVariable", type)); + this.type = type; + } + + public static TypeMarker of(Type type) { + return new TypeMarker<>(type) {}; } public final Type getType() {