6
我想为Timber logger创建一个活动模板,类似于默认的活动模板logm。它使用Groovy脚本收集方法参数并用逗号分隔它们。例如:如何在Intellij IDEA的实时模板中获取方法参数类型?
public int func(int a, float b, Object c, String d) {
logm
}
生成以下代码:
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 + "]");
}
参数由下面的代码收集:用于参数
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).
问题是木材的方法需要类型的格式,对于例如:
int a = 5;
String s = new String("test");
boolean b = false;
Timber.d("%d, %s, %b", a, s, b);
因此,我需要确定方法参数的类型。