diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ArgumentPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ArgumentPostfixTemplate.java new file mode 100644 index 000000000000..c653ea4e526d --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ArgumentPostfixTemplate.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 ArgumentPostfixTemplate extends JavaEditablePostfixTemplate { + public ArgumentPostfixTemplate(@NotNull JavaPostfixTemplateProvider provider) { + super("arg", + "$CALL$($EXPR$$END$)", + "functionCall(expr)", + Collections.singleton(new JavaPostfixTemplateExpressionCondition.JavaPostfixTemplateNonVoidExpressionCondition()), + LanguageLevel.JDK_1_3, false, provider); + } + + @Override + public boolean isBuiltin() { + return true; + } + + @Override + protected void addTemplateVariables(@NotNull PsiElement element, @NotNull Template template) { + super.addTemplateVariables(element, template); + template.addVariable("CALL", "", "", true); + } +} 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 38be8ba3d4dd..d439d9c5eb98 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 @@ -52,6 +52,7 @@ public class JavaPostfixTemplateProvider implements PostfixTemplateProvider { new ThrowExceptionPostfixTemplate(this), new FormatPostfixTemplate(this), new ObjectsRequireNonNullPostfixTemplate(this), + new ArgumentPostfixTemplate(this), new CastExpressionPostfixTemplate(), new ElseStatementPostfixTemplate(), @@ -137,6 +138,7 @@ public class JavaPostfixTemplateProvider implements PostfixTemplateProvider { templateToEdit instanceof JavaEditablePostfixTemplate && // cannot be editable until there is no UI for editing template variables !(templateToEdit instanceof ForIndexedPostfixTemplate) && + !(templateToEdit instanceof ArgumentPostfixTemplate) && !(templateToEdit instanceof OptionalPostfixTemplate)) { return new JavaPostfixTemplateEditor(this, templateToEdit); } diff --git a/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/after.java.template b/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/after.java.template new file mode 100644 index 000000000000..2b5b768faeab --- /dev/null +++ b/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + call(o)$key + } +} \ No newline at end of file diff --git a/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/before.java.template b/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/before.java.template new file mode 100644 index 000000000000..8a3222bc076b --- /dev/null +++ b/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o$key + } +} \ No newline at end of file diff --git a/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/description.html b/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/description.html new file mode 100644 index 000000000000..87b4e43e0638 --- /dev/null +++ b/java/java-impl/src/postfixTemplates/ArgumentPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Wraps object with a function call. + + \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/arg/simple.java b/java/java-tests/testData/codeInsight/template/postfix/templates/arg/simple.java new file mode 100644 index 000000000000..f9769f393b3c --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/arg/simple.java @@ -0,0 +1,6 @@ +public class Foo { + void m(boolean b) { + + b.arg + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/arg/simple_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/arg/simple_after.java new file mode 100644 index 000000000000..cd105ae27c65 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/arg/simple_after.java @@ -0,0 +1,6 @@ +public class Foo { + void m(boolean b) { + + functionCall(b) + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/templates/ArgumentPostfixTemplateTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/templates/ArgumentPostfixTemplateTest.java new file mode 100644 index 000000000000..ba01e0621a94 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/templates/ArgumentPostfixTemplateTest.java @@ -0,0 +1,20 @@ +// 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 com.intellij.codeInsight.template.impl.TemplateManagerImpl; +import org.jetbrains.annotations.NotNull; + +public class ArgumentPostfixTemplateTest extends PostfixTemplateTestCase { + public void testSimple() { + TemplateManagerImpl.setTemplateTesting(myFixture.getProject(), getTestRootDisposable()); + myFixture.configureByFile(getTestName(true) + ".java"); + myFixture.type("\tfunctionCall\t"); + myFixture.checkResultByFile(getTestName(true) + "_after.java", true); + } + + @NotNull + @Override + protected String getSuffix() { + return "arg"; + } +}