Skip to content

Commit ac55d9e

Browse files
committed
Also detect @jakarta.inject.Inject annotations
1 parent df00284 commit ac55d9e

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

macros/src/main/scala-2/com/softwaremill/macwire/internals/ConstructorCrimper.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ object ConstructorCrimper {
7474
lazy val primaryConstructor: Option[Symbol] = publicConstructors.find(_.asMethod.isPrimaryConstructor)
7575

7676
lazy val injectConstructors: Iterable[Symbol] = {
77-
val isInjectAnnotation = (a: Annotation) => a.toString == "javax.inject.Inject"
77+
val isInjectAnnotation = (a: Annotation) =>
78+
a.toString == "javax.inject.Inject" || a.toString == "jakarta.inject.Inject"
7879
val ctors = publicConstructors.filter(_.annotations.exists(isInjectAnnotation))
79-
log.withBlock(s"There are ${ctors.size} constructors annotated with @javax.inject.Inject") {
80+
log.withBlock(
81+
s"There are ${ctors.size} constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject"
82+
) {
8083
ctors.foreach(s => log(showConstructor(c)(s)))
8184
}
8285
ctors
@@ -86,7 +89,7 @@ object ConstructorCrimper {
8689
if (injectConstructors.size > 1)
8790
c.abort(
8891
c.enclosingPosition,
89-
s"Ambiguous constructors annotated with @javax.inject.Inject for type [$targetType]"
92+
s"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [$targetType]"
9093
)
9194
else injectConstructors.headOption
9295

macros/src/main/scala-3/com/softwaremill/macwire/internals/ConstructorCrimper.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,22 @@ private[macwire] class ConstructorCrimper[Q <: Quotes, T: Type](using val q: Q)(
3434
}
3535

3636
lazy val injectConstructors: Iterable[Symbol] = {
37-
val isInjectAnnotation = (a: Term) => a.tpe.typeSymbol.fullName == "javax.inject.Inject"
37+
val isInjectAnnotation = (a: Term) =>
38+
a.tpe.typeSymbol.fullName == "javax.inject.Inject" || a.tpe.typeSymbol.fullName == "jakarta.inject.Inject"
3839
val ctors = publicConstructors.filter(_.annotations.exists(isInjectAnnotation))
39-
log.withBlock(s"There are ${ctors.size} constructors annotated with @javax.inject.Inject") {
40+
log.withBlock(
41+
s"There are ${ctors.size} constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject"
42+
) {
4043
ctors.foreach(c => log(showConstructor(c)))
4144
}
4245
ctors
4346
}
4447

4548
lazy val injectConstructor: Option[Symbol] =
4649
if (injectConstructors.size > 1)
47-
abort(s"Ambiguous constructors annotated with @javax.inject.Inject for type [${targetType.typeSymbol.name}]")
50+
abort(
51+
s"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [${targetType.typeSymbol.name}]"
52+
)
4853
else injectConstructors.headOption
4954

5055
lazy val constructor: Option[Symbol] = log.withBlock(s"Looking for constructor for $targetType") {

macros/src/main/scala-3/com/softwaremill/macwire/internals/autowire/creator.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,20 @@ object Constructor:
8787
case c => None
8888

8989
val injectConstructors: Iterable[Symbol] =
90-
val isInjectAnnotation = (a: Term) => a.tpe.typeSymbol.fullName == "javax.inject.Inject"
90+
val isInjectAnnotation = (a: Term) =>
91+
a.tpe.typeSymbol.fullName == "javax.inject.Inject" || a.tpe.typeSymbol.fullName == "jakarta.inject.Inject"
9192
val ctors = publicConstructors.filter(_.annotations.exists(isInjectAnnotation))
92-
log.withBlock(s"there are ${ctors.size} constructors annotated with @javax.inject.Inject") {
93+
log.withBlock(
94+
s"there are ${ctors.size} constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject"
95+
) {
9396
ctors.foreach(c => log(c.toString))
9497
}
9598
ctors
9699

97100
val injectConstructor: Option[Symbol] =
98101
if injectConstructors.size > 1 then
99102
reportError(
100-
s"multiple constructors annotated with @javax.inject.Inject for type: ${showTypeName(forType)}"
103+
s"multiple constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type: ${showTypeName(forType)}"
101104
)
102105
else injectConstructors.headOption
103106

0 commit comments

Comments
 (0)