diff --git a/CHANGELOG.md b/CHANGELOG.md index 21fa453..b41da1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ # Axon Framework plugin Changelog ## [0.9.2] +- No longer show the routing key inspection warning when the method is not annotated with a relevant handler annotation. - Fix false positive on versions not equal to 4 ## [0.9.1] diff --git a/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspection.kt b/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspection.kt index e96a7f6..2955e0d 100644 --- a/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspection.kt +++ b/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspection.kt @@ -48,9 +48,12 @@ class JavaMissingRoutingKeyOnAggregateMemberInspection : AbstractBaseJavaLocalIn ?: entity.routingKey ?: return null - if (method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) && - entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances" - ) { + val isEventSourcingHandler = method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) + if(!isEventSourcingHandler && !method.hasAnnotation(AxonAnnotation.COMMAND_HANDLER)) { + return null + } + + if (isEventSourcingHandler && entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances") { return null } val payload = method.resolvePayloadType() ?: return null diff --git a/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspection.kt b/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspection.kt index 1503c4e..0ca9f40 100644 --- a/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspection.kt +++ b/src/main/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspection.kt @@ -57,9 +57,11 @@ class KotlinMissingRoutingKeyOnAggregateMemberInspection : AbstractKotlinInspect val routingKey = entityMember.routingKey ?: entity.routingKey ?: return - if (method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) && - entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances" - ) { + val isEventSourcingHandler = method.hasAnnotation(AxonAnnotation.EVENT_SOURCING_HANDLER) + if(!isEventSourcingHandler && !method.hasAnnotation(AxonAnnotation.COMMAND_HANDLER)) { + return + } + if (isEventSourcingHandler && entityMember.eventForwardingMode != "org.axonframework.modelling.command.ForwardMatchingInstances") { return } val payload = method.resolvePayloadType() ?: return diff --git a/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspectionTest.kt b/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspectionTest.kt index 78a72b0..bcf67f8 100644 --- a/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspectionTest.kt +++ b/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/JavaMissingRoutingKeyOnAggregateMemberInspectionTest.kt @@ -61,6 +61,45 @@ class JavaMissingRoutingKeyOnAggregateMemberInspectionTest : AbstractAxonFixture } } + fun `test will not show problem if has no handler annotation`() { + addFile( + "MyCommand.java", """ + class MyCommand {} + """.trimIndent() + ) + + addFile( + "MyEntity.java", """ + import test.MyCommand; + + class MyEntity { + @EntityId + private String myEntityId; + + public void handle(MyCommand command) {} + } + """.trimIndent(), open = true + ) + + addFile( + "MyAggregate.java", """ + import test.MyEntity; + import java.util.List; + + @AggregateRoot + class MyAggregate { + @AggregateMember + List entities; + """.trimIndent() + ) + + myFixture.enableInspections(JavaMissingRoutingKeyOnAggregateMemberInspection()) + val highlights = myFixture.doHighlighting(HighlightSeverity.WARNING) + Assertions.assertThat(highlights).noneMatch { + it.text == "handle" && it.description.contains("The payload requires a myEntityId property or getter") + } + } + fun `test will not show problem when key is present`() { addFile( "MyCommand.java", """ diff --git a/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspectionTest.kt b/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspectionTest.kt index 87d2d9a..862947a 100644 --- a/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspectionTest.kt +++ b/src/test/kotlin/org/axonframework/intellij/ide/plugin/inspections/aggregate/KotlinMissingRoutingKeyOnAggregateMemberInspectionTest.kt @@ -61,6 +61,45 @@ class KotlinMissingRoutingKeyOnAggregateMemberInspectionTest : AbstractAxonFixtu } } + fun `test will not show problem if has no handler annotation`() { + addFile( + "MyCommand.kt", """ + class MyCommand {} + """.trimIndent() + ) + + addFile( + "MyEntity.kt", """ + import test.MyCommand + + class MyEntity { + @EntityId + private lateinit var myEntityId: String + + fun handle(command: MyCommand) {} + } + """.trimIndent(), open = true + ) + + addFile( + "MyAggregate.kt", """ + import test.MyEntity + import java.util.List + + @AggregateRoot + class MyAggregate { + @AggregateMember + private lateinit var entities: List + """.trimIndent() + ) + + myFixture.enableInspections(KotlinMissingRoutingKeyOnAggregateMemberInspection()) + val highlights = myFixture.doHighlighting(HighlightSeverity.WARNING) + Assertions.assertThat(highlights).noneMatch { + it.text == "handle" && it.description.contains("The payload requires a myEntityId property or getter") + } + } + fun `test will not show problem when key is present`() { addFile( "MyCommand.kt", """