### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java,v retrieving revision 1.115 diff -u -r1.115 CompletionTests_1_5.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java 28 Apr 2009 17:46:11 -0000 1.115 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests_1_5.java 13 May 2009 08:24:23 -0000 @@ -13744,5 +13744,91 @@ (R_RESOLVED + R_INTERESTING + R_EXACT_EXPECTED_TYPE + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", requestor.getResults()); } +//bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=274466 +//Check for boolean methods with higher relevance in assert statements +public void test274466() throws JavaModelException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test274466.java", + "package test;" + + "public class Test274466 {\n" + + " boolean methodReturningBoolean() { return true; }\n" + + " Boolean methodReturningBooleanB() { return true; }\n" + + " void methodReturningBlah() { return; }\n" + + " int foo(int p) {\n" + + " assert methodR : \"Exception Message\";" + + " }\n" + + "}\n"); + this.workingCopies[1] = getWorkingCopy( + "/Completion/src3/java/lang/Test.java", + "package java.lang;\n" + + "public class Boolean {\n" + + "}"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "methodR"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "methodReturningBlah[METHOD_REF]{methodReturningBlah(), Ltest.Test274466;, ()V, methodReturningBlah, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + + "methodReturningBooleanB[METHOD_REF]{methodReturningBooleanB(), Ltest.Test274466;, ()Ljava.lang.Boolean;, methodReturningBooleanB, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningBoolean[METHOD_REF]{methodReturningBoolean(), Ltest.Test274466;, ()Z, methodReturningBoolean, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}", + requestor.getResults()); +} +public void test274466a() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Completion/src/test/Test274466.java", + "package test;" + + "public class Test274466 {\n" + + " boolean methodReturningBoolean() { return true; }\n" + + " String methodReturningString() { return \"\"; }\n" + + " byte methodReturningByte() { return 0; }\n" + + " short methodReturningShort() { return 0; }\n" + + " int methodReturningInt() { return 0; }\n" + + " long methodReturningLong() { return 0; }\n" + + " float methodReturningFloat() { return 0; }\n" + + " double methodReturningDouble() { return 0; }\n" + + " char methodReturningChar() { return ' '; }\n" + + " void methodReturningBlah() { return; }\n" + + " int foo(int p) {\n" + + " assert methodReturningBoolean() : methodR" + + " }\n" + + "}\n"); + + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); + String str = this.workingCopies[0].getSource(); + String completeBehind = "methodR"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner); + assertResults( + "methodReturningBlah[METHOD_REF]{methodReturningBlah(), Ltest.Test274466;, ()V, methodReturningBlah, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}\n" + + "methodReturningString[METHOD_REF]{methodReturningString(), Ltest.Test274466;, ()Ljava.lang.String;, methodReturningString, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningBoolean[METHOD_REF]{methodReturningBoolean(), Ltest.Test274466;, ()Z, methodReturningBoolean, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningByte[METHOD_REF]{methodReturningByte(), Ltest.Test274466;, ()B, methodReturningByte, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningChar[METHOD_REF]{methodReturningChar(), Ltest.Test274466;, ()C, methodReturningChar, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningDouble[METHOD_REF]{methodReturningDouble(), Ltest.Test274466;, ()D, methodReturningDouble, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningFloat[METHOD_REF]{methodReturningFloat(), Ltest.Test274466;, ()F, methodReturningFloat, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningInt[METHOD_REF]{methodReturningInt(), Ltest.Test274466;, ()I, methodReturningInt, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningLong[METHOD_REF]{methodReturningLong(), Ltest.Test274466;, ()J, methodReturningLong, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}\n" + + "methodReturningShort[METHOD_REF]{methodReturningShort(), Ltest.Test274466;, ()S, methodReturningShort, " + + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_EXACT_EXPECTED_TYPE + R_NON_RESTRICTED) + "}", + requestor.getResults()); +} } #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.395 diff -u -r1.395 CompletionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 27 Apr 2009 09:38:22 -0000 1.395 +++ codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java 13 May 2009 08:24:29 -0000 @@ -3630,6 +3630,25 @@ addExpectedType(TypeBinding.BOOLEAN, scope); } else if (parent instanceof IfStatement) { addExpectedType(TypeBinding.BOOLEAN, scope); + } + else if (parent instanceof AssertStatement) { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=274466 + // If the exceptionArugument is null, then the assistNode is the conditional part of the assert statement + AssertStatement assertStatement = (AssertStatement) parent; + if (assertStatement.assertExpression == node) { + addExpectedType(TypeBinding.BOOLEAN, scope); + } else { + // The message node accepts all non void types + addExpectedType(TypeBinding.SHORT, scope); + addExpectedType(TypeBinding.INT, scope); + addExpectedType(TypeBinding.LONG, scope); + addExpectedType(TypeBinding.FLOAT, scope); + addExpectedType(TypeBinding.DOUBLE, scope); + addExpectedType(TypeBinding.CHAR, scope); + addExpectedType(TypeBinding.BYTE, scope); + addExpectedType(TypeBinding.BOOLEAN, scope); + addExpectedType(scope.getJavaLangObject(), scope); + } } else if (parent instanceof ForStatement) { // astNodeParent set to ForStatement only for the condition addExpectedType(TypeBinding.BOOLEAN, scope);