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

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-2 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 561-567 Link Here
561
					return;
561
					return;
562
				}
562
				}
563
			}
563
			}
564
			if(expression == this.assistNode
564
			if(expression == this.assistNode 
565
				||	(expression instanceof Assignment && ((Assignment) expression).expression == this.assistNode)
565
				|| (expression instanceof AllocationExpression
566
				|| (expression instanceof AllocationExpression
566
					&& ((AllocationExpression)expression).type == this.assistNode)){
567
					&& ((AllocationExpression)expression).type == this.assistNode)){
567
				buildMoreCompletionContext(expression);
568
				buildMoreCompletionContext(expression);
Lines 575-580 Link Here
575
			}
576
			}
576
		}
577
		}
577
	}
578
	}
579
	
580
	if (this.astPtr > -1 && this.astStack[this.astPtr] instanceof LocalDeclaration) {
581
		LocalDeclaration local = (LocalDeclaration) this.astStack[this.astPtr];
582
		if (local.initialization == this.assistNode) {
583
			Statement enclosing = buildMoreCompletionEnclosingContext(local);
584
			if (enclosing != local && enclosing instanceof IfStatement) {
585
				if (this.currentElement instanceof RecoveredBlock) {
586
					// RecoveredLocalVariable must be removed from its parent because the IfStatement will be added instead
587
					RecoveredBlock recoveredBlock =  (RecoveredBlock) this.currentElement;
588
					recoveredBlock.statements[--recoveredBlock.statementCount] = null;	
589
					this.currentElement = this.currentElement.add(enclosing, 0);
590
				}
591
			}
592
		}
593
	}
578
}
594
}
579
public Object becomeSimpleParser() {
595
public Object becomeSimpleParser() {
580
	CompletionScanner completionScanner = (CompletionScanner)this.scanner;
596
	CompletionScanner completionScanner = (CompletionScanner)this.scanner;
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+72 lines)
Lines 20600-20603 Link Here
20600
			requestor.getResults());
20600
			requestor.getResults());
20601
}
20601
}
20602
20602
20603
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
20604
public void testCompletionAfterInstanceof25_01() throws JavaModelException {
20605
	this.workingCopies = new ICompilationUnit[1];
20606
	this.workingCopies[0] = getWorkingCopy(
20607
		"/Completion/src/test/CompletionAfterInstanceOf.java",
20608
		"package test;\n" +
20609
		"public class CompletionAfterInstanceOf {\n" +
20610
		"	public int returnZero(){ return 0;}\n" +
20611
		"	public Object a;\n" +
20612
		"	void bar(){\n" +
20613
		"		if (this.a instanceof CompletionAfterInstanceOf) {\n" +
20614
		"       	int j = 0;\n" +
20615
		"       	int k = 2;\n" +
20616
		"			int i =  this.a.r\n" +
20617
		"       	int p = 12;\n" +
20618
		"	}\n" +
20619
		"}\n");
20620
20621
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
20622
	requestor.allowAllRequiredProposals();
20623
	String str = this.workingCopies[0].getSource();
20624
	String completeBehind = "this.a.r";
20625
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20626
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20627
20628
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
20629
	int start1 = str.lastIndexOf("r") + "r".length();
20630
	int end1 = start1 + "r".length();
20631
	int start2 = str.lastIndexOf("this.a.r");
20632
	int end2 = start2 + "this.a.r".length();
20633
	int start3 = str.lastIndexOf("this.a.");
20634
	int end3 = start3 + "this.a".length();
20635
	assertResults(
20636
			"returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)this.a).returnZero(), Ltest.CompletionAfterInstanceOf;, I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
20637
			requestor.getResults());
20638
}
20639
20640
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
20641
public void testCompletionAfterInstanceof25_02() throws JavaModelException {
20642
	this.workingCopies = new ICompilationUnit[1];
20643
	this.workingCopies[0] = getWorkingCopy(
20644
		"/Completion/src/test/CompletionAfterInstanceOf.java",
20645
		"package test;\n" +
20646
		"public class CompletionAfterInstanceOf {\n" +
20647
		"	public int returnZero(){ return 0;}\n" +
20648
		"	public Object a;\n" +
20649
		"	void bar(){\n" +
20650
		"       int i;\n" +
20651
		"		if (this.a instanceof CompletionAfterInstanceOf) {\n" +
20652
		"			i =  this.a.r\n" +
20653
		"	}\n" +
20654
		"}\n");
20655
20656
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
20657
	requestor.allowAllRequiredProposals();
20658
	String str = this.workingCopies[0].getSource();
20659
	String completeBehind = "this.a.r";
20660
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20661
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20662
20663
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED;
20664
	int start1 = str.lastIndexOf("r") + "r".length();
20665
	int end1 = start1 + "r".length();
20666
	int start2 = str.lastIndexOf("this.a.r");
20667
	int end2 = start2 + "this.a.r".length();
20668
	int start3 = str.lastIndexOf("this.a.");
20669
	int end3 = start3 + "this.a".length();
20670
	assertResults(
20671
			"returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)this.a).returnZero(), Ltest.CompletionAfterInstanceOf;, I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
20672
			requestor.getResults());
20673
}
20674
20603
}
20675
}

Return to bug 287939