Bug 497096 - Field name proposal
Summary: Field name proposal
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 10
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-30 09:47 EDT by Yauheniy Ratkevich CLA
Modified: 2016-07-06 08:19 EDT (History)
4 users (show)

See Also:


Attachments
screenshot (37.51 KB, image/png)
2016-06-30 09:48 EDT, Yauheniy Ratkevich CLA
no flags Details
STEP BY STEP Screenshots (147.88 KB, application/octet-stream)
2016-07-01 14:46 EDT, Yauheniy Ratkevich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yauheniy Ratkevich CLA 2016-06-30 09:47:09 EDT
Eclipse proposes for me class name instead of a field name.


-- Configuration Details --
Product: Eclipse 4.6.0.20160613-1800 (org.eclipse.epp.package.jee.product)
Installed Features:
 org.eclipse.jdt 3.12.0.v20160606-1100
Comment 1 Yauheniy Ratkevich CLA 2016-06-30 09:48:13 EDT
Created attachment 262831 [details]
screenshot

See the screenshot that clarifies everything.
Comment 2 Jay Arthanareeswaran CLA 2016-06-30 09:55:39 EDT
I don't think we ever propose field names, method names or things like that. What you see is just a list of types that are available in this context, not necessarily useful there.

Noopur, can you confirm please?
Comment 3 Noopur Gupta CLA 2016-06-30 10:11:31 EDT
(In reply to Jay Arthanareeswaran from comment #2)
> I don't think we ever propose field names, method names or things like that.
> What you see is just a list of types that are available in this context, not
> necessarily useful there.
> 
> Noopur, can you confirm please?

We propose field names of kind org.eclipse.jdt.core.CompletionProposal.VARIABLE_DECLARATION.

@Yauheniy, can you please provide a standalone example to reproduce the bug?
Comment 4 Yauheniy Ratkevich CLA 2016-06-30 10:42:46 EDT
(In reply to Noopur Gupta from comment #3)
> (In reply to Jay Arthanareeswaran from comment #2)
> > I don't think we ever propose field names, method names or things like that.
> > What you see is just a list of types that are available in this context, not
> > necessarily useful there.
> > 
> > Noopur, can you confirm please?
> 
> We propose field names of kind
> org.eclipse.jdt.core.CompletionProposal.VARIABLE_DECLARATION.
> 
> @Yauheniy, can you please provide a standalone example to reproduce the bug?

What do you mean "standalone"?

Just start typing field declaration:
private MyClass [here something commmon, that spells like any class and press CTRL+SPACE and you will see that it proposes for you class names].

BUT!! If I type it with semicolon - everything works fine! But who will type semicolon first and then field name?
private MyClass ;|
//move your cursor
private MyClass |;
//start typing and press ctrl+space, it works and proposes "myClass/class/etc."


Is it clear for you? Try it yourself and you will understand, what I'm talking about.
Comment 5 Yauheniy Ratkevich CLA 2016-06-30 10:45:20 EDT
(In reply to Noopur Gupta from comment #3)
> (In reply to Jay Arthanareeswaran from comment #2)
> > I don't think we ever propose field names, method names or things like that.
> > What you see is just a list of types that are available in this context, not
> > necessarily useful there.
> > 
> > Noopur, can you confirm please?
> 
> We propose field names of kind
> org.eclipse.jdt.core.CompletionProposal.VARIABLE_DECLARATION.
> 
> @Yauheniy, can you please provide a standalone example to reproduce the bug?

See the screenshot. It should propose for me "localizationService" in this case.

I saw this problem not only in this specific project and even in the previous versions of Eclipse.
Comment 6 Stephan Herrmann CLA 2016-06-30 12:17:48 EDT
Just to second Noopur's request for a "standalone example": when I have this in my editor:

//---
public class FieldCompletion {
	private FieldCompletion |
}
//---

and hit Ctrl+Space I get the to expected proposals "completion" and "fieldCompletion".

So, perhaps s.t. is different in your context, perhaps s.t. at some location of your file which you are not showing. Can you please show an entire file? If that doesn't let us reproduce we will ask about a self-contained project etc. ...
Comment 7 Yauheniy Ratkevich CLA 2016-07-01 14:46:13 EDT
Created attachment 262865 [details]
STEP BY STEP Screenshots
Comment 8 Yauheniy Ratkevich CLA 2016-07-01 14:48:08 EDT
(In reply to Stephan Herrmann from comment #6)
> Just to second Noopur's request for a "standalone example": when I have this
> in my editor:
> 
> //---
> public class FieldCompletion {
> 	private FieldCompletion |
> }
> //---
> 
> and hit Ctrl+Space I get the to expected proposals "completion" and
> "fieldCompletion".
> 
> So, perhaps s.t. is different in your context, perhaps s.t. at some location
> of your file which you are not showing. Can you please show an entire file?
> If that doesn't let us reproduce we will ask about a self-contained project
> etc. ...

See attachments.
It reproduces when you have any method below this field and if you typing without a semicolon.
Comment 9 Stephan Herrmann CLA 2016-07-01 18:40:20 EDT
OK, all it takes to reproduce the problem is this:

//---
public class Main {
	private LinkageError |
	
	@Override
	public String toString() {
		return "";
	}
}
//---

(sreenshots aren't really the best way to share Java code...)


And here's what makes the difference between attachment 262831 [details], comment 6 on the one hand and successful reproduction of the problem on the other hand: *when followed by an annotated method declaration* the incomplete field declaration is somehow understood as part of the subsequent method declaration. To witness: toString() has this error:

The method toString in type Main can only set one of public / protected / private

Now, while the field declaration is incomplete we obviously have a syntax error. Code completion depends on smart recovery at that error. Things work fine even with an unannotated method declaration, only when also adding the annotation, syntax recovery gets confused.

Technically, we seem to end up seeing a list of modifiers:
  private LinkageError @Override public

most of this is *syntactically OK*, only one token, LinkageError, is syntactically wrong, so dropping this single token is the simplest recovery. After such error recovery there is no hint anymore that completion should produce a field name.


I'm not sure if tweaking the heuristics of syntax recovery for this case is feasible. OTOH, the fact that the @Override annotations makes the difference between desired and undesired recovery could give a hint.


Last note: even in the bad case I see only one class name proposed: Main. That is: part of the problem can still not be reproduced just by following the steps. Not sure if this is worth pursuing.
Comment 10 Yauheniy Ratkevich CLA 2016-07-02 08:56:30 EDT
(In reply to Stephan Herrmann from comment #9)
> OK, all it takes to reproduce the problem is this:
> 
> //---
> public class Main {
> 	private LinkageError |
> 	
> 	@Override
> 	public String toString() {
> 		return "";
> 	}
> }
> //---
> 
> (sreenshots aren't really the best way to share Java code...)
> 
> 
> And here's what makes the difference between attachment 262831 [details],
> comment 6 on the one hand and successful reproduction of the problem on the
> other hand: *when followed by an annotated method declaration* the
> incomplete field declaration is somehow understood as part of the subsequent
> method declaration. To witness: toString() has this error:
> 
> The method toString in type Main can only set one of public / protected /
> private
> 
> Now, while the field declaration is incomplete we obviously have a syntax
> error. Code completion depends on smart recovery at that error. Things work
> fine even with an unannotated method declaration, only when also adding the
> annotation, syntax recovery gets confused.
> 
> Technically, we seem to end up seeing a list of modifiers:
>   private LinkageError @Override public
> 
> most of this is *syntactically OK*, only one token, LinkageError, is
> syntactically wrong, so dropping this single token is the simplest recovery.
> After such error recovery there is no hint anymore that completion should
> produce a field name.
> 
> 
> I'm not sure if tweaking the heuristics of syntax recovery for this case is
> feasible. OTOH, the fact that the @Override annotations makes the difference
> between desired and undesired recovery could give a hint.
> 
> 
> Last note: even in the bad case I see only one class name proposed: Main.
> That is: part of the problem can still not be reproduced just by following
> the steps. Not sure if this is worth pursuing.


"sreenshots aren't really the best way to share Java code..." 
I'm sorry, just wanted to show you position of cursor and popup window as is.


Nevertheless it's not the right way to interpret it.
> Technically, we seem to end up seeing a list of modifiers:
>   private LinkageError @Override public

I think if it takes not really much time, it's really a good idea to fix it. This behaviour is unexpeceted. 

BTW: It reproduces also when field is followed by annotated another one.

	private Exception exc| //HERE THE SAME, wrong completion.
	
	@Deprecated
	private LinkageError linkageError;
Comment 11 Stephan Herrmann CLA 2016-07-02 09:30:54 EDT
(In reply to Yauheniy Ratkevich from comment #10)
> Nevertheless it's not the right way to interpret it.
> > Technically, we seem to end up seeing a list of modifiers:
> >   private LinkageError @Override public
> 
> I think if it takes not really much time, it's really a good idea to fix it.
> This behaviour is unexpeceted. 

Let me just note, that this is not the explicit decision of any engineer to interpret the broken syntax as shown. It's the answer from a sophisticated heuristic-based algorithm. Tweaking that algorithm is a very delicate issue, so "if it takes not really much time" is s.t. we cannot know in advance.