View | Details | Raw Unified | Return to bug 304006 | Differences between
and this patch

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-3 / +33 lines)
Lines 564-575 Link Here
564
			if(expression == this.assistNode
564
			if(expression == this.assistNode
565
				|| (expression instanceof Assignment	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
565
				|| (expression instanceof Assignment	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
566
					&& ((Assignment)expression).expression == this.assistNode
566
					&& ((Assignment)expression).expression == this.assistNode
567
					&& (this.expressionPtr > 0 && this.expressionStack[this.expressionPtr - 1] instanceof InstanceOfExpression))
567
					&& (this.expressionPtr > 0 && hasInstanceOfExpression(this.expressionPtr-1)))
568
				|| (expression instanceof BinaryExpression	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
569
					&& (((BinaryExpression)expression).left == this.assistNode || ((BinaryExpression)expression).right == this.assistNode)
570
					&& (this.expressionPtr > 0 && hasInstanceOfExpression(this.expressionPtr-1)))
568
				|| (expression instanceof AllocationExpression
571
				|| (expression instanceof AllocationExpression
569
					&& ((AllocationExpression)expression).type == this.assistNode)){
572
					&& ((AllocationExpression)expression).type == this.assistNode)){
570
				buildMoreCompletionContext(expression);
573
				buildMoreCompletionContext(expression);
571
				if (this.assistNodeParent == null
574
				if (this.assistNodeParent == null
572
					&& expression instanceof Assignment) {
575
					&& (expression instanceof Assignment || expression instanceof BinaryExpression)) {
573
					this.assistNodeParent = detector.getCompletionNodeParent();
576
					this.assistNodeParent = detector.getCompletionNodeParent();
574
				}
577
				}
575
				return;
578
				return;
Lines 1066-1072 Link Here
1066
	int blockIndex = lastIndexOfElement(K_BLOCK_DELIMITER);
1069
	int blockIndex = lastIndexOfElement(K_BLOCK_DELIMITER);
1067
	int controlIndex = lastIndexOfElement(K_CONTROL_STATEMENT_DELIMITER);
1070
	int controlIndex = lastIndexOfElement(K_CONTROL_STATEMENT_DELIMITER);
1068
	int index = blockIndex != -1 && controlIndex < blockIndex ? blockIndex : controlIndex;
1071
	int index = blockIndex != -1 && controlIndex < blockIndex ? blockIndex : controlIndex;
1069
1072
	// Look for instanceof expression in the stack
1073
	// This is for cases where some other if statements follow the one with the instanceof expression
1074
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
1075
	int indexInstanceOf = index;
1076
	while (indexInstanceOf >= 0) {
1077
		if (this.elementInfoStack[indexInstanceOf] == IF && this.elementObjectInfoStack[indexInstanceOf] instanceof InstanceOfExpression) {
1078
			break;
1079
		}
1080
		indexInstanceOf--;
1081
	}
1082
	if (indexInstanceOf != -1)
1083
		index = indexInstanceOf;	// Instanceof expression found
1070
	if (index != -1 && this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] != null) {
1084
	if (index != -1 && this.elementInfoStack[index] == IF && this.elementObjectInfoStack[index] != null) {
1071
		Expression condition = (Expression)this.elementObjectInfoStack[index];
1085
		Expression condition = (Expression)this.elementObjectInfoStack[index];
1072
1086
Lines 4793-4796 Link Here
4793
		return field;
4807
		return field;
4794
	}
4808
	}
4795
}
4809
}
4810
4811
/*
4812
 * To find out if the expressionStack has an instanceof expression
4813
 * at an index prior to the one given by startIndex
4814
 */
4815
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
4816
private boolean hasInstanceOfExpression(int startIndex) {
4817
	int indexInstanceOf = startIndex;
4818
	while (indexInstanceOf >= 0) {
4819
		if (this.expressionStack[indexInstanceOf] instanceof InstanceOfExpression) {
4820
			return true;
4821
		}
4822
		indexInstanceOf--;
4823
	}
4824
	return false;
4825
}
4796
}
4826
}
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (-9 / +360 lines)
Lines 2368-2375 Link Here
2368
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}",
2368
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}",
2369
			requestor.getResults());
2369
			requestor.getResults());
2370
}
2370
}
2371
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2371
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
2372
// unsupported case
2372
// Auto cast feature works correctly for cases where the completion is asked not immediately next to the
2373
// instanceof expression
2374
// originally added as unsupported case in https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2373
public void testCompletionAfterInstanceof03_05() throws JavaModelException {
2375
public void testCompletionAfterInstanceof03_05() throws JavaModelException {
2374
	this.workingCopies = new ICompilationUnit[1];
2376
	this.workingCopies = new ICompilationUnit[1];
2375
	this.workingCopies[0] = getWorkingCopy(
2377
	this.workingCopies[0] = getWorkingCopy(
Lines 2394-2401 Link Here
2394
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
2396
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
2395
	int start1 = str.lastIndexOf("equal") + "".length();
2397
	int start1 = str.lastIndexOf("equal") + "".length();
2396
	int end1 = start1 + "equal".length();
2398
	int end1 = start1 + "equal".length();
2399
	int start2 = str.lastIndexOf("a.equal");
2400
	int end2 = start2 + "a.equal".length();
2401
	int start3 = str.lastIndexOf("a.");
2402
	int end3 = start3 + "a".length();
2397
	assertResults(
2403
	assertResults(
2398
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}",
2404
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}\n" +
2405
			"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) + "}",
2399
			requestor.getResults());
2406
			requestor.getResults());
2400
}
2407
}
2401
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2408
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
Lines 2503-2510 Link Here
2503
			"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) + "}",
2510
			"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) + "}",
2504
			requestor.getResults());
2511
			requestor.getResults());
2505
}
2512
}
2506
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2513
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
2507
// unsupported case
2514
// Auto cast feature works correctly for cases where the completion is asked not immediately next to the
2515
// instanceof expression
2516
// originally added as unsupported case in https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2508
public void testCompletionAfterInstanceof06_01() throws JavaModelException {
2517
public void testCompletionAfterInstanceof06_01() throws JavaModelException {
2509
	this.workingCopies = new ICompilationUnit[1];
2518
	this.workingCopies = new ICompilationUnit[1];
2510
	this.workingCopies[0] = getWorkingCopy(
2519
	this.workingCopies[0] = getWorkingCopy(
Lines 2529-2540 Link Here
2529
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
2538
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
2530
	int start1 = str.lastIndexOf("equal") + "".length();
2539
	int start1 = str.lastIndexOf("equal") + "".length();
2531
	int end1 = start1 + "equal".length();
2540
	int end1 = start1 + "equal".length();
2541
	int start2 = str.lastIndexOf("a.equal");
2542
	int end2 = start2 + "a.equal".length();
2543
	int start3 = str.lastIndexOf("a.");
2544
	int end3 = start3 + "a".length();
2532
	assertResults(
2545
	assertResults(
2533
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}",
2546
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}\n" +
2547
			"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) + "}",
2534
			requestor.getResults());
2548
			requestor.getResults());
2535
}
2549
}
2536
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2550
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
2537
// unsupported case
2551
// Auto cast feature works correctly for cases where the completion is asked not immediately next to the
2552
// instanceof expression
2553
// originally added as unsupported case in https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2538
public void testCompletionAfterInstanceof06_02() throws JavaModelException {
2554
public void testCompletionAfterInstanceof06_02() throws JavaModelException {
2539
	this.workingCopies = new ICompilationUnit[1];
2555
	this.workingCopies = new ICompilationUnit[1];
2540
	this.workingCopies[0] = getWorkingCopy(
2556
	this.workingCopies[0] = getWorkingCopy(
Lines 2559-2566 Link Here
2559
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
2575
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
2560
	int start1 = str.lastIndexOf("equal") + "".length();
2576
	int start1 = str.lastIndexOf("equal") + "".length();
2561
	int end1 = start1 + "equal".length();
2577
	int end1 = start1 + "equal".length();
2578
	int start2 = str.lastIndexOf("a.equal");
2579
	int end2 = start2 + "a.equal".length();
2580
	int start3 = str.lastIndexOf("a.");
2581
	int end3 = start3 + "a".length();
2562
	assertResults(
2582
	assertResults(
2563
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}",
2583
			"equals[METHOD_REF]{equals(), Ljava.lang.Object;, (Ljava.lang.Object;)Z, equals, (obj), replace["+start1+", "+end1+"], token["+start1+", "+end1+"], " + (relevance1) + "}\n" +
2584
			"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) + "}",
2564
			requestor.getResults());
2585
			requestor.getResults());
2565
}
2586
}
2566
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
2587
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193909
Lines 20766-20769 Link Here
20766
			"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) + "}",
20787
			"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) + "}",
20767
			requestor.getResults());
20788
			requestor.getResults());
20768
}
20789
}
20790
20791
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
20792
// To verify that autocast works correctly after an instanceof even if there are other expressions in between
20793
// instanceof and the place where code assist is requested.
20794
public void testBug304006a() throws JavaModelException {
20795
	this.workingCopies = new ICompilationUnit[1];
20796
	this.workingCopies[0] = getWorkingCopy(
20797
		"/Completion/src/test/CompletionAfterInstanceOf.java",
20798
		"package test;\n" +
20799
		"public class CompletionAfterInstanceOf {\n" +
20800
		"	public int foo() { return 1; }\n" +
20801
		"	public int returnZero(){ return 0;}\n" +
20802
		"	void bar(Object a){\n" +
20803
		"       int i = 1;\n" +
20804
		"		if (a instanceof CompletionAfterInstanceOf) {" +
20805
		"			if (i == 1)\n" +
20806
		"				i =  a.r\n" +
20807
		"	}\n" +
20808
		"}\n");
20809
20810
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
20811
	requestor.allowAllRequiredProposals();
20812
	String str = this.workingCopies[0].getSource();
20813
	String completeBehind = "a.r";
20814
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20815
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20816
20817
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
20818
	int start1 = str.lastIndexOf("r") + "".length();
20819
	int end1 = start1 + "r".length();
20820
	int start2 = str.lastIndexOf("a.r");
20821
	int end2 = start2 + "a.r".length();
20822
	int start3 = str.lastIndexOf("a.");
20823
	int end3 = start3 + "a".length();
20824
	
20825
	assertResults(
20826
			"expectedTypesSignatures={I}\n" +
20827
			"expectedTypesKeys={I}",
20828
			requestor.getContext());
20829
	assertResults(
20830
			"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) + "}",
20831
			requestor.getResults());
20832
}
20833
20834
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
20835
// To verify that autocast works correctly in a binary expression after an instanceof
20836
public void testBug304006b() throws JavaModelException {
20837
	this.workingCopies = new ICompilationUnit[1];
20838
	this.workingCopies[0] = getWorkingCopy(
20839
		"/Completion/src/test/CompletionAfterInstanceOf.java",
20840
		"package test;\n" +
20841
		"public class CompletionAfterInstanceOf {\n" +
20842
		"	public int foo() { return 1; }\n" +
20843
		"	public int returnZero(){ return 0;}\n" +
20844
		"	void bar(Object a){\n" +
20845
		"       int i = 1;\n" +
20846
		"		if (a instanceof CompletionAfterInstanceOf) {" +
20847
		"			if (i == 1 && a.r)\n" +
20848
		"	}\n" +
20849
		"}\n");
20850
20851
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
20852
	requestor.allowAllRequiredProposals();
20853
	String str = this.workingCopies[0].getSource();
20854
	String completeBehind = "a.r";
20855
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20856
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20857
20858
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
20859
	int start1 = str.lastIndexOf("r") + "".length();
20860
	int end1 = start1 + "r".length();
20861
	int start2 = str.lastIndexOf("a.r");
20862
	int end2 = start2 + "a.r".length();
20863
	int start3 = str.lastIndexOf("a.");
20864
	int end3 = start3 + "a".length();
20865
	
20866
	assertResults(
20867
			"expectedTypesSignatures={Z}\n" +
20868
			"expectedTypesKeys={Z}",
20869
			requestor.getContext());
20870
	assertResults(
20871
			"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) + "}",
20872
			requestor.getResults());
20873
}
20874
20875
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
20876
// To verify that autocast works correctly in a binary expression after an instanceof
20877
public void testBug304006c() throws JavaModelException {
20878
	this.workingCopies = new ICompilationUnit[1];
20879
	this.workingCopies[0] = getWorkingCopy(
20880
		"/Completion/src/test/CompletionAfterInstanceOf.java",
20881
		"package test;\n" +
20882
		"public class CompletionAfterInstanceOf {\n" +
20883
		"	public int foo() { return 1; }\n" +
20884
		"	public int returnZero(){ return 0;}\n" +
20885
		"	void bar(Object a){\n" +
20886
		"       int i = 1;\n" +
20887
		"		if (a instanceof CompletionAfterInstanceOf) {" +
20888
		"			if (i == 1 || a.r)\n" +
20889
		"	}\n" +
20890
		"}\n");
20891
20892
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
20893
	requestor.allowAllRequiredProposals();
20894
	String str = this.workingCopies[0].getSource();
20895
	String completeBehind = "a.r";
20896
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20897
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20898
20899
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
20900
	int start1 = str.lastIndexOf("r") + "".length();
20901
	int end1 = start1 + "r".length();
20902
	int start2 = str.lastIndexOf("a.r");
20903
	int end2 = start2 + "a.r".length();
20904
	int start3 = str.lastIndexOf("a.");
20905
	int end3 = start3 + "a".length();
20906
	
20907
	assertResults(
20908
			"expectedTypesSignatures={Z}\n" +
20909
			"expectedTypesKeys={Z}",
20910
			requestor.getContext());
20911
	assertResults(
20912
			"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) + "}",
20913
			requestor.getResults());
20914
}
20915
20916
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
20917
// To verify that autocast works correctly in a binary expression after an instanceof
20918
public void testBug304006d() throws JavaModelException {
20919
	this.workingCopies = new ICompilationUnit[1];
20920
	this.workingCopies[0] = getWorkingCopy(
20921
		"/Completion/src/test/CompletionAfterInstanceOf.java",
20922
		"package test;\n" +
20923
		"public class CompletionAfterInstanceOf {\n" +
20924
		"	public int foo() { return 1; }\n" +
20925
		"	public int returnZero(){ return 0;}\n" +
20926
		"	void bar(Object a){\n" +
20927
		"       int i = 1;\n" +
20928
		"		if (a instanceof CompletionAfterInstanceOf) {" +
20929
		"			if (i == 1 & a.r)\n" +
20930
		"	}\n" +
20931
		"}\n");
20932
20933
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
20934
	requestor.allowAllRequiredProposals();
20935
	String str = this.workingCopies[0].getSource();
20936
	String completeBehind = "a.r";
20937
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20938
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20939
20940
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
20941
	int start1 = str.lastIndexOf("r") + "".length();
20942
	int end1 = start1 + "r".length();
20943
	int start2 = str.lastIndexOf("a.r");
20944
	int end2 = start2 + "a.r".length();
20945
	int start3 = str.lastIndexOf("a.");
20946
	int end3 = start3 + "a".length();
20947
	
20948
	assertResults(
20949
			"expectedTypesSignatures={Z}\n" +
20950
			"expectedTypesKeys={Z}",
20951
			requestor.getContext());
20952
	assertResults(
20953
			"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) + "}",
20954
			requestor.getResults());
20955
}
20956
20957
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
20958
// To verify that autocast works correctly in a binary expression after an instanceof
20959
public void testBug304006e() throws JavaModelException {
20960
	this.workingCopies = new ICompilationUnit[1];
20961
	this.workingCopies[0] = getWorkingCopy(
20962
		"/Completion/src/test/CompletionAfterInstanceOf.java",
20963
		"package test;\n" +
20964
		"public class CompletionAfterInstanceOf {\n" +
20965
		"	public int foo() { return 1; }\n" +
20966
		"	public int returnZero(){ return 0;}\n" +
20967
		"	void bar(Object a){\n" +
20968
		"       int i = 1;\n" +
20969
		"		if (a instanceof CompletionAfterInstanceOf) {" +
20970
		"			if (i == 1 | a.r)\n" +
20971
		"	}\n" +
20972
		"}\n");
20973
20974
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
20975
	requestor.allowAllRequiredProposals();
20976
	String str = this.workingCopies[0].getSource();
20977
	String completeBehind = "a.r";
20978
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20979
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20980
20981
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
20982
	int start1 = str.lastIndexOf("r") + "".length();
20983
	int end1 = start1 + "r".length();
20984
	int start2 = str.lastIndexOf("a.r");
20985
	int end2 = start2 + "a.r".length();
20986
	int start3 = str.lastIndexOf("a.");
20987
	int end3 = start3 + "a".length();
20988
	
20989
	assertResults(
20990
			"expectedTypesSignatures={Z}\n" +
20991
			"expectedTypesKeys={Z}",
20992
			requestor.getContext());
20993
	assertResults(
20994
			"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) + "}",
20995
			requestor.getResults());
20996
}
20997
20998
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
20999
// To verify that autocast works correctly in a binary expression after an instanceof
21000
public void testBug304006f() throws JavaModelException {
21001
	this.workingCopies = new ICompilationUnit[1];
21002
	this.workingCopies[0] = getWorkingCopy(
21003
		"/Completion/src/test/CompletionAfterInstanceOf.java",
21004
		"package test;\n" +
21005
		"public class CompletionAfterInstanceOf {\n" +
21006
		"	public int foo() { return 1; }\n" +
21007
		"	public int returnZero(){ return 0;}\n" +
21008
		"	void bar(Object a){\n" +
21009
		"       int i = 1, j;\n" +
21010
		"		if (a instanceof CompletionAfterInstanceOf) {" +
21011
		"			if (j = a.r)\n" +
21012
		"	}\n" +
21013
		"}\n");
21014
21015
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
21016
	requestor.allowAllRequiredProposals();
21017
	String str = this.workingCopies[0].getSource();
21018
	String completeBehind = "a.r";
21019
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
21020
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
21021
21022
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
21023
	int start1 = str.lastIndexOf("r") + "".length();
21024
	int end1 = start1 + "r".length();
21025
	int start2 = str.lastIndexOf("a.r");
21026
	int end2 = start2 + "a.r".length();
21027
	int start3 = str.lastIndexOf("a.");
21028
	int end3 = start3 + "a".length();
21029
	
21030
	assertResults(
21031
			"expectedTypesSignatures={Z}\n" +
21032
			"expectedTypesKeys={Z}",
21033
			requestor.getContext());
21034
	assertResults(
21035
			"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) + "}",
21036
			requestor.getResults());
21037
}
21038
21039
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
21040
// To verify that autocast works correctly in a binary expression after an instanceof
21041
public void testBug304006g() throws JavaModelException {
21042
	this.workingCopies = new ICompilationUnit[1];
21043
	this.workingCopies[0] = getWorkingCopy(
21044
		"/Completion/src/test/CompletionAfterInstanceOf.java",
21045
		"package test;\n" +
21046
		"public class CompletionAfterInstanceOf {\n" +
21047
		"	public int foo() { return 1; }\n" +
21048
		"	public int returnZero(){ return 0;}\n" +
21049
		"	void bar(Object a){\n" +
21050
		"       int i = 1, j;\n" +
21051
		"		if (a instanceof CompletionAfterInstanceOf) {" +
21052
		"			if (i == a.r)\n" +
21053
		"	}\n" +
21054
		"}\n");
21055
21056
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
21057
	requestor.allowAllRequiredProposals();
21058
	String str = this.workingCopies[0].getSource();
21059
	String completeBehind = "a.r";
21060
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
21061
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
21062
21063
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
21064
	int start1 = str.lastIndexOf("r") + "".length();
21065
	int end1 = start1 + "r".length();
21066
	int start2 = str.lastIndexOf("a.r");
21067
	int end2 = start2 + "a.r".length();
21068
	int start3 = str.lastIndexOf("a.");
21069
	int end3 = start3 + "a".length();
21070
	
21071
	assertResults(
21072
			"expectedTypesSignatures={Z}\n" +
21073
			"expectedTypesKeys={Z}",
21074
			requestor.getContext());
21075
	assertResults(
21076
			"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) + "}",
21077
			requestor.getResults());
21078
}
21079
21080
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=304006
21081
// To verify that autocast works correctly in a binary expression after an instanceof
21082
public void testBug304006h() throws JavaModelException {
21083
	this.workingCopies = new ICompilationUnit[1];
21084
	this.workingCopies[0] = getWorkingCopy(
21085
		"/Completion/src/test/CompletionAfterInstanceOf.java",
21086
		"package test;\n" +
21087
		"public class CompletionAfterInstanceOf {\n" +
21088
		"	public int foo() { return 1; }\n" +
21089
		"	public int returnZero(){ return 0;}\n" +
21090
		"	void bar(Object a){\n" +
21091
		"       int i = 1, j;\n" +
21092
		"		if (a instanceof CompletionAfterInstanceOf) {" +
21093
		"			if (i != a.r)\n" +
21094
		"	}\n" +
21095
		"}\n");
21096
21097
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
21098
	requestor.allowAllRequiredProposals();
21099
	String str = this.workingCopies[0].getSource();
21100
	String completeBehind = "a.r";
21101
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
21102
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
21103
21104
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
21105
	int start1 = str.lastIndexOf("r") + "".length();
21106
	int end1 = start1 + "r".length();
21107
	int start2 = str.lastIndexOf("a.r");
21108
	int end2 = start2 + "a.r".length();
21109
	int start3 = str.lastIndexOf("a.");
21110
	int end3 = start3 + "a".length();
21111
	
21112
	assertResults(
21113
			"expectedTypesSignatures={Z}\n" +
21114
			"expectedTypesKeys={Z}",
21115
			requestor.getContext());
21116
	assertResults(
21117
			"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) + "}",
21118
			requestor.getResults());
21119
}
20769
}
21120
}

Return to bug 304006