Skip to content

Commit

Permalink
fix nested wildcardtype generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Mar 3, 2018
1 parent 58fc447 commit 3be6be0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
16 changes: 11 additions & 5 deletions processor/src/main/java/org/bsc/processor/TypescriptHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class TypescriptHelper {
private final static void log( String fmt, Object ...args ) {
//System.out.println( format( fmt, (Object[])args));
}

private final static void debug( String fmt, Object ...args ) {
System.out.print( "DEBUG: ");
System.out.println( format( fmt, (Object[])args));
}

public static final String processFunctionalInterface( TSType type ) {
Objects.requireNonNull(type, "argument 'type' is not defined!");
Expand Down Expand Up @@ -328,15 +333,16 @@ else if( t instanceof WildcardType ) {
packageResolution,
onTypeMismatch);

result = result.replace( wt.getTypeName(), s);

// CHECK FOR NESTED WILDCARDTYPE
if( tt instanceof ParameterizedType &&
Stream.of((Type[])((ParameterizedType)tt).getActualTypeArguments())
.anyMatch( arg -> (arg instanceof WildcardType) ))
{
// not supportded nested WildcardType
result = format( "%s/*%s*/", s, wt.getTypeName() ) ;
}
else {
result = result.replace( wt.getTypeName(), s);
final Class<?> clazz = (Class<?>) (((ParameterizedType)tt).getRawType());
final String typeName = wt.getTypeName().replace( clazz.getName(), clazz.getSimpleName());
result = result.replace( typeName, s);
}
}
else {
Expand Down
24 changes: 23 additions & 1 deletion processor/src/test/java/org/bsc/processor/ProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -42,7 +44,27 @@ public void testWildcardType() throws Exception {
true) ;

Assert.assertThat( result, IsNull.notNullValue());
Assert.assertThat( result, IsEqual.equalTo("<T>( source:Sample2<T>/*? extends org.bsc.processor.Sample2<? extends T>*/ ):void"));
Assert.assertThat( result, IsEqual.equalTo("<T>( source:Sample2<Sample2<T>> ):void"));
}
{
final Method m = type.getValue().getMethod("merge", BiConsumer.class );
final String result = processor.getMethodParametersAndReturnDecl( m,
type,
declaredTypeMap( TSType.from(String.class), TSType.from(Sample2.class), TSType.from(BiConsumer.class)),
true) ;

Assert.assertThat( result, IsNull.notNullValue());
Assert.assertThat( result, IsEqual.equalTo("<T>( source:BiConsumer<E, Sample2<Sample2<T>>> ):void"));
}
{
final Method m = type.getValue().getMethod("concatMap", Function.class );
final String result = processor.getMethodParametersAndReturnDecl( m,
type,
declaredTypeMap( TSType.from(String.class), TSType.from(Sample2.class), TSType.functional(Function.class, "Func")),
true) ;

Assert.assertThat( result, IsNull.notNullValue());
Assert.assertThat( result, IsEqual.equalTo("<T>( mapper:Func<E, Sample2<T>> ):T"));
}

}
Expand Down
5 changes: 5 additions & 0 deletions processor/src/test/java/org/bsc/processor/Sample1.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.bsc.processor;

import java.util.concurrent.Future;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;

public interface Sample1<E> {

Expand Down Expand Up @@ -40,4 +42,7 @@ public interface Sample1<E> {
E creator( java.util.concurrent.Callable<E> supplier);

<T> void merge(Sample2<? extends Sample2<? extends T>> source);
<T> void merge(BiConsumer<E,Sample2<? extends Sample2<? extends T>>> source);
<T> T concatMap(Function<? super E, ? extends Sample2<? extends T>> mapper);

}

0 comments on commit 3be6be0

Please sign in to comment.