2016-11-27 15 views
6

Timber logger için canlı şablon logm varsayılan canlı şablonuna benzer şekilde canlı bir şablon oluşturmak istiyorum. Yöntem parametrelerini toplamak ve bunları virgülle ayırmak için bir Groovy komut dosyası kullanır. Örneğin:Intellij IDEA'da canlı şablonlarda yöntem parametresi türleri nasıl alınır?

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 + "]"); 
} 

Parametreler aşağıdaki kodla topluyorlar : parametreler için sorun Kereste yöntemleri olduğunu

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). 

gerektiren türü biçimi için

public int func(int a, float b, Object c, String d) { 
    logm 
} 

aşağıdaki kodu oluşturmak örnek:

int a = 5; 
String s = new String("test"); 
boolean b = false; 

Timber.d("%d, %s, %b", a, s, b); 

Böylece, metod parametrelerinin türlerini belirlemem gerek.

cevap

3

imleç ile canlı şablon oluşturmayı% türünde deneyin ve bu şablonu kullandıktan sonra bunları doldurun

İlgili konular