Reputation: 816
I have made an event system in Kotlin where events can be listened to and broadcast, similarly to how events work in C#.
To broadcast an event, I have this line:
playerConnected.broadcast(player)
Here playerConnected
is the event and player
is the context object.
When debugging in IntellIJ, when "stepping into" the broadcast function to see what actions that event listeners do, it instead steps into the broadcast()
function, which makes sense, and it looks something like this:
fun broadcast(args: T) {
for (listener in listeners) {
try {
listener.accept(args)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
I am interested in skipping stepping into broadcast()
and instead step directly into each accept()
function, where listener
is a Consumer<T>
.
In C# I would be able to solve this by adding a DebuggerStepThroughAttribute
to the broadcast()
function.
Is there any equivalent attribute in Kotlin or another way to achieve the same in IntellIJ?
Upvotes: 2
Views: 100
Reputation: 274835
If you are targeting the JVM, and broadcast
is method of a class, you can set the debugger to ignore that whole class.
Go to IntelliJ IDEA's settings, Build, Execution, Deployment > Debugger > Stepping.
In the "Java" section, you can add a class that you want it to ignore:
After clicking on the "+" button, you can search for the class in which broadcast
is in. After you added the class, the whole class will be ignored.
If you don't want it to ignore the entire class, here's a "trick" that might work. Rewrite broadcast
as an extension function in a separate file. Let's say your file is called Foo.kt
. This will actually translate to a Java class called FooKt
, and it will show up when you search for it in the "list of classes to ignore" dialog box. Of course, not all methods can be rewritten as extension functions, and it doesn't always make sense to rewrite them as extension functions, so this doesn't work all the time :(
Upvotes: 2