Postfix templates: added soutv postfix template (IDEA-194685)

This commit is contained in:
Alexander Zolotov
2018-06-27 14:49:24 +03:00
parent 8de417663a
commit 6c66dbbdd0
11 changed files with 110 additions and 0 deletions
@@ -37,6 +37,7 @@ public class JavaPostfixTemplateProvider implements PostfixTemplateProvider {
new ForDescendingPostfixTemplate(this),
new WhileStatementPostfixTemplate(this),
new SoutPostfixTemplate(this),
new SoutvPostfixTemplate(this),
new ReturnStatementPostfixTemplate(this),
new OptionalPostfixTemplate(this),
new ForeachPostfixTemplate("iter", this),
@@ -134,6 +135,7 @@ public class JavaPostfixTemplateProvider implements PostfixTemplateProvider {
// cannot be editable until there is no UI for editing template variables
!(templateToEdit instanceof ForIndexedPostfixTemplate) &&
!(templateToEdit instanceof ForeachPostfixTemplate) &&
!(templateToEdit instanceof SoutvPostfixTemplate) &&
!(templateToEdit instanceof ArgumentPostfixTemplate) &&
!(templateToEdit instanceof OptionalPostfixTemplate)) {
JavaPostfixTemplateEditor editor = new JavaPostfixTemplateEditor(this);
@@ -0,0 +1,32 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.template.postfix.templates;
import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.postfix.templates.editable.JavaEditablePostfixTemplate;
import com.intellij.codeInsight.template.postfix.templates.editable.JavaPostfixTemplateExpressionCondition;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
public class SoutvPostfixTemplate extends JavaEditablePostfixTemplate {
public SoutvPostfixTemplate(@NotNull JavaPostfixTemplateProvider provider) {
super("soutv",
"System.out.println(\"$EXPR_COPY$ = \" + $EXPR$);$END$",
"System.out.println(expr)",
Collections.singleton(new JavaPostfixTemplateExpressionCondition.JavaPostfixTemplateNonVoidExpressionCondition()),
LanguageLevel.JDK_1_3, true, provider);
}
@Override
protected void addTemplateVariables(@NotNull PsiElement element, @NotNull Template template) {
super.addTemplateVariables(element, template);
template.addVariable("EXPR_COPY", "escapeString(EXPR)", null, false);
}
@Override
public boolean isBuiltin() {
return true;
}
}
@@ -0,0 +1,5 @@
public class Foo {
void m() {
5.soutv<caret>
}
}
@@ -0,0 +1,5 @@
public class Foo {
void m() {
System.out.println("5 = " + 5);<caret>
}
}
@@ -0,0 +1,7 @@
package templates;
public class Foo {
void m(boolean b, int value) {
b.soutv<caret>
}
}
@@ -0,0 +1,7 @@
package templates;
public class Foo {
void m(boolean b, int value) {
System.out.println("b = " + b);<caret>
}
}
@@ -0,0 +1,5 @@
public class Foo {
void m() {
"hello".soutv<caret>
}
}
@@ -0,0 +1,5 @@
public class Foo {
void m() {
System.out.println("\"hello\" = " + "hello");<caret>
}
}
@@ -0,0 +1,7 @@
package templates;
public class Foo {
void m(boolean b, int value) {
m().soutv<caret>
}
}
@@ -0,0 +1,7 @@
package templates;
public class Foo {
void m(boolean b, int value) {
m().soutv <caret>
}
}
@@ -0,0 +1,28 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.template.postfix.templates;
import org.jetbrains.annotations.NotNull;
public class SoutvPostfixTemplateTest extends PostfixTemplateTestCase {
@NotNull
@Override
protected String getSuffix() {
return "soutv";
}
public void testPrimitive() {
doTest();
}
public void testVoid() {
doTest();
}
public void testSimple() {
doTest();
}
public void testString() {
doTest();
}
}