From 00aa09169dffe282b76a0cbe17304747b2d616d6 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Fri, 22 Mar 2024 12:54:13 -0400 Subject: [PATCH 1/2] Expose a TypeMarker factory to wrap an arbitrary Type --- .../conjure/java/undertow/lib/TypeMarker.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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..fe136bca9 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 @@ -21,6 +21,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; +import java.util.Objects; /** * Captures generic type information. @@ -49,6 +50,10 @@ protected TypeMarker() { SafeArg.of("typeVariable", type)); } + private TypeMarker(Type type) { + this.type = Preconditions.checkNotNull(type, "Type is required"); + } + public final Type getType() { return type; } @@ -57,4 +62,29 @@ public final Type getType() { public final String toString() { return "TypeMarker{type=" + type + '}'; } + + /** Create a new {@link TypeMarker} instance wrapping the provided {@link Type}. */ + public static TypeMarker of(Type type) { + return new WrappingTypeMarker(type); + } + + private static final class WrappingTypeMarker extends TypeMarker { + private WrappingTypeMarker(Type type) { + super(type); + } + + @Override + public int hashCode() { + return getType().hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other instanceof WrappingTypeMarker) { + WrappingTypeMarker otherMarker = (WrappingTypeMarker) other; + return Objects.equals(getType(), otherMarker.getType()); + } + return false; + } + } } From 577c65ca35efa6f0f30312c6d73aaed69bf25e46 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Fri, 22 Mar 2024 17:05:56 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-2264.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-2264.v2.yml diff --git a/changelog/@unreleased/pr-2264.v2.yml b/changelog/@unreleased/pr-2264.v2.yml new file mode 100644 index 000000000..6c2901696 --- /dev/null +++ b/changelog/@unreleased/pr-2264.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Expose a TypeMarker factory to wrap an arbitrary Type + links: + - https://github.com/palantir/conjure-java/pull/2264