6

मैं Timber logger के लिए डिफ़ॉल्ट लाइव टेम्पलेट लॉगम के लिए एक लाइव टेम्पलेट बनाना चाहता हूं। यह विधि पैरामीटर एकत्र करने और अल्पविराम से अलग करने के लिए ग्रोवी स्क्रिप्ट का उपयोग करता है। उदाहरण के लिए: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); 

इस प्रकार, मुझे विधि पैरामीटर के प्रकार निर्धारित करने की आवश्यकता है।

उत्तर

3

% प्रकार पर कर्सर के साथ लाइव टेम्पलेट बनाने का प्रयास करें, और इस टेम्पलेट

उपयोग करने के बाद उन्हें भरने