Skip to content

Commit 01583f8

Browse files
committed
#175 - Interfaces with generic type parameters that extend other interfaces, don't PROVIDE those extended interfaces
1 parent def3165 commit 01583f8

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/TypeExtendsReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import javax.lang.model.type.TypeMirror;
66
import java.util.ArrayList;
77
import java.util.List;
8-
import java.util.Set;
98

109
/**
1110
* Read the inheritance types for a given bean type.
@@ -152,7 +151,8 @@ private void readInterfaces(TypeElement type) {
152151
}
153152

154153
private void readExtendedInterfaces(String type) {
155-
final TypeElement element = context.element(type);
154+
GenericType genericType = GenericType.parse(type);
155+
final TypeElement element = context.element(genericType.topType());
156156
if (element != null) {
157157
readInterfaces(element);
158158
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.example.generic;
2+
3+
public interface BuildTask {
4+
5+
void build();
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.example.generic;
2+
3+
public interface BuildTaskWith<T> extends BuildTask {
4+
5+
void prepareWith(T param);
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.example.generic;
2+
3+
import jakarta.inject.Singleton;
4+
5+
import java.nio.file.Path;
6+
7+
@Singleton
8+
public class PathBuildTask implements BuildTaskWith<Path> {
9+
10+
@Override
11+
public void prepareWith(Path param) {
12+
// do nothing
13+
}
14+
15+
@Override
16+
public void build() {
17+
// do nothing
18+
}
19+
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.example.generic;
2+
3+
import io.avaje.inject.BeanScope;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
class PathBuildTaskTest {
9+
10+
@Test
11+
void genericInterfaceWithExtends_expect_providesExtendedInterface() {
12+
13+
try (BeanScope beanScope = BeanScope.newBuilder().build()) {
14+
15+
PathBuildTask pathBuildTask = beanScope.get(PathBuildTask.class);
16+
BuildTask buildTask = beanScope.get(BuildTask.class);
17+
18+
// PathBuildTask is registered as providing PathBuildTask.class, BuildTask.class and generic TYPE_BuildTaskWithPath
19+
assertThat(pathBuildTask).isSameAs(buildTask);
20+
21+
Object viaType = beanScope.get(PathBuildTask$DI.TYPE_BuildTaskWithPath, null);
22+
assertThat(viaType).isSameAs(buildTask);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)