diff --git a/src/main/java/io/vlingo/xoom/actors/ProxyGenerator.java b/src/main/java/io/vlingo/xoom/actors/ProxyGenerator.java index 3a0f0448..6053e4af 100644 --- a/src/main/java/io/vlingo/xoom/actors/ProxyGenerator.java +++ b/src/main/java/io/vlingo/xoom/actors/ProxyGenerator.java @@ -24,6 +24,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; +import java.lang.reflect.WildcardType; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -666,6 +667,11 @@ private static Stream typeNameToTypeStream(final Type type) { Arrays.stream(paramType.getActualTypeArguments()).flatMap(GenericParser::typeNameToTypeStream), typeNameToTypeStream(paramType.getRawType()) ); + } else if (type instanceof WildcardType) { + return Stream.concat( + Arrays.stream(((WildcardType) type).getUpperBounds()), + Arrays.stream(((WildcardType) type).getLowerBounds()) + ).flatMap(GenericParser::typeNameToTypeStream); } return Arrays.stream(type.getTypeName().replaceAll("[<>]", "==").split("==")); diff --git a/src/test/java/io/vlingo/xoom/actors/ProxyGeneratorTest.java b/src/test/java/io/vlingo/xoom/actors/ProxyGeneratorTest.java index a30c9cc1..122723ea 100644 --- a/src/test/java/io/vlingo/xoom/actors/ProxyGeneratorTest.java +++ b/src/test/java/io/vlingo/xoom/actors/ProxyGeneratorTest.java @@ -40,6 +40,30 @@ public void testThatImportsNestedGenerics() { assertTrue("RuntimeException is not imported", result.source.contains("import java.lang.RuntimeException;")); } + @Test + public void testThatGenericsWithUpperBoundsAreImported() { + ProxyGenerator.Result result = proxyGenerator.generateFor(ProtocolWithUpperBoundsInGenerics.class.getCanonicalName()); + + assertTrue("Completes is not imported", result.source.contains("import io.vlingo.xoom.common.Completes;")); + assertTrue("List is not imported", result.source.contains("import java.util.List;")); + assertTrue("RuntimeException is not imported", result.source.contains("import java.lang.RuntimeException;")); + assertTrue("Queue is not imported", result.source.contains("import java.util.Queue;")); + assertFalse("A generic type is imported", result.source.contains("import A;")); + assertFalse("B generic type is imported", result.source.contains("import B;")); + } + + @Test + public void testThatGenericsWithLowerBoundsAreImported() { + ProxyGenerator.Result result = proxyGenerator.generateFor(ProtocolWithLowerBoundsInGenerics.class.getCanonicalName()); + + assertTrue("Completes is not imported", result.source.contains("import io.vlingo.xoom.common.Completes;")); + assertTrue("List is not imported", result.source.contains("import java.util.List;")); + assertTrue("RuntimeException is not imported", result.source.contains("import java.lang.RuntimeException;")); + assertTrue("Queue is not imported", result.source.contains("import java.util.Queue;")); + assertFalse("A generic type is imported", result.source.contains("import A;")); + assertFalse("B generic type is imported", result.source.contains("import B;")); + } + @Test public void testThatMethodDefinitionIsValid() { ProxyGenerator.Result result = proxyGenerator.generateFor(ProtocolWithGenericMethods.class.getCanonicalName()); @@ -139,6 +163,16 @@ interface ProtocolWithGenerics>> otherMethod(); } +interface ProtocolWithUpperBoundsInGenerics> { + void someMethod(List> queues); + void otherMethod(List> queues); +} + +interface ProtocolWithLowerBoundsInGenerics> { + void someMethod(List> queues); + void otherMethod(List> queues); +} + interface ProtocolWithWilcardGenerics> { Completes>> someMethod(); Completes>> otherMethod();