Bug 528380 - No Chain Completions for method arguments in lambda expressions
Summary: No Chain Completions for method arguments in lambda expressions
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Recommenders (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 528482
Blocks:
  Show dependency tree
 
Reported: 2017-12-10 08:40 EST by Gayan Perera CLA
Modified: 2019-07-24 14:37 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gayan Perera CLA 2017-12-10 08:40:46 EST
When trying to use chain proposals for method arguments which are inside lambda expressions the chains proposals are not shown.

In the below example the cursor positions are denoted by | character.

Example:

package test.module;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class TestApp {
	private X x;
	
	private <E> void print(Iterator<E> iterator) {
                // doesn't shows chain proposals
		iterator.forEachRemaining(e -> System.out.println(|)); 

		this.load(|); // shows chain proposals
		System.out.println(|); // shows chain proposals
		List<String> strings = |; // shows chain proposals
	}

	public List<String> findAll() {
		return load(Collections.EMPTY_LIST);
	}

	public List<String> load(List<Long> ids) {
		return null;
	}
	
	private class X {
		public List<String> names;
		public List<Long> ids;
		public String message;
	}

}
Comment 1 Andreas Sewe CLA 2017-12-12 04:24:59 EST
Hi Gayan.

Thanks for the extensive test class. That is really helpful.

However, using Photon M4 (to make sure I use the latest version of Eclipse JDT),  I cannot get chain proposals in even the simple, non-lambda System.out.println(|); case:

> System.out.println(|); // shows chain proposals

This doesn't work for me. Debugging shows that Eclipse's JavaContentAssistInvocationContext.getExpectedType() returns null, i.e., JDT doesn't know what type is expected in this case.

That being said, if I change the lambda to

  iterator.forEachRemaining(e -> this.load(|)); 

then I don't get chain proposals either, even though I get them for the this.load(|) call outside the lambda.

Looks like a JDT problem to me. Will report this upstream.
Comment 2 Andreas Sewe CLA 2017-12-12 04:48:36 EST
(In reply to Andreas Sewe from comment #1)
> Looks like a JDT problem to me. Will report this upstream.

Spoke too soon. While IRecommendersCompletionContext.getExpectedType() indeed finds nothing for System.out.println(|); IRecommendersCompletionContext.getExpectedTypeNames() finds int, boolean, Object, etc. And that is indeed different between the inside-lambda (getExpectedTypeNames() returns null) and outside-lambda cases.

@Gayan: What call chains do you see for System.out.println(|)?
Comment 3 Andreas Sewe CLA 2017-12-12 04:53:11 EST
(In reply to Andreas Sewe from comment #2)
> Spoke too soon. While IRecommendersCompletionContext.getExpectedType()
> indeed finds nothing for System.out.println(|);
> IRecommendersCompletionContext.getExpectedTypeNames() finds int, boolean,
> Object, etc. And that is indeed different between the inside-lambda
> (getExpectedTypeNames() returns null) and outside-lambda cases.

In the outside-lambda case

  System.out.println(|);

is a CompletionOnMessageSend (as our ExpectedTypeNamesContextFunction.isArgumentCompletion(ASTNode) exepcts).

But in the inside-lambda case,

  iterator.forEachRemaining(e -> System.out.println(|)); 

it is a CompletionOnSingleNameReference, which we don't recognize as argument completion.
Comment 4 Andreas Sewe CLA 2017-12-12 05:09:00 EST
@Gayan: Reducing severity to normal. Critical would mean that Code Recommenders becomes almost unusable. Not having chain completion in a few places is far from that.
Comment 5 Gayan Perera CLA 2017-12-12 11:37:30 EST
(In reply to Andreas Sewe from comment #4)
> @Gayan: Reducing severity to normal. Critical would mean that Code
> Recommenders becomes almost unusable. Not having chain completion in a few
> places is far from that.

Yes thats ok with me, I looked a bit inside the code and found the same findings you did. I will debug photon and see why its not working for normal scenario as well.
Comment 6 Andreas Sewe CLA 2017-12-13 03:10:38 EST
(In reply to Gayan Perera from comment #5)
> (In reply to Andreas Sewe from comment #4)
> > @Gayan: Reducing severity to normal. Critical would mean that Code
> > Recommenders becomes almost unusable. Not having chain completion in a few
> > places is far from that.
> 
> Yes thats ok with me, I looked a bit inside the code and found the same
> findings you did. I will debug photon and see why its not working for normal
> scenario as well.

Thanks for the help. If you need any help with building and debugging Code Recommenders beyond [1], please let us know on the recommenders-dev mailing list [2].

[1] <https://git.eclipse.org/c/recommenders/org.eclipse.recommenders.git/about/>
[2] <https://accounts.eclipse.org/mailing-list/recommenders-dev>