6
Timber logger의 라이브 템플릿을 기본 라이브 템플릿 logm과 마찬가지로 만들고 싶습니다. Groovy 스크립트를 사용하여 메소드 매개 변수를 수집하고 쉼표로 구분합니다. 예를 들어 :Intellij IDEA의 라이브 템플릿에서 메서드 매개 변수 유형을 얻으려면 어떻게해야합니까?
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).
필요한 유형의 형식에 대한
public int func(int a, float b, Object c, String d) {
logm
}
는 다음 코드를 생성 예 :
int a = 5;
String s = new String("test");
boolean b = false;
Timber.d("%d, %s, %b", a, s, b);
따라서 메서드 매개 변수의 유형을 결정해야합니다.