Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 337368

Summary: Context's expected type does not consider method return
Product: z_Archived Reporter: Stefan Henss <stefan.henss>
Component: RecommendersAssignee: Marcel Bruch <marcel.bruch>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Stefan Henss CLA 2011-02-16 16:43:22 EST
public String completionOnReturn() {
    Button b = new Button(null, 0);
    return b.<^Space>;
}

IntelligentCompletionContext.getExpectedType() gives null in this occasion.
Comment 1 Marcel Bruch CLA 2011-02-18 13:19:15 EST
Added logic to handle completion on method returns. Could you please check with latest head and update this status to reopen or verify?
Comment 2 Stefan Henss CLA 2011-02-19 22:45:38 EST
getExpectedType() works for me, thanks.

I'm reopening this issue for two reasons:

- This might be a bug: context.expectsReturnValue() is still "false" in the given code example, but getExpectedType() works, as mentioned.

- To discuss: Should we always disable templates completion when a return type is expected? One-liners would not make much sense, I guess. Here the user should go with the other proposals. But what about verifying that the last method in a pattern is returning this value and placing the whole pattern in front of the return? For example:

Button b = new Button(null, 0);
return b.<^Space>;

---->

Button b = new Button(null, 0);
b.doThis();
b.doThat();
return b.getText();
Comment 3 Marcel Bruch CLA 2011-02-20 03:55:36 EST
(In reply to comment #2)

> - This might be a bug: context.expectsReturnValue() is still "false" in the
> given code example, but getExpectedType() works, as mentioned.

Agreed. Fixed in master.

> - To discuss: Should we always disable templates completion when a return type
> is expected?
[...]
> 
> Button b = new Button(null, 0);
> return b.<^Space>;
> 
> ---->
> 
> Button b = new Button(null, 0);
> b.doThis();
> b.doThat();
> return b.getText();

Frankly, I think this is by far more than I would expect as a developer because it gets quite challenging if more than one local may be returned (you may have to pick one of two string values for instance). I wouldn't implement this.

In addition I think, one-liners are handled by standard completion quite well and in the case we have a series of calls to execute we  have chain completion now. I'm good w/o having  this very advanced completion feature.

Setting to fixed again and waiting for your verification.
Comment 4 Marcel Bruch CLA 2012-02-02 01:41:31 EST
Closing this issue. Please give latest dev build (v0.5) a try:

http://download.eclipse.org/recommenders/updates/dev/e37/
http://download.eclipse.org/recommenders/updates/dev/e42/
Comment 5 Marcel Bruch CLA 2012-02-02 01:41:52 EST
Closing this issue. Please give latest dev build (v0.5) a try:

http://download.eclipse.org/recommenders/updates/dev/e37/
http://download.eclipse.org/recommenders/updates/dev/e42/