mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
IDEA-83668 soutp live template: take arrays into consideration
GitOrigin-RevId: 354497ccd320e7716e21ecb54c8f0daebfd96e43
This commit is contained in:
committed by
intellij-monorepo-bot
parent
aab311b9ac
commit
30f0b0ab21
@@ -1,10 +1,11 @@
|
||||
import java.lang.String;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class LiveTemplateTest {
|
||||
|
||||
void usage(int num, boolean someBoolean, List<String> args){
|
||||
System.out.println("num = [" + num + "], someBoolean = [" + someBoolean + "], args = [" + args + "]");<caret>
|
||||
void usage(boolean b, int[] ints, int[][] deepInts, Object[][] deepObjects) {
|
||||
System.out.println("b = " + b + ", ints = " + Arrays.toString(ints) + ", deepInts = " + Arrays.deepToString(deepInts) + ", deepObjects = " + Arrays.deepToString(deepObjects));<caret>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import java.util.List;
|
||||
|
||||
public class LiveTemplateTest {
|
||||
|
||||
void usage(int num, boolean someBoolean, List<String> args){
|
||||
void usage(boolean b, int[] ints, int[][] deepInts, Object[][] deepObjects) {
|
||||
<caret>
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</template>
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.soutp"
|
||||
name="soutp" toReformat="true" toShortenFQNames="true" value="println "$FORMAT$"">
|
||||
<variable alwaysStopAt="false" defaultValue="" expression="groovyScript("_1.collect { it + ' = [$' + it + ']'}.join(', ')", methodParameters())" name="FORMAT" />
|
||||
<variable alwaysStopAt="false" defaultValue="" expression="groovyScript("_1.collect { it + ' = $' + it}.join(', ')", methodParameters())" name="FORMAT" />
|
||||
<context>
|
||||
<option name="GROOVY_STATEMENT" value="true" />
|
||||
</context>
|
||||
|
||||
@@ -47,7 +47,7 @@ void usage(int num, boolean someBoolean, List<String> args){
|
||||
expandTemplate(myFixture.getEditor())
|
||||
myFixture.checkResult '''
|
||||
void usage(int num, boolean someBoolean, List<String> args){
|
||||
println "num = [$num], someBoolean = [$someBoolean], args = [$args]"
|
||||
println "num = $num, someBoolean = $someBoolean, args = $args"
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
@@ -34,7 +34,24 @@
|
||||
</template>
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.soutp"
|
||||
name="soutp" toReformat="true" toShortenFQNames="true" value="System.out.println($FORMAT$);">
|
||||
<variable alwaysStopAt="false" defaultValue="" expression="groovyScript("'\"' + _1.collect { it + ' = [\" + ' + it + ' + \"]'}.join(', ') + '\"'", methodParameters())" name="FORMAT" />
|
||||
<variable alwaysStopAt="false" defaultValue="" expression="groovyScript("import com.intellij.psi.*;import com.intellij.psi.util.PsiTreeUtil; def file = PsiDocumentManager.getInstance(_editor.project).getPsiFile(_editor.document); PsiMethod method = PsiTreeUtil.findElementOfClassAtOffset(file, _editor.caretModel.offset, PsiMethod.class, false); PsiParameter[] parameters = method == null ? PsiParameter.EMPTY_ARRAY : method.parameterList.parameters; return parameters.size() == 0 ? '' : '\"' + parameters.collect { def prefix = it.name + ' = '; def type = it.type; return type instanceof PsiArrayType ? type.componentType instanceof PsiPrimitiveType ? prefix + '\" + java.util.Arrays.toString(' + it.name + ')' : prefix + '\" + java.util.Arrays.deepToString(' + it.name + ')' : prefix + '\" + ' + it.name }.join(' + \", ')", methodParameters())" name="FORMAT" />
|
||||
<!--
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
|
||||
def file = PsiDocumentManager.getInstance(_editor.project).getPsiFile(_editor.document)
|
||||
PsiMethod method = PsiTreeUtil.findElementOfClassAtOffset(file, _editor.caretModel.offset, PsiMethod.class, false)
|
||||
PsiParameter[] parameters = method == null ? PsiParameter.EMPTY_ARRAY : method.parameterList.parameters
|
||||
return parameters.size() == 0 ? '' : '"' + parameters.collect {
|
||||
def prefix = it.name + ' = '
|
||||
def type = it.type
|
||||
return type instanceof PsiArrayType
|
||||
? type.componentType instanceof PsiPrimitiveType
|
||||
? prefix + '" + java.util.Arrays.toString(' + it.name + ')'
|
||||
: prefix + '" + java.util.Arrays.deepToString(' + it.name + ')'
|
||||
: prefix + '" + ' + it.name
|
||||
}.join(' + ", ')
|
||||
-->
|
||||
<context>
|
||||
<option name="JAVA_CODE" value="false" />
|
||||
<option name="JAVA_STATEMENT" value="true" />
|
||||
|
||||
Reference in New Issue
Block a user