mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
java postfix templates: '.format' template should be expression-based IDEA-139659
This commit is contained in:
+8
-3
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils.selectorTopmost;
|
||||
import static com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset;
|
||||
|
||||
public class FormatPostfixTemplate extends StringBasedPostfixTemplate {
|
||||
private static final Condition<PsiElement> IS_STRING = new Condition<PsiElement>() {
|
||||
@@ -39,13 +39,18 @@ public class FormatPostfixTemplate extends StringBasedPostfixTemplate {
|
||||
|
||||
|
||||
public FormatPostfixTemplate() {
|
||||
super("format", "String.format(expr)", selectorTopmost(IS_STRING));
|
||||
super("format", "String.format(expr)", selectorAllExpressionsWithCurrentOffset(IS_STRING));
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTemplateString(@NotNull PsiElement element) {
|
||||
return "String.format($expr$, $END$);";
|
||||
return "String.format($expr$, $END$)";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldRemoveParent() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package templates;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
public class Foo {
|
||||
void m(boolean b, int value) {
|
||||
throw new Exception("".format<caret>);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package templates;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
public class Foo {
|
||||
void m(boolean b, int value) {
|
||||
throw new Exception("".format<caret>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package templates;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
public class Foo {
|
||||
void m(boolean b, int value) {
|
||||
throw new Exception(String.format("", <caret>)
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package templates;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
public class Foo {
|
||||
void m(boolean b, int value) {
|
||||
throw new Exception(String.format("", <caret>));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,6 +2,6 @@ package templates;
|
||||
|
||||
public class Foo {
|
||||
void m(boolean b, int value) {
|
||||
String.format("m()", <caret>);
|
||||
String.format("m()", <caret>)
|
||||
}
|
||||
}
|
||||
+8
@@ -31,4 +31,12 @@ public class FormatPostfixTemplateTest extends PostfixTemplateTestCase {
|
||||
public void testNotString() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExpression() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExpressionNotCompleted() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user