Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 337077

Summary: [move member type] Move Type to New File ignores code template when inner class has class level comments
Product: [Eclipse Project] JDT Reporter: Troy <troy>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: deepakazad, Olivier_Thomann
Version: 3.7   
Target Milestone: 3.7 M6   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Fix & tests none

Description Troy CLA 2011-02-13 14:58:09 EST
Build Identifier: Build id: 20100917-0705

If I have an inner-class and it has javadoc in it. I select the inner class, go to Refactor, Move Type to New File, and the new file is created. Looking at the new file though, you'll see that the code template for Comments -> Files is ignored, and my document starts immediately with the package declaration

Reproducible: Always

Steps to Reproduce:
1. Go to Window | Preferences, Java\Code Style\Code Templates.
2. Define a pattern for Comments\Files
3. Create a class containing an inner class. Be sure to create a comment at the class level for the inner class.
E.g.

/**
 * Hello World
 *
 */
public class Foo
{
  /**
   * Goodbye World
   */
  public static class Bar
  {
  }
}

4. Select the inner class element, and go to Refactor | Move Type to New File. Have a look at the new file. It's missing your file comment at the beginning of the file prior to package declaration.
5. Undo your refactor
6. Remove the comment for Bar. Try refactoring again. This time Bar will have the proper file level comment prior to the package declaration.

I haven't gone as far as checking other code template stuff, but perhaps there's problems with other templates too?
Comment 1 Olivier Thomann CLA 2011-02-13 15:49:15 EST
Move to JDT/UI
Comment 2 Deepak Azad CLA 2011-02-13 22:57:03 EST
To reproduce, make sure to enable "Automatically add comments for new methods and types" on the code template preference page.
Comment 3 Markus Keller CLA 2011-02-14 11:24:46 EST
Created attachment 188910 [details]
Fix & tests
Comment 4 Markus Keller CLA 2011-02-14 11:26:49 EST
Fixed in HEAD.