Idea Live Template to Log Method Args

痴心易碎 提交于 2019-12-04 19:09:27

问题


I would like to be able to create a live template in Jetbrain's Idea that will log the method's arguments. Let's call it "larg". It would work like:

public void get(String one, String two) {
    larg<tab>

to create

public void get(String one, String two) {
    log.info("get: one = " + one + " two = " + two);

I'm fine with getting the method name in, but have not figured out how to pull in the method arguments. Any ideas?


回答1:


I'm 4 years late, but the predefined template soutp pretty much does this using a groovyscript variable.

Here's the groovy script that does what you're looking for

groovyScript("'\"' + _1.collect { it + ' = [\" + ' + it + ' + \"]'}.join(', ') + '\"'", methodParameters())



回答2:


This is now 6 years late, but I found a well described solution to this. (I don't have any soutp templates in my templates) http://artfulonline.blogspot.com.au/2014/03/quick-logging-with-intellij-live.html




回答3:


Looks like it is not currently possible with a live template.

From the Jetbrain's forum:

There is no predefined live template function to do this for you automatically.
You can write a plugin that would provide such a function.


来源:https://stackoverflow.com/questions/1440525/idea-live-template-to-log-method-args

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