java postfix templates: '.format' template should be expression-based IDEA-139659

This commit is contained in:
Andrey Starovoyt
2015-04-27 17:06:08 +03:00
parent e79e75784e
commit 373deb8475
7 changed files with 53 additions and 4 deletions
@@ -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>);
}
}
@@ -0,0 +1,9 @@
package templates;
import java.lang.Exception;
public class Foo {
void m(boolean b, int value) {
throw new Exception("".format<caret>
}
}
@@ -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>)
}
}
@@ -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>));
}
}
@@ -2,6 +2,6 @@ package templates;
public class Foo {
void m(boolean b, int value) {
String.format("m()", <caret>);
String.format("m()", <caret>)
}
}
@@ -31,4 +31,12 @@ public class FormatPostfixTemplateTest extends PostfixTemplateTestCase {
public void testNotString() {
doTest();
}
public void testExpression() {
doTest();
}
public void testExpressionNotCompleted() {
doTest();
}
}