paul-bennett / juggle

A declarative search tool for Java APIs
Apache License 2.0
5 stars 0 forks source link

Output of generics is sometimes wrong #116

Closed paul-bennett closed 5 months ago

paul-bennett commented 5 months ago

When emitting a method with generic type parameters, Juggle invariably gets the answer wrong.

Compare this output:

$ juggle -i java.util -i java.util.stream -i java.util.function \

    'Stream (Stream this, ...)' -f plain | grep ' <.> '
public abstract <R> Stream<T> Stream<T>.flatMap(Function<T,R>)
public abstract <R> Stream<T> Stream<T>.map(Function<T,R>)
public <R> Stream<T> Stream<T>.mapMulti(BiConsumer<T,U>)

with this from javap:

$ javap java.util.stream.Stream | grep ' <.> '
public abstract <R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>>);
public abstract <R> Stream<R> map(Function<? super T, ? extends R>);
public default <R> Stream<R> mapMulti(BiConsumer<? super T, ? super Consumer<R>>);

Note how Juggle drops the wildcards and bounds, and doesn't correctly associate type variables across the entire signature (e.g. the type variable R is switched for T in the return type).

paul-bennett commented 5 months ago

Worth investigating the Method.getGenericXxx() methods.

paul-bennett commented 5 months ago

Looks like the trick will be to call t.getActualTypeArguments() from TextOutput.decodeParameterizedType(ParameterizedType t) rather than just pass t.getRawType() down to the decodeType(Type) method.

paul-bennett commented 5 months ago

90% done... one remaining issue is that typenames used in actual parameters aren't stripped of imported packages yet.