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 172709 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 v2.0 + regression tests
patch304006new.txt (text/plain), 31.19 KB, created by
Ayushman Jain
on 2010-06-25 02:16:40 EDT
(
hide
)
Description:
proposed fix v2.0 + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2010-06-25 02:16:40 EDT
Size:
31.19 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java,v >retrieving revision 1.414 >diff -u -r1.414 CompletionEngine.java >--- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 22 Jun 2010 18:42:13 -0000 1.414 >+++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 24 Jun 2010 09:44:29 -0000 >@@ -6710,133 +6710,142 @@ > if (enclosingNode == null || !(enclosingNode instanceof IfStatement)) return; > > IfStatement ifStatement = (IfStatement)enclosingNode; >- >- if (!(ifStatement.condition instanceof InstanceOfExpression)) return; >- >- InstanceOfExpression instanceOfExpression = (InstanceOfExpression) ifStatement.condition; >- >- TypeReference instanceOfType = instanceOfExpression.type; >- >- if (instanceOfType.resolvedType == null) return; >- >- boolean findFromAnotherReceiver = false; >- >- char[][] receiverName = null; >- int receiverStart = -1; >- int receiverEnd = -1; >- >- if (receiver instanceof QualifiedNameReference) { >- QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) receiver; >- >- receiverName = qualifiedNameReference.tokens; >- >- if (receiverName.length != 1) return; >- >- receiverStart = (int) (qualifiedNameReference.sourcePositions[0] >>> 32); >- receiverEnd = (int) qualifiedNameReference.sourcePositions[qualifiedNameReference.tokens.length - 1] + 1; >- >- // if (local instanceof X) local.| >- // if (field instanceof X) field.| >- if (instanceOfExpression.expression instanceof SingleNameReference && >- ((SingleNameReference)instanceOfExpression.expression).binding == qualifiedBinding && >- (qualifiedBinding instanceof LocalVariableBinding || qualifiedBinding instanceof FieldBinding)) { >- findFromAnotherReceiver = true; >- } >- >- // if (this.field instanceof X) field.| >- if (instanceOfExpression.expression instanceof FieldReference) { >- FieldReference fieldReference = (FieldReference)instanceOfExpression.expression; >- >- if (fieldReference.receiver instanceof ThisReference && >- qualifiedBinding instanceof FieldBinding && >- fieldReference.binding == qualifiedBinding) { >- findFromAnotherReceiver = true; >- } >- } >- } else if (receiver instanceof FieldReference) { >- FieldReference fieldReference1 = (FieldReference) receiver; >- >- receiverStart = fieldReference1.sourceStart; >- receiverEnd = fieldReference1.sourceEnd + 1; >- >- if (fieldReference1.receiver instanceof ThisReference) { >- >- receiverName = new char[][] {THIS, fieldReference1.token}; >- >- // if (field instanceof X) this.field.| >+ while (true) { >+ if (!(ifStatement.condition instanceof InstanceOfExpression)) return; >+ >+ InstanceOfExpression instanceOfExpression = (InstanceOfExpression) ifStatement.condition; >+ >+ TypeReference instanceOfType = instanceOfExpression.type; >+ >+ if (instanceOfType.resolvedType == null) return; >+ >+ boolean findFromAnotherReceiver = false; >+ >+ char[][] receiverName = null; >+ int receiverStart = -1; >+ int receiverEnd = -1; >+ >+ if (receiver instanceof QualifiedNameReference) { >+ QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) receiver; >+ >+ receiverName = qualifiedNameReference.tokens; >+ >+ if (receiverName.length != 1) return; >+ >+ receiverStart = (int) (qualifiedNameReference.sourcePositions[0] >>> 32); >+ receiverEnd = (int) qualifiedNameReference.sourcePositions[qualifiedNameReference.tokens.length - 1] + 1; >+ >+ // if (local instanceof X) local.| >+ // if (field instanceof X) field.| > if (instanceOfExpression.expression instanceof SingleNameReference && >- ((SingleNameReference)instanceOfExpression.expression).binding == fieldReference1.binding) { >+ ((SingleNameReference)instanceOfExpression.expression).binding == qualifiedBinding && >+ (qualifiedBinding instanceof LocalVariableBinding || qualifiedBinding instanceof FieldBinding)) { > findFromAnotherReceiver = true; > } >- >- // if (this.field instanceof X) this.field.| >+ >+ // if (this.field instanceof X) field.| > if (instanceOfExpression.expression instanceof FieldReference) { >- FieldReference fieldReference2 = (FieldReference)instanceOfExpression.expression; >- >- if (fieldReference2.receiver instanceof ThisReference && >- fieldReference2.binding == fieldReference1.binding) { >+ FieldReference fieldReference = (FieldReference)instanceOfExpression.expression; >+ >+ if (fieldReference.receiver instanceof ThisReference && >+ qualifiedBinding instanceof FieldBinding && >+ fieldReference.binding == qualifiedBinding) { > findFromAnotherReceiver = true; > } > } >+ } else if (receiver instanceof FieldReference) { >+ FieldReference fieldReference1 = (FieldReference) receiver; >+ >+ receiverStart = fieldReference1.sourceStart; >+ receiverEnd = fieldReference1.sourceEnd + 1; >+ >+ if (fieldReference1.receiver instanceof ThisReference) { >+ >+ receiverName = new char[][] {THIS, fieldReference1.token}; >+ >+ // if (field instanceof X) this.field.| >+ if (instanceOfExpression.expression instanceof SingleNameReference && >+ ((SingleNameReference)instanceOfExpression.expression).binding == fieldReference1.binding) { >+ findFromAnotherReceiver = true; >+ } >+ >+ // if (this.field instanceof X) this.field.| >+ if (instanceOfExpression.expression instanceof FieldReference) { >+ FieldReference fieldReference2 = (FieldReference)instanceOfExpression.expression; >+ >+ if (fieldReference2.receiver instanceof ThisReference && >+ fieldReference2.binding == fieldReference1.binding) { >+ findFromAnotherReceiver = true; >+ } >+ } >+ } > } >- } >- >- if (findFromAnotherReceiver) { >- TypeBinding receiverTypeBinding = instanceOfType.resolvedType; >- char[] castedReceiver = null; >- >- char[] castedTypeChars = CharOperation.concatWith(instanceOfType.getTypeName(), '.'); >- if(this.source != null) { >- int memberRefStart = this.startPosition; >- >- char[] receiverChars = CharOperation.subarray(this.source, receiverStart, receiverEnd); >- char[] dotChars = CharOperation.subarray(this.source, receiverEnd, memberRefStart); >- >- castedReceiver = >- CharOperation.concat( >+ >+ if (findFromAnotherReceiver) { >+ TypeBinding receiverTypeBinding = instanceOfType.resolvedType; >+ char[] castedReceiver = null; >+ >+ char[] castedTypeChars = CharOperation.concatWith(instanceOfType.getTypeName(), '.'); >+ if(this.source != null) { >+ int memberRefStart = this.startPosition; >+ >+ char[] receiverChars = CharOperation.subarray(this.source, receiverStart, receiverEnd); >+ char[] dotChars = CharOperation.subarray(this.source, receiverEnd, memberRefStart); >+ >+ castedReceiver = > CharOperation.concat( >- '(', > CharOperation.concat( >- CharOperation.concat('(', castedTypeChars, ')'), >- receiverChars), >- ')'), >- dotChars); >- } else { >- castedReceiver = >- CharOperation.concat( >+ '(', >+ CharOperation.concat( >+ CharOperation.concat('(', castedTypeChars, ')'), >+ receiverChars), >+ ')'), >+ dotChars); >+ } else { >+ castedReceiver = > CharOperation.concat( >- '(', > CharOperation.concat( >- CharOperation.concat('(', castedTypeChars, ')'), >- CharOperation.concatWith(receiverName, '.')), >- ')'), >- DOT); >+ '(', >+ CharOperation.concat( >+ CharOperation.concat('(', castedTypeChars, ')'), >+ CharOperation.concatWith(receiverName, '.')), >+ ')'), >+ DOT); >+ } >+ >+ if (castedReceiver == null) return; >+ >+ int oldStartPosition = this.startPosition; >+ this.startPosition = receiverStart; >+ >+ findFieldsAndMethods( >+ this.completionToken, >+ receiverTypeBinding, >+ scope, >+ fieldsFound, >+ methodsFound, >+ invocationSite, >+ invocationScope, >+ false, >+ false, >+ null, >+ null, >+ null, >+ false, >+ castedReceiver, >+ receiverStart, >+ receiverEnd); >+ >+ this.startPosition = oldStartPosition; >+ } >+ // traverse the enclosing node to find the instanceof expression corresponding >+ // to the completion node (if any) >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+ if (ifStatement.thenStatement instanceof IfStatement) { >+ ifStatement = (IfStatement) ifStatement.thenStatement; >+ } else { >+ break; > } >- >- if (castedReceiver == null) return; >- >- int oldStartPosition = this.startPosition; >- this.startPosition = receiverStart; >- >- findFieldsAndMethods( >- this.completionToken, >- receiverTypeBinding, >- scope, >- fieldsFound, >- methodsFound, >- invocationSite, >- invocationScope, >- false, >- false, >- null, >- null, >- null, >- false, >- castedReceiver, >- receiverStart, >- receiverEnd); >- >- this.startPosition = oldStartPosition; > } > } > private void findFieldsAndMethodsFromFavorites( >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.217 >diff -u -r1.217 CompletionParser.java >--- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 21 Jun 2010 07:52:34 -0000 1.217 >+++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 24 Jun 2010 09:44:37 -0000 >@@ -563,8 +563,9 @@ > 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.elementPtr >= 0 && this.elementObjectInfoStack[this.elementPtr] instanceof InstanceOfExpression))) >+ && ((this.expressionPtr > 0 && stackHasInstanceOfExpression(this.expressionStack, this.expressionPtr - 1)) >+ // In case of error in compilation unit, expression stack might not have instanceof exp, so try elementObjectInfoStack >+ || (this.elementPtr >= 0 && stackHasInstanceOfExpression(this.elementObjectInfoStack, this.elementPtr)))) > || (expression instanceof AllocationExpression > && ((AllocationExpression)expression).type == this.assistNode) > || (expression instanceof AND_AND_Expression >@@ -1064,7 +1065,7 @@ > } > } > private Statement buildMoreCompletionEnclosingContext(Statement statement) { >- >+ IfStatement ifStatement = null; > int blockIndex = lastIndexOfElement(K_BLOCK_DELIMITER); > int controlIndex = lastIndexOfElement(K_CONTROL_STATEMENT_DELIMITER); > int index; >@@ -1077,42 +1078,63 @@ > int instanceOfIndex = lastIndexOfElement(K_BETWEEN_INSTANCEOF_AND_RPAREN); > index = blockIndex != -1 && instanceOfIndex < blockIndex ? blockIndex : instanceOfIndex; > } >- if (index != -1 && this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] != null) { >- Expression condition = (Expression)this.elementObjectInfoStack[index]; >- >- // If currentElement is a RecoveredLocalVariable then it can be contained in the if statement >- if (this.currentElement instanceof RecoveredLocalVariable && >- this.currentElement.parent instanceof RecoveredBlock) { >- RecoveredLocalVariable recoveredLocalVariable = (RecoveredLocalVariable) this.currentElement; >- if (recoveredLocalVariable.localDeclaration.initialization == null && >- statement instanceof Expression && >- condition.sourceStart < recoveredLocalVariable.localDeclaration.sourceStart) { >- this.currentElement.add(statement, 0); >- >- statement = recoveredLocalVariable.updatedStatement(0, new HashSet()); >- >- // RecoveredLocalVariable must be removed from its parent because the IfStatement will be added instead >- RecoveredBlock recoveredBlock = (RecoveredBlock) recoveredLocalVariable.parent; >- recoveredBlock.statements[--recoveredBlock.statementCount] = null; >- >- this.currentElement = recoveredBlock; >- >+ while (index >= 0) { >+ // Try to find an enclosing if statement even if one is not found immediately preceding the completion node. >+ if (index != -1 && this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] != null) { >+ Expression condition = (Expression)this.elementObjectInfoStack[index]; >+ >+ // If currentElement is a RecoveredLocalVariable then it can be contained in the if statement >+ if (this.currentElement instanceof RecoveredLocalVariable && >+ this.currentElement.parent instanceof RecoveredBlock) { >+ RecoveredLocalVariable recoveredLocalVariable = (RecoveredLocalVariable) this.currentElement; >+ if (recoveredLocalVariable.localDeclaration.initialization == null && >+ statement instanceof Expression && >+ condition.sourceStart < recoveredLocalVariable.localDeclaration.sourceStart) { >+ this.currentElement.add(statement, 0); >+ >+ statement = recoveredLocalVariable.updatedStatement(0, new HashSet()); >+ >+ // RecoveredLocalVariable must be removed from its parent because the IfStatement will be added instead >+ RecoveredBlock recoveredBlock = (RecoveredBlock) recoveredLocalVariable.parent; >+ recoveredBlock.statements[--recoveredBlock.statementCount] = null; >+ >+ this.currentElement = recoveredBlock; >+ >+ } > } >+ if (statement instanceof AND_AND_Expression && this.assistNode instanceof Statement) { >+ statement = (Statement) this.assistNode; >+ } >+ ifStatement = >+ new IfStatement( >+ condition, >+ statement, >+ condition.sourceStart, >+ statement.sourceEnd); >+ index--; >+ break; > } >- if (statement instanceof AND_AND_Expression && this.assistNode instanceof Statement) { >- statement = (Statement) this.assistNode; >+ index--; >+ } >+ if (ifStatement == null) { >+ return statement; >+ } >+ // collect all if statements with instanceof expressions that enclose the completion node >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006 >+ while (index >= 0) { >+ if (this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] instanceof InstanceOfExpression) { >+ InstanceOfExpression condition = (InstanceOfExpression)this.elementObjectInfoStack[index]; >+ ifStatement = >+ new IfStatement( >+ condition, >+ ifStatement, >+ condition.sourceStart, >+ ifStatement.sourceEnd); > } >- IfStatement ifStatement = >- new IfStatement( >- condition, >- statement, >- condition.sourceStart, >- statement.sourceEnd); >- this.enclosingNode = ifStatement; >- return ifStatement; >+ index--; > } >- >- return statement; >+ this.enclosingNode = ifStatement; >+ return ifStatement; > } > private void buildMoreGenericsCompletionContext(ASTNode node, boolean consumeTypeArguments) { > int kind = topKnownElementKind(COMPLETION_OR_ASSIST_PARSER); >@@ -4840,4 +4862,19 @@ > return field; > } > } >+ >+/* >+ * To find out if the given stack has an instanceof expression >+ * at the given startIndex or at one prior to that >+ */ >+private boolean stackHasInstanceOfExpression(Object[] stackToSearch, int startIndex) { >+ int indexInstanceOf = startIndex; >+ while (indexInstanceOf >= 0) { >+ if (stackToSearch[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.221 >diff -u -r1.221 CompletionTests.java >--- src/org/eclipse/jdt/core/tests/model/CompletionTests.java 22 Jun 2010 18:34:03 -0000 1.221 >+++ src/org/eclipse/jdt/core/tests/model/CompletionTests.java 24 Jun 2010 09:47:26 -0000 >@@ -2390,8 +2390,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 >@@ -2525,8 +2530,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 >@@ -2555,8 +2565,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 >@@ -2587,8 +2602,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 >@@ -21454,4 +21474,221 @@ > "AN_INT_VALUE2[FIELD_REF]{AN_INT_VALUE2, Ltest.CompletionAfterCase2;, I, AN_INT_VALUE2, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE + R_FINAL) + "}", > 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 after an instanceof even if there are other expressions in between >+// instanceof and the place where code assist is requested. >+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)\n" + >+ " 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( >+ "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 even when the completion node >+// is preceeded by a number of unrelated instanceof expressions >+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 abc, Object xyz){\n" + >+ " int i = 1, j;\n" + >+ " if(i == 1)\n" + >+ " if (abc instanceof CompletionAfterInstanceOf)\n" + >+ " if(xyz instanceof CompletionAfterInstanceOf){\n" + >+ " j = 1;\n" + >+ " if(j == 1)\n" + >+ " i = abc.r \n" + >+ " }\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "abc.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("abc.r"); >+ int end2 = start2 + "abc.r".length(); >+ int start3 = str.lastIndexOf("abc."); >+ int end3 = start3 + "abc".length(); >+ >+ assertResults( >+ "expectedTypesSignatures={I}\n" + >+ "expectedTypesKeys={I}", >+ requestor.getContext()); >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)abc).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 even when the completion node is preceeded by a number >+// of unrelated instanceof expressions. This case has errors in compilation unit. >+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 abc, Object xyz){\n" + >+ " int i = 1, j;\n" + >+ " j = \n" + >+ " if(i == 1)\n" + >+ " if (abc instanceof CompletionAfterInstanceOf)\n" + >+ " if(xyz instanceof CompletionAfterInstanceOf){\n" + >+ " j = 1;\n" + >+ " if(j == 1)\n" + >+ " xyz.r \n" + >+ " }\n" + >+ " }\n" + >+ "}\n"); >+ >+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true); >+ requestor.allowAllRequiredProposals(); >+ String str = this.workingCopies[0].getSource(); >+ String completeBehind = "xyz.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("xyz.r"); >+ int end2 = start2 + "xyz.r".length(); >+ int start3 = str.lastIndexOf("xyz."); >+ int end3 = start3 + "xyz".length(); >+ >+ assertResults( >+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)xyz).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. This is a case with errors in the compilation unit. >+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" + >+ " int i = \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()); >+} > }
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