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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java (+86 lines)
Lines 13744-13748 Link Here
13744
				(R_RESOLVED + R_INTERESTING + R_EXACT_EXPECTED_TYPE + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
13744
				(R_RESOLVED + R_INTERESTING + R_EXACT_EXPECTED_TYPE + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
13745
			requestor.getResults());	
13745
			requestor.getResults());	
13746
}
13746
}
13747
//bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=274466
13748
//Check for boolean methods with higher relevance in assert statements
13749
public void test274466() throws JavaModelException {
13750
	this.workingCopies = new ICompilationUnit[2];
13751
	this.workingCopies[0] = getWorkingCopy(
13752
			"/Completion/src/test/Test274466.java",
13753
			"package test;" +
13754
			"public class Test274466 {\n" +
13755
			"	boolean methodReturningBoolean() { return true; }\n" +
13756
			"	Boolean methodReturningBooleanB() { return true; }\n" +			
13757
			"   void methodReturningBlah() { return; }\n" +
13758
			"	int foo(int p) {\n" +
13759
			"     assert methodR : \"Exception Message\";" +
13760
			"	}\n" +
13761
			"}\n");
13762
	this.workingCopies[1] = getWorkingCopy(
13763
			"/Completion/src3/java/lang/Test.java",
13764
			"package java.lang;\n" +
13765
			"public class Boolean {\n" +
13766
			"}");
13767
	
13768
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
13769
	String str = this.workingCopies[0].getSource();
13770
	String completeBehind = "methodR";
13771
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
13772
13773
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
13774
	assertResults(
13775
			"methodReturningBlah[METHOD_REF]{methodReturningBlah(), Ltest.Test274466;, ()V, methodReturningBlah, " + 
13776
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" +
13777
			"methodReturningBooleanB[METHOD_REF]{methodReturningBooleanB(), Ltest.Test274466;, ()Ljava.lang.Boolean;, methodReturningBooleanB, " + 
13778
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13779
			"methodReturningBoolean[METHOD_REF]{methodReturningBoolean(), Ltest.Test274466;, ()Z, methodReturningBoolean, " + 
13780
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}",
13781
			requestor.getResults());	
13782
}
13783
public void test274466a() throws JavaModelException {
13784
	this.workingCopies = new ICompilationUnit[1];
13785
	this.workingCopies[0] = getWorkingCopy(
13786
			"/Completion/src/test/Test274466.java",
13787
			"package test;" +
13788
			"public class Test274466 {\n" +
13789
			"	boolean methodReturningBoolean() { return true; }\n" +
13790
			"	String methodReturningString() { return \"\"; }\n" +
13791
			"	byte methodReturningByte() { return 0; }\n" +
13792
			"	short methodReturningShort() { return 0; }\n" +
13793
			"	int methodReturningInt() { return 0; }\n" +
13794
			"	long methodReturningLong() { return 0; }\n" +
13795
			"	float methodReturningFloat() { return 0; }\n" +
13796
			"	double methodReturningDouble() { return 0; }\n" +
13797
			"	char methodReturningChar() { return ' '; }\n" +			
13798
			"   void methodReturningBlah() { return; }\n" +
13799
			"	int foo(int p) {\n" +
13800
			"     assert methodReturningBoolean() : methodR" +
13801
			"	}\n" +
13802
			"}\n");
13803
		
13804
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
13805
	String str = this.workingCopies[0].getSource();
13806
	String completeBehind = "methodR";
13807
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
13808
13809
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
13810
	assertResults(
13811
			"methodReturningBlah[METHOD_REF]{methodReturningBlah(), Ltest.Test274466;, ()V, methodReturningBlah, " + 
13812
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" +
13813
			"methodReturningString[METHOD_REF]{methodReturningString(), Ltest.Test274466;, ()Ljava.lang.String;, methodReturningString, " + 
13814
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13815
			"methodReturningBoolean[METHOD_REF]{methodReturningBoolean(), Ltest.Test274466;, ()Z, methodReturningBoolean, " + 
13816
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13817
			"methodReturningByte[METHOD_REF]{methodReturningByte(), Ltest.Test274466;, ()B, methodReturningByte, " + 
13818
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13819
			"methodReturningChar[METHOD_REF]{methodReturningChar(), Ltest.Test274466;, ()C, methodReturningChar, " + 
13820
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13821
			"methodReturningDouble[METHOD_REF]{methodReturningDouble(), Ltest.Test274466;, ()D, methodReturningDouble, " + 
13822
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13823
			"methodReturningFloat[METHOD_REF]{methodReturningFloat(), Ltest.Test274466;, ()F, methodReturningFloat, " + 
13824
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13825
			"methodReturningInt[METHOD_REF]{methodReturningInt(), Ltest.Test274466;, ()I, methodReturningInt, " + 
13826
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13827
			"methodReturningLong[METHOD_REF]{methodReturningLong(), Ltest.Test274466;, ()J, methodReturningLong, " + 
13828
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" +
13829
			"methodReturningShort[METHOD_REF]{methodReturningShort(), Ltest.Test274466;, ()S, methodReturningShort, " + 
13830
					(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}",
13831
			requestor.getResults());	
13832
}
13747
13833
13748
}
13834
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (+19 lines)
Lines 3630-3635 Link Here
3630
			addExpectedType(TypeBinding.BOOLEAN, scope);
3630
			addExpectedType(TypeBinding.BOOLEAN, scope);
3631
		} else if (parent instanceof IfStatement) {  
3631
		} else if (parent instanceof IfStatement) {  
3632
			addExpectedType(TypeBinding.BOOLEAN, scope);
3632
			addExpectedType(TypeBinding.BOOLEAN, scope);
3633
		}
3634
		else if (parent instanceof AssertStatement) {
3635
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=274466
3636
			// If the exceptionArugument is null, then the assistNode is the conditional part of the assert statement
3637
			AssertStatement assertStatement = (AssertStatement) parent;
3638
			if (assertStatement.assertExpression == node) {
3639
				addExpectedType(TypeBinding.BOOLEAN, scope);
3640
			} else {
3641
				// The message node accepts all non void types
3642
				addExpectedType(TypeBinding.SHORT, scope);
3643
				addExpectedType(TypeBinding.INT, scope);
3644
				addExpectedType(TypeBinding.LONG, scope);
3645
				addExpectedType(TypeBinding.FLOAT, scope);
3646
				addExpectedType(TypeBinding.DOUBLE, scope);
3647
				addExpectedType(TypeBinding.CHAR, scope);
3648
				addExpectedType(TypeBinding.BYTE, scope);
3649
				addExpectedType(TypeBinding.BOOLEAN, scope);
3650
				addExpectedType(scope.getJavaLangObject(), scope);
3651
			}
3633
		} else if (parent instanceof ForStatement) {   // astNodeParent set to ForStatement only for the condition  
3652
		} else if (parent instanceof ForStatement) {   // astNodeParent set to ForStatement only for the condition  
3634
			addExpectedType(TypeBinding.BOOLEAN, scope);
3653
			addExpectedType(TypeBinding.BOOLEAN, scope);
3635
3654

Return to bug 274466