diff options
author | Sebastian Ratz | 2019-10-05 04:13:11 +0000 |
---|---|---|
committer | Roland Grunberg | 2019-10-07 18:32:43 +0000 |
commit | 98392df9bdef2f736420e927e1dbf1fe2afa0866 (patch) | |
tree | 57ca5df8f27fb1f6bf9a6cf9fb64ff24cfc97d84 | |
parent | cf6c42522ee5a5ea21a34fcfdecf3504d4750a04 (diff) | |
download | eclipse.jdt.ui-98392df9bdef2f736420e927e1dbf1fe2afa0866.tar.gz eclipse.jdt.ui-98392df9bdef2f736420e927e1dbf1fe2afa0866.tar.xz eclipse.jdt.ui-98392df9bdef2f736420e927e1dbf1fe2afa0866.zip |
Bug 458804 - Postfix Completion: MethodInvocationI20191007-1800
void test() {
String x = "5";
Integer.valueOf(x).var$
}
resulted in
void test() {
String x = "5";
String name = Integer.valueOf(x);$
}
Change-Id: I6821fc70e4a467477f3a0c28375a4fba734414b8
Signed-off-by: Sebastian Ratz <sebastian.ratz@sap.com>
2 files changed, 38 insertions, 0 deletions
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java index 3fd74dc468..ee61a504b0 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java @@ -411,6 +411,37 @@ public class PostFixCompletionTest extends TestCase { assertEquals(expected.toString(), viewer.getDocument().get()); } + public void testVarForMethodInvocation2() throws Exception { + StringBuffer buf= new StringBuffer(); + buf.append("package test;\n" + + "public class VarForMethodInvocation2 {\n" + + " public void test () {\n" + + " String s = \"5\";\n" + + " Integer.valueOf(s).var$\n" + + " }\n" + + "}"); + + int completionIndex= getCompletionIndex(buf); + ICompilationUnit cu= getCompilationUnit(pkg, buf, "VarForMethodInvocation2.java"); + List<ICompletionProposal> proposals= computeCompletionProposals(cu, completionIndex); + + assertProposalsExist(Arrays.asList("var - Creates a new variable"), proposals); + + ITextViewer viewer= initializeViewer(cu); + applyProposal(viewer, proposals, "var", completionIndex); + + StringBuffer expected= new StringBuffer(); + expected.append("package test;\n" + + "public class VarForMethodInvocation2 {\n" + + " public void test () {\n" + + " String s = \"5\";\n" + + " Integer name = Integer.valueOf(s);\n" + + " }\n" + + "}"); + + assertEquals(expected.toString(), viewer.getDocument().get()); + } + public void testNestedQualifiedNames() throws Exception { StringBuffer buf= new StringBuffer(); buf.append("package test;\n" + diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContext.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContext.java index a4ed557c1b..16fdda3bba 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContext.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContext.java @@ -615,6 +615,13 @@ public class JavaPostfixContext extends JavaContext { ITypeBinding[] res= new ITypeBinding[1]; node.accept(new ASTVisitor() { + + @Override + public boolean visit(MethodInvocation n) { + res[0]= n.resolveTypeBinding(); + return false; + } + @Override public boolean visit(SimpleName n) { IBinding b= n.resolveBinding(); |