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

标签 android android-studio intellij-idea groovy live-templates

我想为 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/

相关文章:

php - 在 PHP 中获取 POST 数据

安卓最高自定义通知的大小

android - 如何制作画廊?

maven - java.lang.NoSuchMethodError : org. apache.hadoop.conf.Configuration.reloadExistingConfigurations()V

java - 使用 IntelliJ 引用 jar lib 会导致 ClassNotFoundException

java - 如果类名可用于导入,Intellij idea 不会给我创建类意图操作

java - 如何制作一个无法退出的app

android - 将项目从 gradle 2.1 升级到 3.5 后无法解析 AppCompatActivity

Android Studio 3.5.2 模拟器。如何查看应用程序列表

php - Android 单选按钮值无法存储在 php mysql : "Required Fields are Missing" 中