Bug 33225 - Override methods... inserts methods incorrectly if class body is as {}
Summary: Override methods... inserts methods incorrectly if class body is as {}
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.1 RC2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-26 06:17 EST by Darshan Shaligram CLA
Modified: 2003-03-10 11:57 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Darshan Shaligram CLA 2003-02-26 06:17:01 EST
I have a class like this:

--cut--
import javax.swing.*;

public class Foo extends AbstractAction
{}
--cut--

If I now use Override Methods... from the Outline view to add the 
actionPerformed() method, I get this result:

--cut--
import java.awt.event.ActionEvent;
import javax.swing.*;

public class DET extends AbstractAction 
	/**
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
	}

{}
--cut--

I'd have expected to see the generated method inside the class' braces.

(The problem is replicable only if the class' braces are as {}, and stand on 
their own line.)
Comment 1 Martin Aeschlimann CLA 2003-02-26 13:04:13 EST
JDT Core IType.createMethod is used
Comment 2 Olivier Thomann CLA 2003-02-26 13:34:52 EST
This is still a problem in 2.1 RC1.
Comment 3 Olivier Thomann CLA 2003-02-26 14:12:47 EST
I might have a fix for this one.
Comment 4 Philipe Mulet CLA 2003-02-27 05:08:14 EST
Ok if not too much risky.
Comment 5 Olivier Thomann CLA 2003-02-27 09:20:06 EST
The problem comes from the normalize method in DOMType.
The test is:
	if (fInsertionPosition < openBodyEnd) {
		fInsertionPosition = getCloseBodyPosition();
	}
instead of:
	if (fInsertionPosition <= openBodyEnd) {
		fInsertionPosition = getCloseBodyPosition();
	}
The reason is that the fInsertion position is inclusive. If it is equal to
openBodyEnd, it means that this is not a good position for insertion. This would
result with the new method outside of the class braces.
Changing < for <= means that in this case the new method is inserted before the
closing brace.
Comment 6 Olivier Thomann CLA 2003-02-27 09:57:06 EST
Fixed and released in 2.1 stream.
Regression tests added.
Comment 7 Olivier Thomann CLA 2003-03-10 11:57:49 EST
Verified.