From 6c66dbbdd021f227060460cd07f10be91dbd479c Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Wed, 27 Jun 2018 14:34:10 +0300 Subject: [PATCH] Postfix templates: added soutv postfix template (IDEA-194685) --- .../JavaPostfixTemplateProvider.java | 2 ++ .../templates/SoutvPostfixTemplate.java | 32 +++++++++++++++++++ .../postfix/templates/soutv/primitive.java | 5 +++ .../templates/soutv/primitive_after.java | 5 +++ .../postfix/templates/soutv/simple.java | 7 ++++ .../postfix/templates/soutv/simple_after.java | 7 ++++ .../postfix/templates/soutv/string.java | 5 +++ .../postfix/templates/soutv/string_after.java | 5 +++ .../postfix/templates/soutv/void.java | 7 ++++ .../postfix/templates/soutv/void_after.java | 7 ++++ .../templates/SoutvPostfixTemplateTest.java | 28 ++++++++++++++++ 11 files changed, 110 insertions(+) create mode 100644 java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutvPostfixTemplate.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive_after.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple_after.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string_after.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void_after.java create mode 100644 java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/templates/SoutvPostfixTemplateTest.java diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java index b8c2105b15f2..a0b1b7b98410 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/JavaPostfixTemplateProvider.java @@ -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); diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutvPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutvPostfixTemplate.java new file mode 100644 index 000000000000..0538301c1113 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutvPostfixTemplate.java @@ -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; + } +} diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive.java new file mode 100644 index 000000000000..de94d1e1d195 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive.java @@ -0,0 +1,5 @@ +public class Foo { + void m() { + 5.soutv + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive_after.java new file mode 100644 index 000000000000..f70c9115d3b5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/primitive_after.java @@ -0,0 +1,5 @@ +public class Foo { + void m() { + System.out.println("5 = " + 5); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple.java new file mode 100644 index 000000000000..c16c852405d4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple.java @@ -0,0 +1,7 @@ +package templates; + +public class Foo { + void m(boolean b, int value) { + b.soutv + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple_after.java new file mode 100644 index 000000000000..e098c4cc0dd9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/simple_after.java @@ -0,0 +1,7 @@ +package templates; + +public class Foo { + void m(boolean b, int value) { + System.out.println("b = " + b); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string.java new file mode 100644 index 000000000000..c2dfcf9be3ba --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string.java @@ -0,0 +1,5 @@ +public class Foo { + void m() { + "hello".soutv + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string_after.java new file mode 100644 index 000000000000..033d190f8d3f --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/string_after.java @@ -0,0 +1,5 @@ +public class Foo { + void m() { + System.out.println("\"hello\" = " + "hello"); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void.java new file mode 100644 index 000000000000..417bc526e90c --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void.java @@ -0,0 +1,7 @@ +package templates; + +public class Foo { + void m(boolean b, int value) { + m().soutv + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void_after.java new file mode 100644 index 000000000000..2ee15c5267b8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/soutv/void_after.java @@ -0,0 +1,7 @@ +package templates; + +public class Foo { + void m(boolean b, int value) { + m().soutv + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/templates/SoutvPostfixTemplateTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/templates/SoutvPostfixTemplateTest.java new file mode 100644 index 000000000000..2824b84c13dd --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/templates/SoutvPostfixTemplateTest.java @@ -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(); + } +} \ No newline at end of file