summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManju Mathew2013-04-15 11:47:42 (EDT)
committer Dani Megert2013-04-15 11:47:42 (EDT)
commit9e44ebc0447ede8a22ec472659a5fa68ca2c3424 (patch)
treeb036a091ba6fa01c1f1993834b5c77f7cff1f2f3
parentce474a3aac184c85eac01756791c5dd2ad20cc33 (diff)
downloadeclipse.jdt.ui-9e44ebc0447ede8a22ec472659a5fa68ca2c3424.zip
eclipse.jdt.ui-9e44ebc0447ede8a22ec472659a5fa68ca2c3424.tar.gz
eclipse.jdt.ui-9e44ebc0447ede8a22ec472659a5fa68ca2c3424.tar.bz2
Fixed bug 198508: [content assist] Code completion enhancement - semicolon after calls to void methodsI20130416-0800
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CamelCaseCompletionTest.java6
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java50
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodInsertionFormattedCompletionTest.java6
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParameterGuessingCompletionTest.java8
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParamsCompletionTest.java8
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FilledArgumentNamesMethodProposal.java5
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java17
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyJavaCompletionProposal.java3
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java3
9 files changed, 65 insertions, 41 deletions
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CamelCaseCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CamelCaseCompletionTest.java
index 36c9215..8400ee4 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CamelCaseCompletionTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CamelCaseCompletionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -42,12 +42,12 @@ public class CamelCaseCompletionTest extends AbstractCompletionTest {
public void testMethod() throws Exception {
addMembers("void methodCallWithParams(int par) {}");
- assertMethodBodyProposal("this.mCW|", "methodCallWith", "this.methodCallWithParams(|)");
+ assertMethodBodyProposal("this.mCW|", "methodCallWith", "this.methodCallWithParams(|);");
}
public void testMethodWithTrailing() throws Exception {
addMembers("void methodCallWithParams(int par) {}");
- assertMethodBodyProposal("this.mCWith|", "methodCallWith", "this.methodCallWithParams(|)");
+ assertMethodBodyProposal("this.mCWith|", "methodCallWith", "this.methodCallWithParams(|);");
}
public void testField() throws Exception {
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java
index a70f603..7accf33 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -895,16 +895,16 @@ public class CodeCompletionTest extends AbstractCompletionTest {
int i= 0;
assertAppliedProposal(contents, proposals[i++], "clone()");
assertAppliedProposal(contents, proposals[i++], "equals()");
- assertAppliedProposal(contents, proposals[i++], "finalize()");
+ assertAppliedProposal(contents, proposals[i++], "finalize();");
assertAppliedProposal(contents, proposals[i++], "getClass()");
assertAppliedProposal(contents, proposals[i++], "hashCode()");
- assertAppliedProposal(contents, proposals[i++], "notify()");
- assertAppliedProposal(contents, proposals[i++], "notifyAll()");
- assertAppliedProposal(contents, proposals[i++], "run()");
+ assertAppliedProposal(contents, proposals[i++], "notify();");
+ assertAppliedProposal(contents, proposals[i++], "notifyAll();");
+ assertAppliedProposal(contents, proposals[i++], "run();");
assertAppliedProposal(contents, proposals[i++], "toString()");
- assertAppliedProposal(contents, proposals[i++], "wait()");
- assertAppliedProposal(contents, proposals[i++], "wait()");
- assertAppliedProposal(contents, proposals[i++], "wait()");
+ assertAppliedProposal(contents, proposals[i++], "wait();");
+ assertAppliedProposal(contents, proposals[i++], "wait();");
+ assertAppliedProposal(contents, proposals[i++], "wait();");
}
public void testNormalAllMethodCompletionWithParametersGuessed() throws Exception {
@@ -946,16 +946,16 @@ public class CodeCompletionTest extends AbstractCompletionTest {
int i= 0;
assertAppliedProposal(contents, proposals[i++], "clone()");
assertAppliedProposal(contents, proposals[i++], "equals(run)");
- assertAppliedProposal(contents, proposals[i++], "finalize()");
+ assertAppliedProposal(contents, proposals[i++], "finalize();");
assertAppliedProposal(contents, proposals[i++], "getClass()");
assertAppliedProposal(contents, proposals[i++], "hashCode()");
- assertAppliedProposal(contents, proposals[i++], "notify()");
- assertAppliedProposal(contents, proposals[i++], "notifyAll()");
- assertAppliedProposal(contents, proposals[i++], "run()");
+ assertAppliedProposal(contents, proposals[i++], "notify();");
+ assertAppliedProposal(contents, proposals[i++], "notifyAll();");
+ assertAppliedProposal(contents, proposals[i++], "run();");
assertAppliedProposal(contents, proposals[i++], "toString()");
- assertAppliedProposal(contents, proposals[i++], "wait()");
- assertAppliedProposal(contents, proposals[i++], "wait(longVal)");
- assertAppliedProposal(contents, proposals[i++], "wait(longVal, intVal)");
+ assertAppliedProposal(contents, proposals[i++], "wait();");
+ assertAppliedProposal(contents, proposals[i++], "wait(longVal);");
+ assertAppliedProposal(contents, proposals[i++], "wait(longVal, intVal);");
assertEquals(i, proposals.length);
}
@@ -996,16 +996,16 @@ public class CodeCompletionTest extends AbstractCompletionTest {
int i= 0;
assertAppliedProposal(contents, proposals[i++], "clone()");
assertAppliedProposal(contents, proposals[i++], "equals(arg0)");
- assertAppliedProposal(contents, proposals[i++], "finalize()");
+ assertAppliedProposal(contents, proposals[i++], "finalize();");
assertAppliedProposal(contents, proposals[i++], "getClass()");
assertAppliedProposal(contents, proposals[i++], "hashCode()");
- assertAppliedProposal(contents, proposals[i++], "notify()");
- assertAppliedProposal(contents, proposals[i++], "notifyAll()");
- assertAppliedProposal(contents, proposals[i++], "run()");
+ assertAppliedProposal(contents, proposals[i++], "notify();");
+ assertAppliedProposal(contents, proposals[i++], "notifyAll();");
+ assertAppliedProposal(contents, proposals[i++], "run();");
assertAppliedProposal(contents, proposals[i++], "toString()");
- assertAppliedProposal(contents, proposals[i++], "wait()");
- assertAppliedProposal(contents, proposals[i++], "wait(arg0)");
- assertAppliedProposal(contents, proposals[i++], "wait(arg0, arg1)");
+ assertAppliedProposal(contents, proposals[i++], "wait();");
+ assertAppliedProposal(contents, proposals[i++], "wait(arg0);");
+ assertAppliedProposal(contents, proposals[i++], "wait(arg0, arg1);");
assertEquals(i, proposals.length);
}
@@ -1051,7 +1051,7 @@ public class CodeCompletionTest extends AbstractCompletionTest {
"public class Completion {\n" +
" \n" +
" void foomethod() {\n" +
- " this.foomethod()//here\n" +
+ " this.foomethod();//here\n" +
" }\n" +
"}\n";
@@ -1888,7 +1888,7 @@ public class CodeCompletionTest extends AbstractCompletionTest {
buf.append("\n");
buf.append("public class B {\n");
buf.append(" public void bar() {\n");
- buf.append(" foo()//here\n");
+ buf.append(" foo();//here\n");
buf.append(" }\n");
buf.append("}\n");
assertEquals(buf.toString(), doc.get());
@@ -1966,7 +1966,7 @@ public class CodeCompletionTest extends AbstractCompletionTest {
buf.append("\n");
buf.append("public class B {\n");
buf.append(" public void bar() {\n");
- buf.append(" A.foo()//here\n");
+ buf.append(" A.foo();//here\n");
buf.append(" }\n");
buf.append(" public void foo(int x) {\n");
buf.append(" }\n");
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodInsertionFormattedCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodInsertionFormattedCompletionTest.java
index 5e20493..001b583 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodInsertionFormattedCompletionTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodInsertionFormattedCompletionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -96,7 +96,7 @@ public class MethodInsertionFormattedCompletionTest extends AbstractCompletionTe
public void testFormattedMethodWithParameterFilling2() throws Exception {
getJDTUIPrefs().setValue(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES, true);
addMembers("private java.util.List fList;");
- assertMethodBodyProposal("fList.", "add(int", "fList.add ( |arg0|, arg1 )");
+ assertMethodBodyProposal("fList.", "add(int", "fList.add ( |arg0|, arg1 );");
}
public void testFormattedMethodWithParameterGuessing1() throws Exception {
@@ -114,7 +114,7 @@ public class MethodInsertionFormattedCompletionTest extends AbstractCompletionTe
addMembers("private java.util.List fList;");
addLocalVariables("int foo= 3; Object obj= null;\n");
- assertMethodBodyProposal("fList.", "add(int", "fList.add ( |foo|, obj )");
+ assertMethodBodyProposal("fList.", "add(int", "fList.add ( |foo|, obj );");
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParameterGuessingCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParameterGuessingCompletionTest.java
index 8bdc617..f597bba 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParameterGuessingCompletionTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParameterGuessingCompletionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -46,7 +46,7 @@ public class MethodParameterGuessingCompletionTest extends AbstractCompletionTes
}
public void testMethodWithParam2() throws Exception {
- assertMethodBodyProposal("fList.", "add(int", "fList.add(|foo|, obj)");
+ assertMethodBodyProposal("fList.", "add(int", "fList.add(|foo|, obj);");
}
public void testInsertMethodWithParam1() throws Exception {
@@ -54,7 +54,7 @@ public class MethodParameterGuessingCompletionTest extends AbstractCompletionTes
}
public void testInsertMethodWithParam2() throws Exception {
- assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|foo|, obj)bar");
+ assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|foo|, obj);bar");
}
public void testOverwriteMethodWithParam1() throws Exception {
@@ -64,7 +64,7 @@ public class MethodParameterGuessingCompletionTest extends AbstractCompletionTes
public void testOverwriteMethodWithParam2() throws Exception {
getJDTUIPrefs().setValue(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, false);
- assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|foo|, obj)");
+ assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|foo|, obj);");
}
}
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParamsCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParamsCompletionTest.java
index ed2c5bc..9f60dde 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParamsCompletionTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MethodParamsCompletionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -44,7 +44,7 @@ public class MethodParamsCompletionTest extends AbstractCompletionTest {
}
public void testMethodWithParam2() throws Exception {
- assertMethodBodyProposal("fList.", "add(int", "fList.add(|arg0|, arg1)");
+ assertMethodBodyProposal("fList.", "add(int", "fList.add(|arg0|, arg1);");
}
public void testInsertMethodWithParam1() throws Exception {
@@ -52,7 +52,7 @@ public class MethodParamsCompletionTest extends AbstractCompletionTest {
}
public void testInsertMethodWithParam2() throws Exception {
- assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|arg0|, arg1)bar");
+ assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|arg0|, arg1);bar");
}
public void testOverwriteMethodWithParam1() throws Exception {
@@ -62,7 +62,7 @@ public class MethodParamsCompletionTest extends AbstractCompletionTest {
public void testOverwriteMethodWithParam2() throws Exception {
getJDTUIPrefs().setValue(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, false);
- assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|arg0|, arg1)");
+ assertMethodBodyProposal("fList.|bar", "add(int", "fList.add(|arg0|, arg1);");
}
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FilledArgumentNamesMethodProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FilledArgumentNamesMethodProposal.java
index 783be74..58b4acc 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FilledArgumentNamesMethodProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FilledArgumentNamesMethodProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -142,6 +142,9 @@ public class FilledArgumentNamesMethodProposal extends JavaMethodCompletionPropo
buffer.append(RPAREN);
+ if (canAutomaticallyAppendSemicolon())
+ buffer.append(SEMICOLON);
+
return buffer.toString();
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java
index 30a84df..02fb8da 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java
@@ -23,6 +23,7 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.Signature;
+import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
@@ -57,6 +58,8 @@ public class JavaMethodCompletionProposal extends LazyJavaCompletionProposal {
super.apply(document, trigger, offset);
if (needsLinkedMode()) {
setUpLinkedMode(document, ')');
+ } else if (!fProposal.isConstructor() && getReplacementString().endsWith(";")) { //$NON-NLS-1$
+ setUpLinkedMode(document, ';');
}
}
@@ -126,6 +129,17 @@ public class JavaMethodCompletionProposal extends LazyJavaCompletionProposal {
return fHasParameters;
}
+ /**
+ * Returns whether we automatically complete the method with a semicolon.
+ *
+ * @return <code>true</code> if the return type of the method is void, <code>false</code>
+ * otherwise
+ * @since 3.9
+ */
+ protected final boolean canAutomaticallyAppendSemicolon() {
+ return !fProposal.isConstructor() && CharOperation.equals(new char[] { Signature.C_VOID }, Signature.getReturnType(fProposal.getSignature()));
+ }
+
private boolean computeHasParameters() throws IllegalArgumentException {
return Signature.getParameterCount(fProposal.getSignature()) > 0;
}
@@ -188,6 +202,9 @@ public class JavaMethodCompletionProposal extends LazyJavaCompletionProposal {
buffer.append(RPAREN);
+ if (canAutomaticallyAppendSemicolon())
+ buffer.append(SEMICOLON);
+
return buffer.toString();
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyJavaCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyJavaCompletionProposal.java
index 4b12870..a2c579c 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyJavaCompletionProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/LazyJavaCompletionProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -43,6 +43,7 @@ public class LazyJavaCompletionProposal extends AbstractJavaCompletionProposal {
protected static final String RPAREN= ")"; //$NON-NLS-1$
protected static final String COMMA= ","; //$NON-NLS-1$
protected static final String SPACE= " "; //$NON-NLS-1$
+ protected static final String SEMICOLON= ";"; //$NON-NLS-1$
protected static final class FormatterPrefs {
/* Methods & constructors */
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java
index 6d5966d..6b9c707 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java
@@ -281,6 +281,9 @@ public class ParameterGuessingProposal extends JavaMethodCompletionProposal {
buffer.append(RPAREN);
+ if (canAutomaticallyAppendSemicolon())
+ buffer.append(SEMICOLON);
+
return buffer.toString();
}