Skip to content

Commit 23fb0bf

Browse files
committed
#251 - Adjustments for fixing Aspects on methods with generic parameters
1 parent 0e44d68 commit 23fb0bf

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

blackbox-test-inject/src/main/java/org/example/myapp/ExampleService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import jakarta.inject.Singleton;
44
import org.example.myapp.aspect.MyTimed;
55

6+
import java.util.List;
67
import java.util.concurrent.ConcurrentHashMap;
78
import java.util.concurrent.atomic.AtomicLong;
89

@@ -31,4 +32,8 @@ public void withParamAtomic(AtomicLong atomicLong) {
3132
public void withParamImport(ConcurrentHashMap<String, String> param0) {
3233
System.out.println("withParamAtomic " + param0);
3334
}
35+
36+
public void withListString(List<String> param0) {
37+
System.out.println("withListString " + param0);
38+
}
3439
}

blackbox-test-inject/src/test/java/org/example/myapp/ExampleServiceTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.avaje.inject.BeanScope;
44
import org.junit.jupiter.api.Test;
55

6+
import java.util.List;
67
import java.util.concurrent.ConcurrentHashMap;
78
import java.util.concurrent.atomic.AtomicLong;
89

@@ -17,6 +18,7 @@ void exercise() {
1718
exampleService.runOnly("foo");
1819
exampleService.withParamAtomic(new AtomicLong(42));
1920
exampleService.withParamImport(new ConcurrentHashMap<>());
21+
exampleService.withListString(List.of("a", "b"));
2022
}
2123
}
2224
}

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ static class MethodParam {
316316
private final UtilType utilType;
317317
private final String paramType;
318318
private final GenericType genericType;
319+
private final GenericType fullGenericType;
319320
private final boolean nullable;
320321
private final String simpleName;
321322
private boolean requestParam;
@@ -328,13 +329,12 @@ static class MethodParam {
328329
this.utilType = Util.determineType(param.asType());
329330
this.paramType = utilType.rawType();
330331
this.genericType = GenericType.parse(paramType);
332+
this.fullGenericType = GenericType.parse(utilType.full());
331333
}
332334

333335
@Override
334336
public String toString() {
335-
return "MethodParam{" +
336-
"genericType=" + genericType +
337-
'}';
337+
return "MethodParam{" + fullGenericType + '}';
338338
}
339339

340340
void addDependsOnGeneric(Set<GenericType> set) {
@@ -393,9 +393,7 @@ Dependency getDependsOn() {
393393
}
394394

395395
void addImports(Set<String> importTypes) {
396-
397-
importTypes.addAll(Arrays.asList(utilType.full().split("[<|>|,]")));
398-
396+
fullGenericType.addImports(importTypes);
399397
if (genericType.isGenericType()) {
400398
importTypes.add(Constants.PROVIDER);
401399
}
@@ -431,23 +429,17 @@ void writeMethodParam(Append writer) {
431429
writer.append(" ").append(simpleName);
432430
}
433431

434-
void writeMethodParamType(Append writer) {
435-
writer.append(Util.shortName(genericType.topType()));
436-
}
437-
438432
void writeMethodParamAspect(Append writer) {
439-
final var type = GenericType.parse(utilType.full());
440-
if (type.isGenericType()) {
441-
type.writeShort(writer);
433+
if (fullGenericType.isGenericType()) {
434+
fullGenericType.writeShort(writer);
442435
} else {
443-
writer.append(Util.shortName(type.topType()));
436+
writer.append(Util.shortName(fullGenericType.topType()));
444437
}
445438
writer.append(" ").append(simpleName);
446439
}
447440

448441
void writeMethodParamTypeAspect(Append writer) {
449-
final var type = GenericType.parse(utilType.full());
450-
writer.append(Util.shortName(type.topType()));
442+
writer.append(Util.shortName(fullGenericType.topType()));
451443
}
452444

453445
void writeConstructorInit(Append writer) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ boolean isCollection() {
4646
return type == Type.LIST || type == Type.SET;
4747
}
4848

49+
String full() {
50+
return rawType;
51+
}
52+
4953
String rawType() {
5054
switch (type) {
5155
case SET:
@@ -77,7 +81,4 @@ String getMethod(boolean nullable) {
7781
return nullable ? "getNullable(" : "get(";
7882
}
7983

80-
public String full() {
81-
return rawType;
82-
}
8384
}

0 commit comments

Comments
 (0)