https://kotlinlang.org logo
Title
a

adibfara

10/30/2018, 7:36 AM
This is not a directly Kotlin related question, but it can be used with Kotlin too, how do you navigate to the implementation of an abstract function, in a specific implementation class? suppose you have an
Animal
class that has
abstract fun run()
and you have
class Dog : Anima() { //implements run }
and you have an instance of dog and usage of
run()
somewhere
kotlin
val dog = Dog()
dog.run()
how do you navigate to
run
implementation in Dog?
:stackoverflow: 4
k

karelpeeters

10/30/2018, 8:50 AM
If you have the interface opened there's an icon on the left od the function that pops open a list of the implementations of that function.
s

Saiedmomen

10/30/2018, 8:56 AM
right click on method > goto > implementation(s)
f

frellan

10/30/2018, 9:07 AM
Cmd + Click
m

Mike

10/30/2018, 10:42 AM
There are keyboard shortcuts too. Cmd-b/ctrl-b for goto implementation.
a

adibfara

10/30/2018, 1:00 PM
all of the suggestions show all of the implementations, and if you have a lot of implementations of the class, it might be handy to show the implementation for that specific class.
m

Mike

10/30/2018, 1:10 PM
I suspect that w/o running the code, it would be tough for the IDE to determine what the actual type of
dog
is at that line. I know WE can see it in this example, but…
a

adibfara

10/30/2018, 2:36 PM
It's what type of animal, not type of Dog and I don't think it would be hard for the IDE to go to that file and it's implementation of
run()
unless it is an abstract class itself
k

karelpeeters

10/30/2018, 2:37 PM
Actually if you do
val dog = Dog()
it has type
Dog
so it should all just work, right?
Which declaration do you want to go to?
a

adibfara

10/30/2018, 2:38 PM
Yes it should, but it doesnt. It goes to the abstract function in the base class which is Animal
unless you find the implementations (which includes Dog) but has all of the implementations and this becomes problematic when you have a lot of implementations (like UseCase for example)
m

Mike

10/30/2018, 2:48 PM
Type of variable
dog
is what I was saying. And how many times have you had people say to you “it shouldn’t be that hard to…“. If you feel this way, raise a feature request on IntelliJ ticket system. They’ll let you know if it’s feasible or not…
k

karelpeeters

10/30/2018, 2:54 PM
I's say that would be a bug, but for me it works fine on this code:
abstract class Parent {
    abstract fun test()
}

class Child: Parent() {
    override fun test() { println("child") }
}

class Other: Parent() {
    override fun test() { println("other") }
}

fun main(args: Array<String>) {
    val child = Child()
    child.test()
}
💯 1
a

adibfara

10/30/2018, 2:56 PM
Karel when you CMD+click on child.test() does it go to the Child class?
k

karelpeeters

10/30/2018, 2:56 PM
I do
Ctrl+B
.
Ctrl+Click works too!
a

adibfara

10/30/2018, 2:57 PM
Now it seems that it is a bug! Thanks a lot
I'll investigate more as I can to find the cause