Skip to content

Make TypeVisitor public #7838

@jiquera

Description

@jiquera

API(s)

com.google.common.reflect.TypeVisitor

How do you want it to be improved?

Make it public

Why do we need it to be improved?

This is a very useful class for e.g. computing class distances in the class-hierarchy (we use this to do runtime factory matching), checking if a type is concrete and several other use cases. However, currently it's not accessible AND because it's relatively simple it's awkward to make an alternative implementation without triggering copyright scanners.

Example

In our case we use OSGI to find factories that generate GUI components based on types. In order to find the best possible match we compute the distance of the type-to-render to the supported type by the factory (equal = 0, superclass = 1,...). I'd like extend this from Classes to Types so we can use wildcards. However, the code needed for this is almost exactly what TypeVisitor does which causes our copyright scanners to trigger.

Current Behavior

It's currently package private

Desired Behavior

I'd like to make it publicly available

Concrete Use Cases

In our case we use OSGI to find factories that generate GUI components based on types. In order to find the best possible match we compute the distance of the type-to-render to the supported type by the factory (equal = 0, superclass = 1,...). I'd like extend this from Classes to Types so we can use wildcards. However, the code needed for this is almost exactly what TypeVisitor does which causes our copyright scanners to trigger.

Additionally in the new system I'd like to reject typevariables in the factory declarations (I use the typetoken trick to define their supported input types as the class parameter) as they would not make sense.

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions