Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ object ConstructorCrimper {
lazy val primaryConstructor: Option[Symbol] = publicConstructors.find(_.asMethod.isPrimaryConstructor)

lazy val injectConstructors: Iterable[Symbol] = {
val isInjectAnnotation = (a: Annotation) => a.toString == "javax.inject.Inject"
val isInjectAnnotation = (a: Annotation) =>
a.toString == "javax.inject.Inject" || a.toString == "jakarta.inject.Inject"
val ctors = publicConstructors.filter(_.annotations.exists(isInjectAnnotation))
log.withBlock(s"There are ${ctors.size} constructors annotated with @javax.inject.Inject") {
log.withBlock(
s"There are ${ctors.size} constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject"
) {
ctors.foreach(s => log(showConstructor(c)(s)))
}
ctors
Expand All @@ -86,7 +89,7 @@ object ConstructorCrimper {
if (injectConstructors.size > 1)
c.abort(
c.enclosingPosition,
s"Ambiguous constructors annotated with @javax.inject.Inject for type [$targetType]"
s"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [$targetType]"
)
else injectConstructors.headOption

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ private[macwire] class ConstructorCrimper[Q <: Quotes, T: Type](using val q: Q)(
}

lazy val injectConstructors: Iterable[Symbol] = {
val isInjectAnnotation = (a: Term) => a.tpe.typeSymbol.fullName == "javax.inject.Inject"
val isInjectAnnotation = (a: Term) =>
a.tpe.typeSymbol.fullName == "javax.inject.Inject" || a.tpe.typeSymbol.fullName == "jakarta.inject.Inject"
val ctors = publicConstructors.filter(_.annotations.exists(isInjectAnnotation))
log.withBlock(s"There are ${ctors.size} constructors annotated with @javax.inject.Inject") {
log.withBlock(
s"There are ${ctors.size} constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject"
) {
ctors.foreach(c => log(showConstructor(c)))
}
ctors
}

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

lazy val constructor: Option[Symbol] = log.withBlock(s"Looking for constructor for $targetType") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,20 @@ object Constructor:
case c => None

val injectConstructors: Iterable[Symbol] =
val isInjectAnnotation = (a: Term) => a.tpe.typeSymbol.fullName == "javax.inject.Inject"
val isInjectAnnotation = (a: Term) =>
a.tpe.typeSymbol.fullName == "javax.inject.Inject" || a.tpe.typeSymbol.fullName == "jakarta.inject.Inject"
val ctors = publicConstructors.filter(_.annotations.exists(isInjectAnnotation))
log.withBlock(s"there are ${ctors.size} constructors annotated with @javax.inject.Inject") {
log.withBlock(
s"there are ${ctors.size} constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject"
) {
ctors.foreach(c => log(c.toString))
}
ctors

val injectConstructor: Option[Symbol] =
if injectConstructors.size > 1 then
reportError(
s"multiple constructors annotated with @javax.inject.Inject for type: ${showTypeName(forType)}"
s"multiple constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type: ${showTypeName(forType)}"
)
else injectConstructors.headOption

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class CompileTests extends CompileTestsSupport {
"type arguments [NotActor] do not conform to macro method wireActor's type parameter bounds [T <: akka.actor.Actor]"
),
"wireProps-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActor]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActor]"
),
"wireAnonymousActor-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActor]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActor]"
),
"wireActor-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActor]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActor]"
),
"wireProps-12-noPublicConstructor" -> List("Cannot find a public constructor for [SomeActor]"),
"wireAnonymousActor-12-noPublicConstructor" -> List("Cannot find a public constructor for [SomeActor]"),
Expand All @@ -54,7 +54,7 @@ class CompileTests extends CompileTestsSupport {
"wireActorWithProducer-6-injectAnnotationButNoDependencyInScope" -> List("Cannot find a value of type: [C]"),
"wireActorWithProducer-7-notActorProducer" -> List("wireActorWith does not support the type: [NotProducer]"),
"wireActorWithProducer-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActorProducer]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActorProducer]"
),
"wireActorWithProducer-12-noPublicConstructor" -> List(
"Cannot find a public constructor for [SomeActorProducer]"
Expand All @@ -76,7 +76,7 @@ class CompileTests extends CompileTestsSupport {
"wireAnonymousActorWith does not support the type: [NotProducer]"
),
"wireAnonymousActorWithProducer-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActorProducer]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActorProducer]"
),
"wireAnonymousActorWithProducer-12-noPublicConstructor" -> List(
"Cannot find a public constructor for [SomeActorProducer]"
Expand All @@ -96,7 +96,7 @@ class CompileTests extends CompileTestsSupport {
"wirePropsWithProducer-6-injectAnnotationButNoDependencyInScope" -> List("Cannot find a value of type: [C]"),
"wirePropsWithProducer-7-notActorProducer" -> List("wirePropsWith does not support the type: [NotProducer]"),
"wirePropsWithProducer-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActorProducer]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActorProducer]"
),
"wirePropsWithProducer-12-noPublicConstructor" -> List(
"Cannot find a public constructor for [SomeActorProducer]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class CompileTests extends CompileTestsSupport {
"type arguments [NotActor] do not conform to macro method wireActor's type parameter bounds [T <: org.apache.pekko.actor.Actor]"
),
"wireProps-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActor]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActor]"
),
"wireAnonymousActor-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActor]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActor]"
),
"wireActor-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActor]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActor]"
),
"wireProps-12-noPublicConstructor" -> List("Cannot find a public constructor for [SomeActor]"),
"wireAnonymousActor-12-noPublicConstructor" -> List("Cannot find a public constructor for [SomeActor]"),
Expand All @@ -54,7 +54,7 @@ class CompileTests extends CompileTestsSupport {
"wireActorWithProducer-6-injectAnnotationButNoDependencyInScope" -> List("Cannot find a value of type: [C]"),
"wireActorWithProducer-7-notActorProducer" -> List("wireActorWith does not support the type: [NotProducer]"),
"wireActorWithProducer-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActorProducer]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActorProducer]"
),
"wireActorWithProducer-12-noPublicConstructor" -> List(
"Cannot find a public constructor for [SomeActorProducer]"
Expand All @@ -76,7 +76,7 @@ class CompileTests extends CompileTestsSupport {
"wireAnonymousActorWith does not support the type: [NotProducer]"
),
"wireAnonymousActorWithProducer-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActorProducer]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActorProducer]"
),
"wireAnonymousActorWithProducer-12-noPublicConstructor" -> List(
"Cannot find a public constructor for [SomeActorProducer]"
Expand All @@ -96,7 +96,7 @@ class CompileTests extends CompileTestsSupport {
"wirePropsWithProducer-6-injectAnnotationButNoDependencyInScope" -> List("Cannot find a value of type: [C]"),
"wirePropsWithProducer-7-notActorProducer" -> List("wirePropsWith does not support the type: [NotProducer]"),
"wirePropsWithProducer-11-toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject for type [SomeActorProducer]"
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [SomeActorProducer]"
),
"wirePropsWithProducer-12-noPublicConstructor" -> List(
"Cannot find a public constructor for [SomeActorProducer]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class CompileTests extends CompileTestsSupport {
"Companion object for",
"Target] has no apply methods constructing target type."
),
"toManyInjectAnnotations" -> List("Ambiguous constructors annotated with @javax.inject.Inject for type [Target]"),
"toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [Target]"
),
"nullaryMethodUsedAsCandidate" -> List("Found multiple values of type [A]: [List(Module.foo(), a)]"),
"wireWithTwoParamsLists" -> List("found : A => (B => __wrapper$1", "required: ? => __wrapper$1"),
"wireRecEmptyString" -> List(valueNotFound("String"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class CompileTests extends CompileTestsSupport {
"has no apply methods constructing target type",
"[Target]"
),
"toManyInjectAnnotations" -> List("Ambiguous constructors annotated with @javax.inject.Inject for type [Target]"),
"toManyInjectAnnotations" -> List(
"Ambiguous constructors annotated with @javax.inject.Inject or @jakarta.inject.Inject for type [Target]"
),
"wireWithTwoParamsLists" -> List("Found: Main.A => Main.B => Main.Test.C", "Required: Any => Main.Test.C"),
"wireRecEmptyString" -> List(valueNotFound("String"))
)
Expand Down