You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when a generator needs to produce generics, implementation details of the library need to be exposed to the user, who needs to receive a Class<T> type parameter (plus constraining annotations) to be able to manually call Generators.gen.
Instead of having the user receive Class<T> class and Class<?> annotations in user-defined generate() methods add support for using type parameters directly:
Hiding implementation details
At present time, our generator implementation for generic classes look something like this:
Internally, they are called with the type parameter of the generated class. They go on to pass that class to the user's default implementation. The user then uses that received type to manually call Generators or another specific generator like this:
This is a clear schism in the usual API we are usually trying to provide for our users, in which they just ask for the parameters they need to build their target class, such as this:
To solve this problem and hide specific parameterizing types from the user, it'd be better if we did the following instead:
In the user-defined generator the user declares parameters as usual. If they don't know the specific type of a parameter, they introduce a variable-type parameter in their generator function:
Internally, when a test or otherwise needs to generate a value of MyParameterizedType<SpecificX, SpecificY>, the type parameters will be resolved and the implementation will be called. The implementation receives those type parameters as input, resolves them to specific values, just the same as any other type, and then calls the user code:
Currently, when a generator needs to produce generics, implementation details of the library need to be exposed to the user, who needs to receive a
Class<T> type
parameter (plus constraining annotations) to be able to manually callGenerators.gen
.Instead of having the user receive
Class<T> class
andClass<?> annotations
in user-definedgenerate()
methods add support for using type parameters directly:Hiding implementation details
At present time, our generator implementation for generic classes look something like this:
Internally, they are called with the type parameter of the generated class. They go on to pass that class to the user's default implementation. The user then uses that received type to manually call
Generators
or another specific generator like this:This is a clear schism in the usual API we are usually trying to provide for our users, in which they just ask for the parameters they need to build their target class, such as this:
or this:
To solve this problem and hide specific parameterizing types from the user, it'd be better if we did the following instead:
In the user-defined generator the user declares parameters as usual. If they don't know the specific type of a parameter, they introduce a variable-type parameter in their generator function:
Internally, when a test or otherwise needs to generate a value of
MyParameterizedType<SpecificX, SpecificY>
, the type parameters will be resolved and the implementation will be called. The implementation receives those type parameters as input, resolves them to specific values, just the same as any other type, and then calls the user code:In this way, generics are handled just like any other type.
The text was updated successfully, but these errors were encountered: