Bug 75908 - Code Placement for Action Performed
Summary: Code Placement for Action Performed
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: VE (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: VE Bugzilla inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-08 11:07 EDT by Chas Douglass CLA
Modified: 2011-06-13 11:37 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 Chas Douglass CLA 2004-10-08 11:07:33 EDT
The generated code can be placed incorrectly.

Test case:
Create a new visual class like JPanel.  Drop a JCheckbox on the new panel.  It
will look like this:
	private JCheckBox getJCheckBox() {
		if (jCheckBox == null) {
			jCheckBox = new JCheckBox();
		}
		return jCheckBox;
	}
Switch to "source" mode and edit it to look like this:
	private JCheckBox getJCheckBox() {
	    if (jCheckBox == null) {
		jCheckBox = new JCheckBox();
                if (true) {
                    jCheckBox.setSelected(true);
                }
	    }
            return jCheckBox;
	}

Now switch back to "design" mode, right-click on the checkbox and select
"events->actionPerformed".

Switch back to source mode and notice that the new code has been inserted inside
the if-block previously added:

    private JCheckBox getJCheckBox() {
	if (jCheckBox == null) {
	    jCheckBox = new JCheckBox();
            if (true) {
                jCheckBox.setSelected(true);
                jCheckBox.addActionListener(new java.awt.event.ActionListener() { 
                     public void actionPerformed(java.awt.event.ActionEvent e) {    
                	System.out.println("actionPerformed()"); // TODO Auto-generated
Event stub actionPerformed()
                    }
                });
            }
	}
	return jCheckBox;
    }

Correct result:
The inserted code should not be inside any conditional (or looping) blocks
inside the getJCheckBox() method.