Bug 381360 - [1.8][assist] Code completion broken just after default method definition.
Summary: [1.8][assist] Code completion broken just after default method definition.
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: BETA J8   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 380188 402079
  Show dependency tree
 
Reported: 2012-06-01 08:32 EDT by Srikanth Sankaran CLA
Modified: 2013-11-30 19:57 EST (History)
1 user (show)

See Also:


Attachments
sketch (9.80 KB, patch)
2012-07-01 19:08 EDT, Stephan Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2012-06-01 08:32:49 EDT
BETA_JAVA8 top of branch.

Create a 1.8 project (by editing org.eclipse.jdt.core.preferences) and
add the following:

interface I {
  // code completion works here  try completing voi|
  void foo () default { System.out.println(""); }
  // code completion is broken here try completing voi| 
}

As shown in comments above, code completion breaks just after the
definition of default method.
Comment 1 Stephan Herrmann CLA 2012-06-19 14:12:50 EDT
I'd expect similar results for all new syntax elements.

E.g., no proposals here:

ActionListener al = (e) -> System.out.println(e.|);

Instead, we see a syntax error "Syntax error on token "ARROW", invalid AssignmentOperator"

We'll need to check
- recovery in the Parser
- reporting by DiagnoseParser
- adjustments in AssistParser and family.
Comment 2 Srikanth Sankaran CLA 2012-06-20 00:46:23 EDT
Feel free to spawn a fresh bug for comment#1 if early analysis
indicates different locations for fix (likely), Thanks
Comment 3 Stephan Herrmann CLA 2012-06-30 18:49:44 EDT
The problem re default methods is probably related to bug 383973.
Comment 4 Stephan Herrmann CLA 2012-07-01 19:06:20 EDT
With the work from bug 383973 completion was still broken, but I could narrow the issue down to a problem in RecoveredMethod.updateOnClosingBrace() which prematurely returned the grand-parent (the compilation unit), where it should return the parent (type). As a result CompletionParser.checkRecoveredType() did not find the type and thus couldn't propose a type reference proposal, only keyword proposals.

I'll attach the sketch of a patch on top of bug 383973 comment 5, which ensures that upon "void foo() default {stmts;}" we record the opening brace before skipping the block "{stmts;}". I tried using RecoveredMethod.updateOnOpeningBrace() instead of the direct field assignment, but that didn't actually work.

I don't think this is the best location for fixing the issue.
Ayush, perhaps you can use my analysis to find a better solution?
Comment 5 Stephan Herrmann CLA 2012-07-01 19:08:04 EDT
Created attachment 218131 [details]
sketch

This fixes the immediate issue re default methods - but may not be the best strategy.
Comment 6 Ayushman Jain CLA 2012-07-02 01:04:22 EDT
(In reply to comment #4)
> I don't think this is the best location for fixing the issue.
> Ayush, perhaps you can use my analysis to find a better solution?

Thanks Stephan, once the grammar changes are in, I'll see how it can be fixed in RecoveredMethod.updateOnOpeningBrace()
Comment 7 Srikanth Sankaran CLA 2013-02-16 02:55:04 EST
(In reply to comment #6)
> (In reply to comment #4)
> > I don't think this is the best location for fixing the issue.
> > Ayush, perhaps you can use my analysis to find a better solution?
> 
> Thanks Stephan, once the grammar changes are in, I'll see how it can be
> fixed in RecoveredMethod.updateOnOpeningBrace()

Hi Ayush, the grammar changes have been in for a while - do you want to see
how it can be fixed ? :)
Comment 8 Srikanth Sankaran CLA 2013-02-16 02:58:46 EST
(In reply to comment #0)
> BETA_JAVA8 top of branch.
> 
> Create a 1.8 project (by editing org.eclipse.jdt.core.preferences) and
> add the following:
> 
> interface I {
>   // code completion works here  try completing voi|
>   void foo () default { System.out.println(""); }
>   // code completion is broken here try completing voi| 
> }
> 
> As shown in comments above, code completion breaks just after the
> definition of default method.

This works now that the grammar has changed for default methods.
I will close this for now. Code completion and recovery issues
need to be looked at first order projects by themselves in due
course.