Bug 247757 - [model] Move a class to root package, lose block comment at the top
Summary: [model] Move a class to root package, lose block comment at the top
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-17 19:09 EDT by Allan Pratt CLA
Modified: 2008-10-27 15:34 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix and regression tests (8.85 KB, patch)
2008-09-24 12:41 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Allan Pratt CLA 2008-09-17 19:09:54 EDT
JDT will delete a block comment at the top of a class file if you drag the file from a named package to the root package.

Undo did not undo the move or restore the block comment.

STEPS TO REPRODUCE:

1. Create a project where source files are in a "src" directory.
2. Create a class LogToy in a package like com.spumco.
3. Write a block comment at the top of the file, above the "package" line that was placed in the file by the "New > Class" wizard. Start the block comment with "/*" on one line. Add more lines that start with "*" and end with "*/"
4. Save the file.
5. In the Package view, drag the class from the com.spumco package to the src directory (the root package).

JDT will automatically remove the "package" line from the source file.

It will ALSO DELETE THE BLOCK COMMENT. It's just gone. Very rude.
Comment 1 Allan Pratt CLA 2008-09-17 19:12:11 EDT
Sorry, I misspoke. "Undo" did undo the move, but did not restore the deleted block comment.

(Also, in the first sentence of the description I should have referred to dragging the CLASS from the package it's in to the root package, not the FILE.)
Comment 2 Jerome Lanneluc CLA 2008-09-19 06:21:22 EDT
I guess removing or leaving the block comment depends on its content. If the block comment is:
/*
 * This class belongs to package com.spumco
 */
package com.spumco;

then it makes sense to remove it.

If the block comment is:

/*
 * Copyright SomeCompany 2008
 */
package com.spumco;

then we would want to keep it.

Note that the former behavior exists since Eclipse 1.0. The rational being that the block comment is associated with the package declaration. So it would be hard to change it.

So this would need a preference.
Comment 3 Allan Pratt CLA 2008-09-19 12:51:04 EDT
Is deleting the comment EVER the right answer? How often does a block comment at the top of a class file contain NOTHING besides the (almost useless) statement telling what package the class is in?

Comments are like pearls: good ones are rare and some are highly valuable. The best ones represent a substantial investment of effort on the part of the creator, and it's a pleasant surprise when you find them. Let's not crush the ones at the tops of class files based on the assumption that they're "probably worthless." Even with a preference.

Maybe this: scan the entire source file for the (old) package name in comments, and if it appears, remind the user to examine those comments and update appropriately.

Or this: scan for the old package+class name in comments and offer to change it to the new package+class name. It's not safe to do this on the package name alone in a comment (without the class name), because the comment could be referring to the things that are still in the old package. Since the root package doesn't have a name, it would also put us in the awkward position of replacing a package-name string with nothing.

But deleting an entire comment? No. Refactoring always requires attention to comments, and deleting comments should never be the answer.
Comment 4 Jerome Lanneluc CLA 2008-09-22 05:45:00 EDT
That makes sense. I'll see if I have time to fix that. Or if you have a patch, that would even be easier.
Comment 5 Allan Pratt CLA 2008-09-22 12:48:26 EDT
Sorry, no patch. I'm a user of JDT, not a developer of it. I wouldn't know where to look.

As for finding time ... should I have given this "Critical" severity? It's defined as "crashes, loss of data, severe memory leak" ... and this definitely causes irretrievable data loss. (Even if I'm using an SCM, anything I changed in that comment since the last checkin is irretrievable.)
Comment 6 Jerome Lanneluc CLA 2008-09-24 12:41:14 EDT
Created attachment 113387 [details]
Proposed fix and regression tests
Comment 7 Jerome Lanneluc CLA 2008-09-25 05:02:40 EDT
Fix and tests released for 3.5M3
Comment 8 Olivier Thomann CLA 2008-10-27 15:34:25 EDT
Verified for 3.5M3 using I20081026-2000