Bug 32061 - No code assist in instance variable inner class
Summary: No code assist in instance variable inner class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-17 15:42 EST by Jared Burns CLA
Modified: 2004-05-18 10:58 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jared Burns CLA 2003-02-17 15:42:28 EST
Build 20030214

I get no code assist in the context of an inner class created in an instance
variable declaration. My specific test case is trying to create a single
inner class that can be reused by multiple widgets as a selection listener.

So I have:
private SelectionAdapter buttonListener= new SelectionAdapter() {
  public void widgetSelected(SelectionEvent event) {
    if (event.widget == addButton) {
      addProperty();
    } else if (event.widget == editButton) {
      edit();
    }
  }
}

If I try to get code assist to see the fields/methods on event, for example,
I get nothing.
Comment 1 Dirk Baeumer CLA 2003-02-18 03:59:14 EST
Jared this works for me using the following example:

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class X {
	private SelectionAdapter buttonListener= new SelectionAdapter() {
	  public void widgetSelected(SelectionEvent event) {
		if (event.widget == null) {
		  // addProperty();
		} else if (event.widget == null) {
		  // edit();
		}
	  }
	};
}

Any additional steps to reproduce this ?

Philippe, anything you can think of that can cause this behaviour.
Comment 2 David Audel CLA 2003-02-19 07:36:09 EST
I cannot reproduce the problem with your test case.

Jared - Could you give me all the source of the compilation unit where the 
problem occur ?
Comment 3 Dominic Seymour CLA 2003-04-29 07:48:09 EDT
Build 200303272130, jdk 1.4.1_02, win32.

I just came across this bug while writing Swing code. The example code below 
is the minimum required to reproduce the problem for me. The bug shows up when 
you create an anonymous inner class in an instance variable declaration AFTER 
a method containing both an anonymous inner class declaration AND a method 
call. 

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.Action;
import javax.swing.JButton;

public class CodeCompletionBug  {

    private JButton button = new JButton();

    // The anonymous class before the constructor class works.
    private Action action1 = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            // Code completion works in here.
        }
    };
    
    public void someInitMethod() {
    
        // Remove this and the broken completion below will work.
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Code completion works in here.  
	    }
        });
        
        // Or remove this.
        someMethod();
        
    }

    // Code completion does not propose constructors after the "new" keyword.
    private Action action2; // = new 

    // Did it manually but completion is broken inside the anonymous class.
    private Action action3 = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            // Code completion does not work in here.
            //e.
        }
    };
    
    private void someMethod() { }

}
Comment 4 David Audel CLA 2004-04-28 07:06:00 EDT
I can reproduce the bug with Dominic test case in build 20040422.

The problem is inside AssistParser#recoveryTokenCheck(). K_TYPE_DELIMITER is 
not correctly remove from the element stack.

Fixed and tests added
   CompletionParserTest2#138()
   CompletionParserTest2#139()
Comment 5 Olivier Thomann CLA 2004-05-18 10:58:57 EDT
Verified in 200405180816.