Skip to content
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

ResolvedType.getAllTypes() returns parent, this, and interfaces #56

Closed
wants to merge 1 commit into from

Conversation

krzysiekbielicki
Copy link

Convenience method for the full set of types for a type (fixes #50)

@cowtowncoder
Copy link
Member

@krzysiekbielicki Thank you for contributing this! I hope to check out PR soon but have a few things queued up -- but I wanted to add a note to say that I saw this and will try to get to it ASAP.

@ljnelson WDYT?

@cowtowncoder cowtowncoder added hacktoberfest Issue related to Hactoberfest2020 activities, eligible for additional rewards hacktoberfest-accepted Tag for issues, PRs that are explicitly marked as accepted for Hacktoberfest labels Oct 16, 2020
@ljnelson
Copy link

I'll let you folks figure it out. I did my own thing over here. I opted to always include the full set of types, i.e. not just the parent but the grandparent and so on. See: https://microbean.github.io/microbean-type/apidocs/org/microbean/type/Types.html#toTypes(java.lang.reflect.Type)

@cowtowncoder
Copy link
Member

Ah, right. So as implemented the method does not include types recursively, but only immediate parent. So yes, that should be added; at least I don't see as much value in something that only includes immediate super types.

*
* @return List of parent, current and interfaces of this type containing at least current type
*/
public List<ResolvedType> getAllTypes() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to resolve super types recursively, as methods called will only include immediate super class, interfaces implemented; but not super types of those types.

I think name should be getAllSuperTypes(); I also think that list should NOT include type itself (so that name makes sense in that context).
It might make sense to refactor this so that were two variants:

  1. getAllSuperTypes() to work as described
  2. addAllSuperTypes(Collection<ResolvedType>) that would add types into given set

... and come to think of this, I realized that List does not quite make sense here, for two reasons:

  1. There is no well-defined ordering for inclusion; for this reason, we could just use Collection. But further,
  2. Since it will be necessary to avoid duplicate interfaces (there are cases where things like java.io.Serializable are implemented via multiple super-interfaces).

So most likely return type really should be Set. This does open up some further questions (should differently parameterized super-types -- say, Comparable<X> vs Comparable<Y>; or, some cases, "raw" variant -- be included once or multiple times), but for now simple equality could work (which would lead to double inclusion for varying type parameters).

Finally, there may be a problem with recusive types (most common being Enum...), so a test for that might be needed. But I can take care of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issue related to Hactoberfest2020 activities, eligible for additional rewards hacktoberfest-accepted Tag for issues, PRs that are explicitly marked as accepted for Hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFE: Add a convenience method for the full set of types for a type
3 participants