Ich möchte eine Live-Vorlage für Timber logger ähnlich wie Live-Vorlage logm erstellen. Es verwendet ein Groovy-Skript, um Methodenparameter zu sammeln und sie durch Kommas zu trennen. Zum Beispiel:Wie erhalten Methodenparametertypen in Live-Vorlagen in Intellij IDEA?
public int func(int a, float b, Object c, String d) {
logm
}
erzeugen den folgenden Code:
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 + "]");
}
Parameter durch den folgenden Code sammeln:
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).
Das Problem ist, das Holz Methoden erfordern Typ Format für Parameter, Beispiel:
int a = 5;
String s = new String("test");
boolean b = false;
Timber.d("%d, %s, %b", a, s, b);
Also muss ich die Arten der Methodenparameter bestimmen.