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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+247 lines)
Lines 19627-19630 Link Here
19627
		COMPLETION_PROJECT.setOptions(options);	
19627
		COMPLETION_PROJECT.setOptions(options);	
19628
	}
19628
	}
19629
}
19629
}
19630
19631
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19632
// All the tests with the prefix test269493 are designed to offer coverage for all the changes that went
19633
// into this fix.
19634
public void test269493() throws JavaModelException {
19635
	this.workingCopies = new ICompilationUnit[1];
19636
	this.workingCopies[0] = getWorkingCopy(
19637
			"/Completion/src/test/Test269493.java",
19638
			"package test;" +
19639
			"public class Test269493 {\n" +
19640
			"	void foo() {\n" +
19641
			"   for (int i = 0; i < 10; i++)\n" +
19642
			"       ass\n" +
19643
			"	}\n" +
19644
			"}\n" +
19645
			"}\n");
19646
			
19647
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); 
19648
	String str = this.workingCopies[0].getSource();
19649
	String completeBehind = "ass";
19650
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19651
19652
	// Save current compliance settings
19653
	Map options = COMPLETION_PROJECT.getOptions(true);
19654
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
19655
	
19656
	try {
19657
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
19658
		COMPLETION_PROJECT.setOptions(options);
19659
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19660
		assertResults(
19661
				"assert[KEYWORD]{assert, null, null, assert, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
19662
				requestor.getResults());
19663
	} finally {
19664
		// Restore compliance settings.
19665
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
19666
		COMPLETION_PROJECT.setOptions(options);	
19667
	}
19668
}
19669
19670
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19671
public void test269493b() throws JavaModelException {
19672
	this.workingCopies = new ICompilationUnit[1];
19673
	this.workingCopies[0] = getWorkingCopy(
19674
			"/Completion/src/test/Test269493.java",
19675
			"package test;" +
19676
			"public class Test269493 {\n" +
19677
			"	void foo() {\n" +
19678
			"   for (int i = 0; i < 10; i++)\n" +
19679
			"       ret\n" +
19680
			"	}\n" +
19681
			"}\n" +
19682
			"}\n");
19683
			
19684
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19685
	String str = this.workingCopies[0].getSource();
19686
	String completeBehind = "ret";
19687
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19688
19689
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19690
	assertResults(
19691
			"return[KEYWORD]{return, null, null, return, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
19692
			requestor.getResults());
19693
}
19694
19695
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19696
public void test269493c() throws JavaModelException {
19697
	this.workingCopies = new ICompilationUnit[1];
19698
	this.workingCopies[0] = getWorkingCopy(
19699
			"/Completion/src/test/Test269493.java",
19700
			"package test;" +
19701
			"public class Test269493 {\n" +
19702
			"	void foo() {\n" +
19703
			"   for (int i = 0; i < 10; i++)\n" +
19704
			"       bre\n" +
19705
			"	}\n" +
19706
			"}\n" +
19707
			"}\n");
19708
			
19709
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19710
	String str = this.workingCopies[0].getSource();
19711
	String completeBehind = "bre";
19712
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19713
19714
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19715
	assertResults(
19716
			"break[KEYWORD]{break, null, null, break, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
19717
			requestor.getResults());
19718
}
19719
19720
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19721
public void test269493d() throws JavaModelException {
19722
	this.workingCopies = new ICompilationUnit[1];
19723
	this.workingCopies[0] = getWorkingCopy(
19724
			"/Completion/src/test/Test269493.java",
19725
			"package test;" +
19726
			"public class Test269493 {\n" +
19727
			"	void foo() {\n" +
19728
			"   for (int i = 0; i < 10; i++)\n" +
19729
			"       cont\n" +
19730
			"	}\n" +
19731
			"}\n" +
19732
			"}\n");
19733
			
19734
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19735
	String str = this.workingCopies[0].getSource();
19736
	String completeBehind = "cont";
19737
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19738
19739
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19740
	assertResults(
19741
			"continue[KEYWORD]{continue, null, null, continue, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
19742
			requestor.getResults());
19743
}
19744
19745
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19746
public void test269493e() throws JavaModelException {
19747
	this.workingCopies = new ICompilationUnit[1];
19748
	this.workingCopies[0] = getWorkingCopy(
19749
			"/Completion/src/test/Test269493.java",
19750
			"package test;" +
19751
			"public class Test269493 {\n" +
19752
			"	int foo(int p) {\n" +
19753
			"       if (p == 0)\n" +
19754
			"           return 0;\n" +
19755
			"       else\n" +
19756
			"           ret\n" +
19757
			"	}\n" +
19758
			"}\n" +
19759
			"}\n");
19760
			
19761
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19762
	String str = this.workingCopies[0].getSource();
19763
	String completeBehind = "ret";
19764
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19765
19766
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19767
	assertResults(
19768
			"return[KEYWORD]{return, null, null, return, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
19769
			requestor.getResults());
19770
}
19771
19772
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19773
public void test269493f() throws JavaModelException {
19774
	this.workingCopies = new ICompilationUnit[1];
19775
	this.workingCopies[0] = getWorkingCopy(
19776
			"/Completion/src/test/Test269493.java",
19777
			"package test;" +
19778
			"public class Test269493 {\n" +
19779
			"	int foo(int p) {\n" +
19780
			"       if (p == 0)\n" +
19781
			"           return 0;\n" +
19782
			"       els\n" +
19783
			"	}\n" +
19784
			"}\n" +
19785
			"}\n");
19786
			
19787
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19788
	String str = this.workingCopies[0].getSource();
19789
	String completeBehind = "els";
19790
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19791
19792
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19793
	assertResults(
19794
			"else[KEYWORD]{else, null, null, else, " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_RESTRICTED) + "}",
19795
			requestor.getResults());
19796
}
19797
19798
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19799
public void test269493g() throws JavaModelException {
19800
	this.workingCopies = new ICompilationUnit[1];
19801
	this.workingCopies[0] = getWorkingCopy(
19802
			"/Completion/src/test/Test269493.java",
19803
			"package test;" +
19804
			"public class Test269493 {\n" +
19805
			"	int foo(int p) {\n" +
19806
			"       els\n" +
19807
			"	}\n" +
19808
			"}\n" +
19809
			"}\n");
19810
			
19811
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19812
	String str = this.workingCopies[0].getSource();
19813
	String completeBehind = "els";
19814
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19815
19816
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19817
	assertResults(
19818
			"",
19819
			requestor.getResults());
19820
}
19821
19822
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19823
public void test269493h() throws JavaModelException {
19824
	this.workingCopies = new ICompilationUnit[1];
19825
	this.workingCopies[0] = getWorkingCopy(
19826
			"/Completion/src/test/Test269493.java",
19827
			"package test;" +
19828
			"public class Test269493 {\n" +
19829
			"	int foo(int p) {\n" +
19830
			"       if (p == 0)\n" +
19831
			"           return 0;\n" +
19832
			"       else\n" +
19833
			"           els\n" +
19834
			"	}\n" +
19835
			"}\n" +
19836
			"}\n");
19837
			
19838
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19839
	String str = this.workingCopies[0].getSource();
19840
	String completeBehind = "els";
19841
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19842
19843
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19844
	assertResults(
19845
			"",
19846
			requestor.getResults());
19847
}
19848
19849
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for loop without block
19850
public void test269493i() throws JavaModelException {
19851
	this.workingCopies = new ICompilationUnit[1];
19852
	this.workingCopies[0] = getWorkingCopy(
19853
			"/Completion/src/test/Test269493.java",
19854
			"package test;" +
19855
			"public class Test269493 {\n" +
19856
			"	int foo(int p) {\n" +
19857
			"       if (p == 0) {\n" +
19858
			"           return 0;\n" +
19859
			"       }\n" +
19860
			"       else\n" +
19861
			"           els\n" +
19862
			"	}\n" +
19863
			"}\n" +
19864
			"}\n");
19865
			
19866
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
19867
	String str = this.workingCopies[0].getSource();
19868
	String completeBehind = "els";
19869
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
19870
19871
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
19872
	assertResults(
19873
			"",
19874
			requestor.getResults());
19875
}
19876
19630
}
19877
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-2 / +10 lines)
Lines 3595-3600 Link Here
3595
				if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_CONTROL_STATEMENT_DELIMITER) {
3595
				if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_CONTROL_STATEMENT_DELIMITER) {
3596
					popElement(K_CONTROL_STATEMENT_DELIMITER);
3596
					popElement(K_CONTROL_STATEMENT_DELIMITER);
3597
				}
3597
				}
3598
				pushOnElementStack(K_CONTROL_STATEMENT_DELIMITER);
3598
				break;
3599
				break;
3599
			case TokenNamewhile:
3600
			case TokenNamewhile:
3600
				pushOnElementStack(K_BETWEEN_WHILE_AND_RIGHT_PAREN, this.bracketDepth);
3601
				pushOnElementStack(K_BETWEEN_WHILE_AND_RIGHT_PAREN, this.bracketDepth);
Lines 4013-4020 Link Here
4013
				keywords[count++]= Keywords.THIS;
4014
				keywords[count++]= Keywords.THIS;
4014
			}
4015
			}
4015
			keywords[count++]= Keywords.NEW;
4016
			keywords[count++]= Keywords.NEW;
4016
4017
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=269493: Keywords are not proposed in a for
4017
			if(kind == K_BLOCK_DELIMITER) {
4018
			// loop without block. Completion while at K_CONTROL_STATEMENT_DELIMITER case needs to handled
4019
			// similar to the K_BLOCK_DELIMITER with minor differences.
4020
			if(kind == K_BLOCK_DELIMITER || kind == K_CONTROL_STATEMENT_DELIMITER) {
4018
				if(this.canBeExplicitConstructor == YES) {
4021
				if(this.canBeExplicitConstructor == YES) {
4019
					canBeExplicitConstructorCall = true;
4022
					canBeExplicitConstructorCall = true;
4020
				}
4023
				}
Lines 4044-4049 Link Here
4044
							keywords[count++]= Keywords.FINALLY;
4047
							keywords[count++]= Keywords.FINALLY;
4045
							break;
4048
							break;
4046
					}
4049
					}
4050
				} else if(this.previousKind == K_CONTROL_STATEMENT_DELIMITER && this.previousInfo == IF) {
4051
					keywords[count++]= Keywords.ELSE;
4047
				}
4052
				}
4048
				if(isInsideLoop()) {
4053
				if(isInsideLoop()) {
4049
					keywords[count++]= Keywords.CONTINUE;
4054
					keywords[count++]= Keywords.CONTINUE;
Lines 4341-4346 Link Here
4341
			case K_FIELD_INITIALIZER_DELIMITER : return false;
4346
			case K_FIELD_INITIALIZER_DELIMITER : return false;
4342
			case K_SWITCH_LABEL : return true;
4347
			case K_SWITCH_LABEL : return true;
4343
			case K_BLOCK_DELIMITER :
4348
			case K_BLOCK_DELIMITER :
4349
			case K_CONTROL_STATEMENT_DELIMITER:
4344
				switch(this.elementInfoStack[i]) {
4350
				switch(this.elementInfoStack[i]) {
4345
					case FOR :
4351
					case FOR :
4346
					case DO :
4352
					case DO :
Lines 4360-4365 Link Here
4360
			case K_METHOD_DELIMITER : return false;
4366
			case K_METHOD_DELIMITER : return false;
4361
			case K_FIELD_INITIALIZER_DELIMITER : return false;
4367
			case K_FIELD_INITIALIZER_DELIMITER : return false;
4362
			case K_BLOCK_DELIMITER :
4368
			case K_BLOCK_DELIMITER :
4369
			case K_CONTROL_STATEMENT_DELIMITER:
4363
				switch(this.elementInfoStack[i]) {
4370
				switch(this.elementInfoStack[i]) {
4364
					case FOR :
4371
					case FOR :
4365
					case DO :
4372
					case DO :
Lines 4379-4384 Link Here
4379
			case K_METHOD_DELIMITER : return false;
4386
			case K_METHOD_DELIMITER : return false;
4380
			case K_FIELD_INITIALIZER_DELIMITER : return false;
4387
			case K_FIELD_INITIALIZER_DELIMITER : return false;
4381
			case K_BLOCK_DELIMITER : return false;
4388
			case K_BLOCK_DELIMITER : return false;
4389
			case K_CONTROL_STATEMENT_DELIMITER: return false; // FWIW
4382
			case K_INSIDE_RETURN_STATEMENT : return true;
4390
			case K_INSIDE_RETURN_STATEMENT : return true;
4383
		}
4391
		}
4384
		i--;
4392
		i--;

Return to bug 269493