如何在Intellij IDEA的实时模板中获取方法参数类型?

Sta*_*lov 6 groovy android intellij-idea live-templates android-studio

我想为默认的实时模板logm创建Timber记录器的实时模板.它使用Groovy脚本来收集方法参数并用逗号分隔它们.例如:

public int func(int a, float b, Object c, String d) {
    logm
}
Run Code Online (Sandbox Code Playgroud)

生成以下代码:

public int func(int a, float b, Object c, String d) {
    Log.d(TAG, "func() called with: a = [" + a + "], b = [" + b + "], c = [" + c + "], d = [" + d + "]");
}
Run Code Online (Sandbox Code Playgroud)

参数通过以下代码收集:

def params = _2.collect {it + ' = [" + ' + it + ' + "]'}.join(', ');
return '"' + _1 + '() called' + (params.empty  ? '' : ' with: ' + params) + '"'

//Where _1 and _2 - default IDEA methods, in this case 
//_1 - methodName(), which eturns the name of the embracing method (where the template is expanded).
//_2 - methodParameters(), which returns the list of parameters of the embracing method (where the template is expanded).
Run Code Online (Sandbox Code Playgroud)

问题是Timber方法需要参数的类型格式,例如:

int a = 5;
String s = new String("test");
boolean b = false;

Timber.d("%d, %s, %b", a, s, b);
Run Code Online (Sandbox Code Playgroud)

因此,我需要确定方法参数的类型.

mr.*_*ker 3

尝试创建实时模板,光标位于 % 类型,并在使用此模板后填充它们