mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Postfix templates: add a template to wrap an expression with a function call (IDEA-122461)
This commit is contained in:
+32
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
void m(Object o) {
|
||||
<spot>call(o)</spot>$key
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class Foo {
|
||||
void m(Object o) {
|
||||
<spot>o</spot>$key
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Wraps object with a function call.
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Foo {
|
||||
void m(boolean b) {
|
||||
|
||||
b.arg<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class Foo {
|
||||
void m(boolean b) {
|
||||
|
||||
functionCall(b<caret>)
|
||||
}
|
||||
}
|
||||
+20
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user