Bug 271296 - [assist] void typed proposal may not be appropriate in many contexts
Summary: [assist] void typed proposal may not be appropriate in many contexts
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-06 06:32 EDT by Srikanth Sankaran CLA
Modified: 2010-05-27 17:35 EDT (History)
1 user (show)

See Also:
srikanth_sankaran: review+


Attachments
Proposed patch (44.38 KB, patch)
2009-05-15 02:52 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated Patch (45.85 KB, patch)
2009-06-29 02:11 EDT, Jay Arthanareeswaran CLA
srikanth_sankaran: iplog+
srikanth_sankaran: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2009-04-06 06:32:08 EDT
Version: 3.5.0
Build id: I20090313-0100

1. Create a Java project with the following:

public class C {

        public void Methodaaaa1() {}
        public void Methodaaaa2() {}
        public void Methodaaaa3() {}
        public void Methodaaaa4() {}
        public void Methodaaaa5() {}
        public void Methodaaaa6() {}
        public void Methodaaaa7() {}
        public void Methodaaaa8() {}
        public void Methodaaaa9() {}
        public void Methodaaaa10() {}
        public void Methodaaaa11() {}
        public void Methodaaaa12() {}
        public boolean Methodboolean() { return false;}
        public Boolean Methodboolean2() { return false;}


        public void foo() {
                if (Meth|)
        }

}

2. At the '|' do a <Ctrl-Space> to complete. 

3. You will see that all the void typed proposals appear in the list.
   Should these even be proposed ?

       Perhaps not.

4. See that this is one instance of a context where void types are
   not suitable, not the only one. In general whenever the completion
   engine has a definite notion of expected type, it would appear
   void types should not be proposed.
Comment 1 Srikanth Sankaran CLA 2009-04-20 03:53:21 EDT
See bug# 25876 & bug# 43897. We don't want to eliminate void typed proposals altogether, we may want to diminish their relevance so they are offered below
others.
Comment 2 Srikanth Sankaran CLA 2009-04-27 05:45:11 EDT
Jay, can you take a look at this ? Normally we use the notion of expected type
to boost the relavance of a proposal. In this case, we may want to diminish
the relavance. Thanks.
Comment 3 Jay Arthanareeswaran CLA 2009-05-07 02:34:04 EDT
Consider this test:
public class C {
		void foo00() {}
		void foo01(){}
        String foo0 () {return null;}
        float foo1 () {return 0;}
        int foo2() {return 0;}
        Long foo3() {return null;}
        long foo4() {return 0;}
        Integer foo5() {return 0;}
        
        void test() {
        	foo|
        }
}

On Ctrl+Space, we get all foo methods get the same relevance value and ultimately listed alphabetically.

My question is, if the completion node doesn't have an expected type, should we give higher relevance to void methods?
Comment 4 David Audel CLA 2009-05-07 05:58:16 EDT
In this case I would use the same relevance for all methods because it is not so rare to want to use a method without using the returned value (eg. List.add(Object)).
Comment 5 Jay Arthanareeswaran CLA 2009-05-15 02:52:16 EDT
Created attachment 135919 [details]
Proposed patch

The fix introduces a new relevance for methods returning void values with a value of -5. This way the relevance of such methods get reduced by 5. Test cases have been modified to relflect/test this behavior.
Comment 6 David Audel CLA 2009-05-29 10:01:20 EDT
I looked the patch and i have several suggestions:
- I do not understand why the void check is done in the for loop inside computeRelevanceForExpectingType(). I think it should be done at the beginning of the method with something like:
private int computeRelevanceForExpectingType(TypeBinding proposalType){
	if (proposalType == TypeBinding.VOID) return VOID;
	...


- Before this patch all the relevance constants were positive so there is no risk to compute a negative relevance.
This patch change this rule and add a negative constant.

To limit the risk of a negative relevance when adding a new constant in RelevanceConstants the new rules could be:
	- a relevance is the sum of constants defined in RelevanceConstants 
	- each constant can be added only one time in the relevance of a proposal 
	- the sum of all negative constants and R_DEFAULT must be positive
You should add a comment in RelevanceConstants which explicitly describe these new rules.



We should fix this bug for 3.6 as it is too late for 3.5.
Comment 7 Jay Arthanareeswaran CLA 2009-06-01 06:22:38 EDT
Agree with you on the changes, David. In fact, this change unearthed many more test cases that may have to be changed. And since this is going only for 3.6, I will work on fixing the test cases and submit a new patch after that.
Comment 8 Jay Arthanareeswaran CLA 2009-06-29 02:11:36 EDT
Created attachment 140340 [details]
Updated Patch

Attached the patch with the modifications as per suggestions and modified test cases.
Comment 9 Srikanth Sankaran CLA 2009-07-09 06:49:06 EDT
Released Jay's fix in HEAD for 3.6M1
Comment 10 Frederic Fusier CLA 2009-08-03 12:15:13 EDT
Verified for 3.6M1
Comment 11 Frederic Fusier CLA 2009-08-03 12:17:16 EDT
(In reply to comment #10)
> Verified for 3.6M1
> 
... using I20090802-2000 build