-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Iterate over implementations in isPossibleType #4033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,25 @@ public static TypeInfo typeInfo(Type type) { | |
| return new TypeInfo(type); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the type name of a [Type], unwrapping any lists or non-null decorations | ||
| * | ||
| * @param type the Type | ||
| * | ||
| * @return the inner TypeName for this type | ||
| */ | ||
| public static TypeName getTypeName(Type type) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What |
||
| while (!(type instanceof TypeName)) { | ||
| if (type instanceof NonNullType) { | ||
| type = ((NonNullType) type).getType(); | ||
| } | ||
| if (type instanceof ListType) { | ||
| type = ((ListType) type).getType(); | ||
| } | ||
| } | ||
| return (TypeName) type; | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a unit test and some JavaDoc |
||
| private final Type rawType; | ||
| private final TypeName typeName; | ||
| private final Deque<Class<?>> decoration = new ArrayDeque<>(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,4 +136,21 @@ class TypeInfoTest extends Specification { | |
| "[named!]!" | "[newName!]!" | ||
| "[[named!]!]" | "[[newName!]!]" | ||
| } | ||
|
|
||
| def "test getTypeName gets to the inner type"() { | ||
|
|
||
| expect: | ||
| Type actualType = TestUtil.parseType(actual) | ||
| def typeName = TypeInfo.getTypeName(actualType) | ||
| typeName.getName() == expected | ||
|
|
||
| where: | ||
| actual | expected | ||
| "named" | "named" | ||
| "named!" | "named" | ||
| "[named]" | "named" | ||
| "[named!]" | "named" | ||
| "[named!]!" | "named" | ||
| "[[named!]!]" | "named" | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth investing in a cached reverse lookup at some point instead of looking through all the types everytime. Maybe on that new read only type registry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you see this reverse lookup working - simply a map of name -> type say or somethings else?
ps the read only type registry PR is now merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i know now - I suspect you want something like