InelliJ IDEA navigation in this scenario in Kotlin language

Answered

Consider this kotlin interface:

interface Command

interface CommandHandler<Q: Command, R> {

    fun handle(command: Q): R

}

data class TestCommand(): Command //does not really mather, inside just some @field:JsonProperty("value") val blabla: String

Now there is a Spring Service for example:


@RestController
@RequestMapping("/test")
class TestEndpoint(private val testCommandHandler: CommandHandler<TestCommand, Unit>)
{

@PostMapping("/aaa")
fun testMethod(@RequestBody command: TestCommand): ResponseEntity<Void> {
testCommandHandler.handle(command)
}

Consider that when you left click on "handle" you will go straight to CommandHandler interface rather than to one and only:

@Component
class TestCommandHandler(): CommandHandler<TestCommand, Unit> {

override fun handle(command: TestCommand) {
(...)
}


Is there an option how to navigate straight to one and only implementation of this interface?


0
4 comments

"I think you want "Go to implementation" (Ctrl+Alt+B):"

 

Not really - this option will show me all implementations of

fun handle(command: Q): R

To clarify it, consider that `Q` can be something other like
`BlaBlaCommand` and IntelliJ will suggest it to me even
though i am calling `handle` with
private val testCommandHandler: CommandHandler<TestCommand, Unit>
So it's a case where `Q` is `TestCommand` not `BlaBlaCommand`



Consider scenario when I have over 100 of them
and i Have only one concrete implementation of excatly type `TestCommand`

Now when I am in `TestEndpoint` class in `testMethod` (see example above) I want to navigate straight
to one and only valid implementation of handle.
So the one where genereic type `T` is `TestCommand`.




0

Thanks for the example project! I think what you are describing is https://youtrack.jetbrains.com/issue/KT-38739, please watch the issue for updates.

0

Please sign in to leave a comment.