Skip to content

Commit f4b12a3

Browse files
Merge pull request #328 from AxonFramework/fix/aggregate-member-false-positive
No longer show the routing key inspection warning when the method is …
2 parents 9b0fcdf + 0ec17b2 commit f4b12a3

File tree

5 files changed

+90
-6
lines changed

5 files changed

+90
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Axon Framework plugin Changelog
44

55
## [0.9.2]
6+
- No longer show the routing key inspection warning when the method is not annotated with a relevant handler annotation.
67
- Fix false positive on versions not equal to 4
78

89
## [0.9.1]

src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspection.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ class JavaMissingRoutingKeyOnAggregateMemberInspection : AbstractBaseJavaLocalIn
4848
?: entity.routingKey
4949
?: return null
5050

51-
if (method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) &&
52-
entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances"
53-
) {
51+
val isEventSourcingHandler = method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER)
52+
if(!isEventSourcingHandler && !method.hasAnnotation(AxonAnnotation.COMMAND_HANDLER)) {
53+
return null
54+
}
55+
56+
if (isEventSourcingHandler && entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances") {
5457
return null
5558
}
5659
val payload = method.resolvePayloadType() ?: return null

src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspection.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ class KotlinMissingRoutingKeyOnAggregateMemberInspection : AbstractKotlinInspect
5757
val routingKey = entityMember.routingKey
5858
?: entity.routingKey
5959
?: return
60-
if (method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) &&
61-
entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances"
62-
) {
60+
val isEventSourcingHandler = method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER)
61+
if(!isEventSourcingHandler && !method.hasAnnotation(AxonAnnotation.COMMAND_HANDLER)) {
62+
return
63+
}
64+
if (isEventSourcingHandler && entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances") {
6365
return
6466
}
6567
val payload = method.resolvePayloadType() ?: return

src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspectionTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,45 @@ class JavaMissingRoutingKeyOnAggregateMemberInspectionTest : AbstractAxonFixture
6161
}
6262
}
6363

64+
fun `test will not show problem if has no handler annotation`() {
65+
addFile(
66+
"MyCommand.java", """
67+
class MyCommand {}
68+
""".trimIndent()
69+
)
70+
71+
addFile(
72+
"MyEntity.java", """
73+
import test.MyCommand;
74+
75+
class MyEntity {
76+
@EntityId
77+
private String myEntityId;
78+
79+
public void handle(MyCommand command) {}
80+
}
81+
""".trimIndent(), open = true
82+
)
83+
84+
addFile(
85+
"MyAggregate.java", """
86+
import test.MyEntity;
87+
import java.util.List;
88+
89+
@AggregateRoot
90+
class MyAggregate {
91+
@AggregateMember
92+
List<MyEntity> entities;
93+
""".trimIndent()
94+
)
95+
96+
myFixture.enableInspections(JavaMissingRoutingKeyOnAggregateMemberInspection())
97+
val highlights = myFixture.doHighlighting(HighlightSeverity.WARNING)
98+
Assertions.assertThat(highlights).noneMatch {
99+
it.text == "handle" && it.description.contains("The payload requires a myEntityId property or getter")
100+
}
101+
}
102+
64103
fun `test will not show problem when key is present`() {
65104
addFile(
66105
"MyCommand.java", """

src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspectionTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,45 @@ class KotlinMissingRoutingKeyOnAggregateMemberInspectionTest : AbstractAxonFixtu
6161
}
6262
}
6363

64+
fun `test will not show problem if has no handler annotation`() {
65+
addFile(
66+
"MyCommand.kt", """
67+
class MyCommand {}
68+
""".trimIndent()
69+
)
70+
71+
addFile(
72+
"MyEntity.kt", """
73+
import test.MyCommand
74+
75+
class MyEntity {
76+
@EntityId
77+
private lateinit var myEntityId: String
78+
79+
fun handle(command: MyCommand) {}
80+
}
81+
""".trimIndent(), open = true
82+
)
83+
84+
addFile(
85+
"MyAggregate.kt", """
86+
import test.MyEntity
87+
import java.util.List
88+
89+
@AggregateRoot
90+
class MyAggregate {
91+
@AggregateMember
92+
private lateinit var entities: List<MyEntity>
93+
""".trimIndent()
94+
)
95+
96+
myFixture.enableInspections(KotlinMissingRoutingKeyOnAggregateMemberInspection())
97+
val highlights = myFixture.doHighlighting(HighlightSeverity.WARNING)
98+
Assertions.assertThat(highlights).noneMatch {
99+
it.text == "handle" && it.description.contains("The payload requires a myEntityId property or getter")
100+
}
101+
}
102+
64103
fun `test will not show problem when key is present`() {
65104
addFile(
66105
"MyCommand.kt", """

0 commit comments

Comments
 (0)