aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAyushman Jain2012-07-30 07:14:52 (EDT)
committerJayaprakash Arthanareeswaran2012-08-10 02:59:14 (EDT)
commit56e6ea207731f6d3851d3f932b5a1a8aae6b42f7 (patch)
treecfdb5dcac9c7b2a5679245a83d38a03f0c2dcbc2
parent530988a731872b445321868ef3627a37fb897b2a (diff)
downloadeclipse.jdt.core-56e6ea207731f6d3851d3f932b5a1a8aae6b42f7.zip
eclipse.jdt.core-56e6ea207731f6d3851d3f932b5a1a8aae6b42f7.tar.gz
eclipse.jdt.core-56e6ea207731f6d3851d3f932b5a1a8aae6b42f7.tar.bz2
Fixed Bug 385858 - Add token location for constructor start
(TL_CONSTRUCTOR_START)
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java8
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java121
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java5
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java10
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/core/CompletionContext.java17
5 files changed, 157 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
index c0022a6..829bb99 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java
@@ -3014,7 +3014,7 @@ public void test0109() throws JavaModelException {
"completion token kind=TOKEN_KIND_NAME\n" +
"expectedTypesSignatures={Ljava.lang.Object;}\n" +
"expectedTypesKeys={Ljava/lang/Object;}\n"+
- "completion token location=UNKNOWN",
+ "completion token location={CONSTRUCTOR_START}",
result.context);
}
public void test0110() throws JavaModelException {
@@ -3040,7 +3040,7 @@ public void test0110() throws JavaModelException {
"completion token kind=TOKEN_KIND_NAME\n" +
"expectedTypesSignatures={Ljava.lang.Object;}\n" +
"expectedTypesKeys={Ljava/lang/Object;}\n"+
- "completion token location=UNKNOWN",
+ "completion token location={CONSTRUCTOR_START}",
result.context);
}
public void test0111() throws JavaModelException {
@@ -3066,7 +3066,7 @@ public void test0111() throws JavaModelException {
"completion token kind=TOKEN_KIND_NAME\n" +
"expectedTypesSignatures={Ljava.lang.Object;}\n" +
"expectedTypesKeys={Ljava/lang/Object;}\n"+
- "completion token location=UNKNOWN",
+ "completion token location={CONSTRUCTOR_START}",
result.context);
}
public void test0112() throws JavaModelException {
@@ -3092,7 +3092,7 @@ public void test0112() throws JavaModelException {
"completion token kind=TOKEN_KIND_NAME\n" +
"expectedTypesSignatures={Ljava.lang.Object;}\n" +
"expectedTypesKeys={Ljava/lang/Object;}\n"+
- "completion token location=UNKNOWN",
+ "completion token location={CONSTRUCTOR_START}",
result.context);
}
public void test0113() throws JavaModelException {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
index e199804..ef80588 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
@@ -1041,6 +1041,10 @@ public static Test suite() {
suite.addTest(new CompletionTests("testBug292087b"));
suite.addTest(new CompletionTests("testBug292087c"));
suite.addTest(new CompletionTests("testBug292087d"));
+ suite.addTest(new CompletionTests("testBug385858a"));
+ suite.addTest(new CompletionTests("testBug385858b"));
+ suite.addTest(new CompletionTests("testBug385858c"));
+ suite.addTest(new CompletionTests("testBug385858d"));
return suite;
}
public CompletionTests(String name) {
@@ -25655,4 +25659,121 @@ public void testBug292087d() throws JavaModelException {
"MyClassMethod[METHOD_REF]{MyClassMethod(), Ltest.Try;, ()Ltest.MyClass;, MyClassMethod, null, " + (R_RESOLVED + R_NON_STATIC + R_NAME_LESS_NEW_CHARACTERS + R_EXACT_EXPECTED_TYPE) + "}",
requestor.getResults());
}
+
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=385858
+public void testBug385858a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Completion.java",
+ "package test;\n" +
+ "public class Completion {\n" +
+ " void foo() {" +
+ " Completion c = new C\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "new C";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ "completion offset=74\n" +
+ "completion range=[73, 73]\n" +
+ "completion token=\"C\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ltest.Completion;}\n" +
+ "expectedTypesKeys={Ltest/Completion;}\n" +
+ "completion token location={CONSTRUCTOR_START}",
+ requestor.getContext());
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385858
+public void testBug385858b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Completion.java",
+ "package test;\n" +
+ "public class Completion {\n" +
+ " Completion c = new C\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "new C";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ "completion offset=61\n" +
+ "completion range=[60, 60]\n" +
+ "completion token=\"C\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ltest.Completion;}\n" +
+ "expectedTypesKeys={Ltest/Completion;}\n" +
+ "completion token location={CONSTRUCTOR_START}",
+ requestor.getContext());
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385858
+public void testBug385858c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Completion.java",
+ "package test;\n" +
+ "public class Completion {\n" +
+ " static class Inner{}\n" +
+ " void foo() {" +
+ " Inner c = new Completion.\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "new Completion.";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ "completion offset=102\n" +
+ "completion range=[102, 101]\n" +
+ "completion token=\"\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ltest.Completion$Inner;}\n" +
+ "expectedTypesKeys={Ltest/Completion$Inner;}\n" +
+ "completion token location={CONSTRUCTOR_START}",
+ requestor.getContext());
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385858
+public void testBug385858d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Completion.java",
+ "package test;\n" +
+ "public class Completion {\n" +
+ " static class Inner{}\n" +
+ " void foo() {" +
+ " Inner c = new \n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "new ";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ assertResults(
+ "completion offset=92\n" +
+ "completion range=[92, 91]\n" +
+ "completion token=\"\"\n" +
+ "completion token kind=TOKEN_KIND_NAME\n" +
+ "expectedTypesSignatures={Ltest.Completion$Inner;}\n" +
+ "expectedTypesKeys={Ltest/Completion$Inner;}\n" +
+ "completion token location={CONSTRUCTOR_START}",
+ requestor.getContext());
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java
index 09935f5..43a3873 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTestsRequestor2.java
@@ -197,6 +197,11 @@ public class CompletionTestsRequestor2 extends CompletionRequestor {
buffer.append("STATEMENT_START"); //$NON-NLS-1$
first = false;
}
+ if ((locationType & CompletionContext.TL_CONSTRUCTOR_START) != 0) {
+ if (!first) buffer.append(',');
+ buffer.append("CONSTRUCTOR_START"); //$NON-NLS-1$
+ first = false;
+ }
buffer.append('}');
}
}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index ded8ad2..2d1a070 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -1603,6 +1603,16 @@ public final class CompletionEngine
(method.annotations == null || method.annotations.length == 0)) {
context.setTokenLocation(CompletionContext.TL_MEMBER_START);
}
+ } else if (astNode instanceof CompletionOnSingleTypeReference) {
+ CompletionOnSingleTypeReference completionOnSingleTypeReference = (CompletionOnSingleTypeReference) astNode;
+ if (completionOnSingleTypeReference.isConstructorType) {
+ context.setTokenLocation(CompletionContext.TL_CONSTRUCTOR_START);
+ }
+ } else if (astNode instanceof CompletionOnQualifiedTypeReference) {
+ CompletionOnQualifiedTypeReference completionOnQualifiedTypeReference = (CompletionOnQualifiedTypeReference) astNode;
+ if (completionOnQualifiedTypeReference.isConstructorType){
+ context.setTokenLocation(CompletionContext.TL_CONSTRUCTOR_START);
+ }
} else {
ReferenceContext referenceContext = scope.referenceContext();
if (referenceContext instanceof AbstractMethodDeclaration) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/CompletionContext.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/CompletionContext.java
index fbdac5d..e00443f 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/CompletionContext.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/CompletionContext.java
@@ -52,6 +52,23 @@ public class CompletionContext {
* @since 3.4
*/
public static final int TL_STATEMENT_START = 2;
+
+ /**
+ * The completed token is the first token of a constructor.<br>
+ * e.g.
+ * <pre>
+ * public class X {
+ * public void bar() {
+ * new Foo| // completion occurs at |
+ * }
+ * }
+ * </pre>
+ *
+ * @see #getTokenLocation()
+ *
+ * @since 3.9
+ */
+ public static final int TL_CONSTRUCTOR_START = 4;
/**
* The completion token is unknown.