AxonFramework / IdeaPlugin

An IntelliJ IDEA plugin for Axon Framework
Apache License 2.0
34 stars 21 forks source link

Zero-arg queries in java are not detected as publisher #294

Open CodeDrivenMitch opened 1 month ago

CodeDrivenMitch commented 1 month ago

Basic information

Steps to reproduce

Expected behaviour

The popup contains the place the query is published

Actual behaviour

The popup is not there. It seems the IDEA SDK does not detect a zero-arg constructor as an actual constructor, as this test fails:

fun `test resolves zero-arg constructor as creator too in java`() {
    addFile("MyZeroArgQuery.java", """
        public class MyZeroArgQuery {          
        }
    """.trimIndent())
    addFile(
        "MyQueryPublisher.java", """        
        import test.MyZeroArgQuery;

        class MyQueryPublisher {
           private final QueryGateway queryGateway;

           public MyQueryPublisher(QueryGateway queryGateway) {
               this.queryGateway = queryGateway;
           }

           public void publish() {
                 queryGateway.query(new MyZeroArgQuery(), String.class);
           }
       }
    """.trimIndent(), open = true
    )
    val creators = project.creatorResolver().getCreatorsForPayload("test.MyZeroArgQuery")
    Assertions.assertThat(creators).anyMatch {
        it.payload == "test.MyZeroArgQuery" &&
                it.renderText() == "MyQueryPublisher.publish"
        it.renderContainerText() == null
    }
}
CodeDrivenMitch commented 1 month ago

I have been unable to resolve this issue, as neither the Psi nor UAST sees the constructor for Java. For Kotlin it works. Posted a question to Jetbrains for clarification.