我想为 Timber logger 创建一个实时模板类似于默认的实时模板 logm 。它使用 Groovy 脚本来收集方法参数并用逗号分隔它们。例如:
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).
问题是 Timber 方法需要参数的类型格式,例如:
int a = 5;
String s = new String("test");
boolean b = false;
Timber.d("%d, %s, %b", a, s, b);
因此,我需要确定方法参数的类型。
最佳答案
尝试用光标在 % 类型上创建实时模板,并在使用此模板后填充它们
关于android - 如何在 Intellij IDEA 中获取实时模板中的方法参数类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40830371/