Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 160299 Details for
Bug 304006
[code assist] Autocast after instanceof feature doesnt work in some cases.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed fix v0.5 + regression tests
patchAutoCastFull.txt (text/plain), 24.78 KB, created by
Ayushman Jain
on 2010-02-26 08:27:17 EST
(
hide
)
Description:
proposed fix v0.5 + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2010-02-26 08:27:17 EST
Size:
24.78 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java,v >retrieving revision 1.210 >diff -u -r1.210 CompletionParser.java >--- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 18 Feb 2010 06:50:57 -0000 1.210 >+++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 26 Feb 2010 12:38:12 -0000 >@@ -564,12 +564,15 @@ > if(expression == this.assistNode > || (expression instanceof Assignment // https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939 > && ((Assignment)expression).expression == this.assistNode >- && (this.expressionPtr > 0 && this.expressionStack[this.expressionPtr - 1] instanceof InstanceOfExpression)) >+ && (this.expressionPtr > 0 && hasInstanceOfExpression(this.expressionPtr-1))) >+ || (expression instanceof BinaryExpression // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+ && (((BinaryExpression)expression).left == this.assistNode || ((BinaryExpression)expression).right == this.assistNode) >+ && (this.expressionPtr > 0 && hasInstanceOfExpression(this.expressionPtr-1))) > || (expression instanceof AllocationExpression > && ((AllocationExpression)expression).type == this.assistNode)){ > buildMoreCompletionContext(expression); > if (this.assistNodeParent == null >- && expression instanceof Assignment) { >+ && (expression instanceof Assignment || expression instanceof BinaryExpression)) { > this.assistNodeParent = detector.getCompletionNodeParent(); > } > return; >@@ -1066,7 +1069,18 @@ > int blockIndex = lastIndexOfElement(K_BLOCK_DELIMITER); > int controlIndex = lastIndexOfElement(K_CONTROL_STATEMENT_DELIMITER); > int index = blockIndex != -1 && controlIndex < blockIndex ? blockIndex : controlIndex; >- >+ // Look for instanceof expression in the stack >+ // This is for cases where some other if statements follow the one with the instanceof expression >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+ int indexInstanceOf = index; >+ while (indexInstanceOf >= 0) { >+ if (this.elementInfoStack[indexInstanceOf] == IF && this.elementObjectInfoStack[indexInstanceOf] instanceof InstanceOfExpression) { >+ break; >+ } >+ indexInstanceOf--; >+ } >+ if (indexInstanceOf != -1) >+ index = indexInstanceOf; // Instanceof expression found > if (index != -1 && this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] != null) { > Expression condition = (Expression)this.elementObjectInfoStack[index]; > >@@ -4793,4 +4807,20 @@ > return field; > } > } >+ >+/* >+ * To find out if the expressionStack has an instanceof expression >+ * at an index prior to the one given by startIndex >+ */ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+private boolean hasInstanceOfExpression(int startIndex) { >+ int indexInstanceOf = startIndex; >+ while (indexInstanceOf >= 0) { >+ if (this.expressionStack[indexInstanceOf] instanceof InstanceOfExpression) { >+ return true; >+ } >+ indexInstanceOf--; >+ } >+ return false; >+} > } >\ No newline at end of file >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/CompletionTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java,v >retrieving revision 1.211 >diff -u -r1.211 CompletionTests.java >--- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 18 Feb 2010 06:51:07 -0000 1.211 >+++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 26 Feb 2010 12:38:52 -0000 >@@ -2368,8 +2368,10 @@ > "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}", > requestor.getResults()); > } >-// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 >-// unsupported case >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// Auto cast feature works correctly for cases where the completion is asked not immediately next to the >+// instanceof expression >+// originally added as unsupported case in https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 > public void testCompletionAfterInstanceof03_05() throws JavaModelException { > this.workingCopies = new ICompilationUnit[1]; > this.workingCopies[0] = getWorkingCopy( >@@ -2394,8 +2396,13 @@ > int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; > int start1 = str.lastIndexOf("equal") + "".length(); > int end1 = start1 + "equal".length(); >+ int start2 = str.lastIndexOf("a.equal"); >+ int end2 = start2 + "a.equal".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); > assertResults( >- "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}", >+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}\n" + >+ "equalsFoo[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).equalsFoo(), Ltest.CompletionAfterInstanceOf;, ()V, Ltest.CompletionAfterInstanceOf;, equalsFoo, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", > requestor.getResults()); > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 >@@ -2503,8 +2510,10 @@ > "equalsFoo[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).equalsFoo(), Ltest.CompletionAfterInstanceOf;, ()V, Ltest.CompletionAfterInstanceOf;, equalsFoo, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", > requestor.getResults()); > } >-// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 >-// unsupported case >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// Auto cast feature works correctly for cases where the completion is asked not immediately next to the >+// instanceof expression >+// originally added as unsupported case in https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 > public void testCompletionAfterInstanceof06_01() throws JavaModelException { > this.workingCopies = new ICompilationUnit[1]; > this.workingCopies[0] = getWorkingCopy( >@@ -2529,12 +2538,19 @@ > int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; > int start1 = str.lastIndexOf("equal") + "".length(); > int end1 = start1 + "equal".length(); >+ int start2 = str.lastIndexOf("a.equal"); >+ int end2 = start2 + "a.equal".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); > assertResults( >- "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}", >+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}\n" + >+ "equalsFoo[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).equalsFoo(), Ltest.CompletionAfterInstanceOf;, ()V, Ltest.CompletionAfterInstanceOf;, equalsFoo, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", > requestor.getResults()); > } >-// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 >-// unsupported case >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// Auto cast feature works correctly for cases where the completion is asked not immediately next to the >+// instanceof expression >+// originally added as unsupported case in https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 > public void testCompletionAfterInstanceof06_02() throws JavaModelException { > this.workingCopies = new ICompilationUnit[1]; > this.workingCopies[0] = getWorkingCopy( >@@ -2559,8 +2575,13 @@ > int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; > int start1 = str.lastIndexOf("equal") + "".length(); > int end1 = start1 + "equal".length(); >+ int start2 = str.lastIndexOf("a.equal"); >+ int end2 = start2 + "a.equal".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); > assertResults( >- "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}", >+ "equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}\n" + >+ "equalsFoo[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).equalsFoo(), Ltest.CompletionAfterInstanceOf;, ()V, Ltest.CompletionAfterInstanceOf;, equalsFoo, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", > requestor.getResults()); > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909 >@@ -20766,4 +20787,334 @@ > "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", > requestor.getResults()); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly after an instanceof even if there are other expressions in between >+// instanceof and the place where code assist is requested. >+public void testBug304006a() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (i == 1)\n" + >+ " i = a.r\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={I}\n" + >+ "expectedTypesKeys={I}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly in a binary expression after an instanceof >+public void testBug304006b() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (i == 1 && a.r)\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={Z}\n" + >+ "expectedTypesKeys={Z}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly in a binary expression after an instanceof >+public void testBug304006c() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (i == 1 || a.r)\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={Z}\n" + >+ "expectedTypesKeys={Z}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly in a binary expression after an instanceof >+public void testBug304006d() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (i == 1 & a.r)\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={Z}\n" + >+ "expectedTypesKeys={Z}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly in a binary expression after an instanceof >+public void testBug304006e() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (i == 1 | a.r)\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={Z}\n" + >+ "expectedTypesKeys={Z}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly in a binary expression after an instanceof >+public void testBug304006f() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1, j;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (j = a.r)\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={Z}\n" + >+ "expectedTypesKeys={Z}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly in a binary expression after an instanceof >+public void testBug304006g() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1, j;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (i == a.r)\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={Z}\n" + >+ "expectedTypesKeys={Z}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+// To verify that autocast works correctly in a binary expression after an instanceof >+public void testBug304006h() throws JavaModelException { >+ this.workingCopies = new ICompilationUnit[1]; >+ this.workingCopies[0] = getWorkingCopy( >+ "/Completion/src/test/CompletionAfterInstanceOf.java", >+ "package test;\n" + >+ "public class CompletionAfterInstanceOf {\n" + >+ " public int foo() { return 1; }\n" + >+ " public int returnZero(){ return 0;}\n" + >+ " void bar(Object a){\n" + >+ " int i = 1, j;\n" + >+ " if (a instanceof CompletionAfterInstanceOf) {" + >+ " if (i != a.r)\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "a.r"; >+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); >+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); >+ >+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED; >+ int start1 = str.lastIndexOf("r") + "".length(); >+ int end1 = start1 + "r".length(); >+ int start2 = str.lastIndexOf("a.r"); >+ int end2 = start2 + "a.r".length(); >+ int start3 = str.lastIndexOf("a."); >+ int end3 = start3 + "a".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={Z}\n" + >+ "expectedTypesKeys={Z}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}", >+ requestor.getResults()); >+} > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 304006
:
160299
|
162384
|
172709