Bug 132679 - [assist] Completion fails within non-static anonymous inner class
Summary: [assist] Completion fails within non-static anonymous inner class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 RC1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 132703 274020 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-21 09:47 EST by Barry Kaplan CLA
Modified: 2009-05-14 11:29 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (142.74 KB, patch)
2009-05-06 09:42 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Barry Kaplan CLA 2006-03-21 09:47:26 EST
In the code snippet below, ctrl-space expansion fails at the comment. 
The code compiles and runs correctly.

public class Context {

  private int value = 10;

  public abstract class Callback {
      public abstract void doit(int value) {}
  }
}

public class ContextTest {

  private Context context = new Context();

  public void test() {
    context.new Callback() {
      public void doit(int value) {
        Set foo = new HashSet();

        foo. // expansion fails here with message in status bar:
             //   "Callback cannot be resolved to a type"  
      }
    }
  }

}
Comment 1 Markus Keller CLA 2006-03-21 11:48:30 EST
*** Bug 132703 has been marked as a duplicate of this bug. ***
Comment 2 Markus Keller CLA 2006-03-21 11:54:27 EST
The code does not really compile. But I can reproduce even with the obvious fixes applied (abstract method has no body, add imports, add missing ";").
Comment 3 Barry Kaplan CLA 2006-03-21 19:31:05 EST
Another item on this. I also have a non-inner abstract class called Callback in the same package as the Context.

If I control-click/open-declaration on the Callback from within ContextTest, the outer Callback class is opened instead of the inner Callback class.
Comment 4 David Audel CLA 2009-04-17 10:49:24 EDT
I do not reproduce the bug in I20090407-1430.

I close this bug as WORKSFORME.
Comment 5 Srikanth Sankaran CLA 2009-04-28 08:24:16 EDT
Version: 3.5.0
Build id: I20090428-0100

I can reproduce the problem by fixing the compile errors (delete
abstract method body, add imports, fix semicolon etc)

Here is a simpler test case you can paste into the explorer:

import java.util.HashSet;
import java.util.Set;

class Context {

  private int value = 10;

  public abstract class Callback {
      public abstract void doit(int value);
  }
}

public class ContextTest {

  private Context context = new Context();

  public void test() {
	  Set foo = new HashSet();
	  // completion works here after "foo."
      context.new Callback() {
      public void doit(int value) {
        Set foo = new HashSet();
        // completion does not work here after "foo."
       
      }
    };
  }

}

Comment 6 David Audel CLA 2009-04-28 08:54:57 EDT
I also reproduce the problem now. I probably do not use the right test case before.
Comment 7 David Audel CLA 2009-05-06 09:42:40 EDT
Created attachment 134615 [details]
Proposed patch

The problem is in recovery and not only in completion.

The receiver of the anonymous must be attached earlier to the allocation expression to be taken into account by the recovery.

This patch modify the grammar so parser files must be generated
Comment 8 Olivier Thomann CLA 2009-05-06 10:29:52 EDT
+1. Patch looks good.
Comment 9 David Audel CLA 2009-05-07 04:49:13 EDT
Released for 3.5RC1.

Tests added
  DietRecoveryTest#test126()
  CompletionTests#testBug132679()
Comment 10 David Audel CLA 2009-05-07 04:49:54 EDT
*** Bug 274020 has been marked as a duplicate of this bug. ***
Comment 11 Olivier Thomann CLA 2009-05-14 11:29:13 EDT
Verified for 3.5RC1 using I20090511-2000.