How to change a value while debugging to a variable using a conditional breakpoint in a IntelliJ Kotlin project on the fly?

霸气de小男生 提交于 2020-05-15 07:57:45

问题


In an Java Project this is possible while debugging by “mis”-using a conditional breakpoint to set a value to a property or variable:

Java Breakpoint

Unfortunately the same thing is not possible in a Kotlin Project. The error is: Assignments are not expressions, and only expressions are allowed in this context:

Kotlin Breakpoint

I know that I can do it in debugger window using “Set Value”, but then i have to do it every time manually. Using a conditional breakpoint/watchpoint the value is set automatically without even suspending the program until I delete the breakpoint. This is pretty useful for smoke test or presentations.

Thanks in advance!


回答1:


Do not do that in the condition field, use "evaluate and log" - this breakpoint action is created specifically for this.

Also you can unset "suspend" and it will silently set value for you:




回答2:


You could execute a function to set the value:

run { text = "Some Value" }

This is an expression; it returns Unit, but has the side effect of setting your variable.

If the condition field needs you to return a boolean you can add it after:

run { text = "Some Value"; false }

This returns false so the execution wouldn't stop.



来源:https://stackoverflow.com/questions/58487806/how-to-change-a-value-while-debugging-to-a-variable-using-a-conditional-breakpoi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!