postfix templates incorrect expand IDEA-133867

This commit is contained in:
Andrey Starovoyt
2014-12-04 21:15:05 +03:00
parent 2a2b009535
commit 0b767366cb
28 changed files with 203 additions and 9 deletions

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.assert<caret>
}
boolean methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.assert <caret>
}
boolean methodCall(String s) {
return null;
}
}

View File

@@ -1,8 +1,8 @@
public class Foo {
void m() {
assert is();<caret>
is();.assert <caret>
}
boolean is() {
return false;
}

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.if<caret>
}
boolean methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.if <caret>
}
boolean methodCall(String s) {
return null;
}
}

View File

@@ -1,10 +1,8 @@
public class Foo {
void m() {
if (is()) {
<caret>
}
is();.if <caret>
}
boolean is() {
return false;
}

View File

@@ -0,0 +1,5 @@
public class Foo {
Object m() {
new Object(.return<caret>
}
}

View File

@@ -0,0 +1,5 @@
public class Foo {
Object m() {
new Object(.return <caret>
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
String m() {
methodCall(.return<caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
String m() {
methodCall("string".return<caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
String m() {
methodCall("string".return <caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
String m() {
methodCall(.return <caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
String m() {
(methodCall("").return<caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
String m() {
(methodCall("").return <caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.sout<caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.sout <caret>
}
String methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,11 @@
import java.lang.Exception;
public class Foo {
void m() {
methodCall(.throw<caret>
}
Exception methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,11 @@
import java.lang.Exception;
public class Foo {
void m() {
methodCall(.throw <caret>
}
Exception methodCall(String s) {
return null;
}
}

View File

@@ -2,6 +2,6 @@ import java.lang.RuntimeException;
public class Foo {
void m() {
throw new RuntimeException("error");
new RuntimeException("error");.throw <caret>
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.while<caret>
}
boolean methodCall(String s) {
return null;
}
}

View File

@@ -0,0 +1,9 @@
public class Foo {
void m() {
methodCall(.while <caret>
}
boolean methodCall(String s) {
return null;
}
}

View File

@@ -71,5 +71,9 @@ public class AssertStatementPostfixTemplateTest extends PostfixTemplateTestCase
public void testSimpleWithSemicolon() {
doTest();
}
public void testIncompleteExpression() {
doTest();
}
}

View File

@@ -69,5 +69,7 @@ public class IfStatementPostfixTemplateTest extends PostfixTemplateTestCase {
doTest();
}
public void testIncompleteExpression() {
doTest();
}
}

View File

@@ -38,4 +38,20 @@ public class ReturnPostfixTemplateTest extends PostfixTemplateTestCase {
public void testComposite2() {
doTest();
}
public void testIncompleteExpression() {
doTest();
}
public void testIncompleteConstructor() {
doTest();
}
public void testIncompleteExpressionWithParam() {
doTest();
}
public void testIncompleteParentheses() {
doTest();
}
}

View File

@@ -31,4 +31,8 @@ public class SoutPostfixTemplateTest extends PostfixTemplateTestCase {
public void testVoid() {
doTest();
}
public void testIncompleteExpression() {
doTest();
}
}

View File

@@ -37,4 +37,7 @@ public class ThrowStatementPostfixTemplateTest extends PostfixTemplateTestCase {
public void testSimpleWithSemicolon() {
doTest();
}
public void testIncompleteExpression() {
doTest();
}
}

View File

@@ -34,6 +34,10 @@ public class WhileStatementPostfixTemplateTest extends PostfixTemplateTestCase {
doTest();
}
public void testIncompleteExpression() {
doTest();
}
@NotNull
@Override
protected String getSuffix() {

View File

@@ -19,6 +19,7 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
@@ -41,7 +42,11 @@ public class TopmostExpressionSelector implements PostfixTemplateExpressionSelec
@NotNull Document copyDocument,
int newOffset) {
PsiElement topmostExpression = template.getPsiInfo().getTopmostExpression(context);
return topmostExpression != null && myCondition.value(topmostExpression);
return topmostExpression != null &&
topmostExpression.getTextRange().getEndOffset() == newOffset &&
!PsiTreeUtil.hasErrorElements(topmostExpression) &&
myCondition.value(topmostExpression);
}
@Override