Bug 68710

Summary: Open Declaration opens wrong target
Product: [Eclipse Project] JDT Reporter: Nico Seessle <nico>
Component: CoreAssignee: David Audel <david_audel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 3.0   
Target Milestone: 3.1 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Nico Seessle CLA 2004-06-27 15:23:58 EDT
In the following code

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class Test {
    public void foo() {
        final JTable table = new JTable();
        table.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() { // <-- (2)
                    public void valueChanged(ListSelectionEvent arg0) {
                    }
                });
        table.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                JPopupMenu popup = getPopup(); // <-- (1)
            }

            private JPopupMenu getPopup() {
                return null;
            }
        });
    }
}

If you select the call to "getPopup()" on the line marked (1) and select "Open
Declaration" from the context menu (or press F3, or Ctrl-Click) the editor
positions on ListSelectionListener on the line marked (2).
Comment 1 Dani Megert CLA 2004-07-06 10:19:27 EDT
Looks like a model bug: also source and hover are wrong probably because
codeSelect returns the wrong element.
Comment 2 David Audel CLA 2004-10-29 05:33:45 EDT
Problem is multiple consecutive anonymous classes. SelectionParser build only a
partial AST but to build a JavaElement, all anonymous type are needed to compute
the correct occurence count.

Fixed and test added
  ResolveTest#testResolveLocalClass7()
  ResolveTest#testResolveLocalField2()
  ResolveTest#testResolveLocalMethod2()
  ResolveTest#testResolveLocalVariable()

CompilationUnit#getElementAt() and ClassFile#getElementAtConsideringSibling()
are used instead of HandleFactory.
Comment 3 Frederic Fusier CLA 2004-11-02 10:58:32 EST
Verified for 3.1 M3 with build I200411020800 + org.eclipse.jdt.core v_517.