Skip to content

Commit 66d1675

Browse files
committed
#144 - Implied qualifier name for constructor parameters takes [suffix] type name into account
1 parent 3434467 commit 66d1675

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,14 @@ String builderGetDependency(String builderName) {
266266
sb.append(",\"").append(named).append("\"");
267267
} else if (!isGenericParam() && utilType.allowsNamedQualifier()) {
268268
// implied qualifier name, leading '!' means implied
269-
sb.append(",\"!").append(simpleName).append("\"");
269+
sb.append(",\"!");
270+
final String shortName = Util.shortName(paramType);
271+
if (simpleName.endsWith(shortName)) {
272+
sb.append(simpleName, 0, simpleName.length() - shortName.length());
273+
} else {
274+
sb.append(simpleName);
275+
}
276+
sb.append("\"");
270277
}
271278
sb.append(")");
272279
return sb.toString();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.example.coffee.primary;
2+
3+
import jakarta.inject.Named;
4+
import jakarta.inject.Singleton;
5+
6+
@Singleton
7+
public class UseNamedPEmailer {
8+
9+
private final PEmailer emailer;
10+
private final PEmailer other;
11+
private final PEmailer otherPEmailer;
12+
13+
public UseNamedPEmailer(@Named("Other") PEmailer emailer, PEmailer other, PEmailer otherPEmailer) {
14+
this.emailer = emailer;
15+
this.other = other;
16+
this.otherPEmailer = otherPEmailer;
17+
}
18+
19+
public String emailNamed() {
20+
return emailer.email();
21+
}
22+
23+
public String emailOther() {
24+
return other.email();
25+
}
26+
27+
public String emailOtherPEmailer() {
28+
return otherPEmailer.email();
29+
}
30+
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.example.coffee.primary;
2+
3+
import io.avaje.inject.ApplicationScope;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
class UseNamedPEmailerTest {
9+
10+
@Test
11+
void named_secondary() {
12+
UseNamedPEmailer bean = ApplicationScope.get(UseNamedPEmailer.class);
13+
assertThat(bean.emailNamed()).isEqualTo("other");
14+
assertThat(bean.emailOther()).isEqualTo("other");
15+
assertThat(bean.emailOtherPEmailer()).isEqualTo("other");
16+
}
17+
}

0 commit comments

Comments
 (0)