Bug 88126

Summary: [ast rewrite] Inconsistent results in modifying TagElements
Product: [Eclipse Project] JDT Reporter: Edwin Chan <edwin>
Component: CoreAssignee: Martin Aeschlimann <martinae>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
A plugin to modify Javadoc tags
none
A project to be used as a test case
none
Sample output
none
A project to be used as a test case (restored to how it should start out) none

Description Edwin Chan CLA 2005-03-15 17:27:20 EST
 
Comment 1 Edwin Chan CLA 2005-03-15 17:28:53 EST
Created attachment 18814 [details]
A plugin to modify Javadoc tags

Here's a plugin to demostrate the problem
Comment 2 Edwin Chan CLA 2005-03-15 17:31:14 EST
Created attachment 18815 [details]
A project to be used as a test case

To use the plugin, right-click on the compilation unit (test.Test) in the
project and select "Modify Selected Javadoc Tags" to see what happens.
Comment 3 Edwin Chan CLA 2005-03-15 17:32:05 EST
Created attachment 18816 [details]
Sample output

This is the result I got from running my plugin on the test case.
Comment 4 Edwin Chan CLA 2005-03-15 17:37:59 EST
I wrote some code to modify the Javadoc tags via the Eclipse DOM
(TagElement.setTagName), but it doesn't seem to do what I expected.

I had expected setTagName to replace the existing tag with whatever I set it to.
 However, it doesn't seem to do the right thing if the tag includes '.' or '-',
but it almost does for '_', except for the trailing space.  
Comment 5 Edwin Chan CLA 2005-03-15 17:39:27 EST
Created attachment 18817 [details]
A project to be used as a test case (restored to how it should start out)

Fixed the Javadoc to restore it to how it was before I ran my plugin
Comment 6 Frederic Fusier CLA 2005-03-16 04:40:57 EST
Problem is not in setTagName(String) which works correctly until you include @
in tag name. So, I've modified your rewriter as follow:
  static class JavadocRewriter extends ASTVisitor {
    JavadocRewriter() {
      super(true);
    }
    
    public boolean visit(TagElement n) {
      String tag = n.getTagName();
      if (tag == null) {
        // No tags yet.
      }
      else if (tag.startsWith("@-")) {
        n.setTagName("@DASH");
      }
      else if (tag.startsWith("@.")) {
        n.setTagName("@PERIOD");
      }
      else if (tag.startsWith("@_")) {
        n.setTagName("@UNDERSCORE");
      }
      return true;
    }
  }

Then, setting a breakpoint in Test.rewriteJavadoc(ICompilationUnit) method at line:
      TextEdit te = cu.rewrite(doc, null);
shows that Javadoc is correct:
 /** 
 * @PERIOD and more stuff
 * @DASH and more stuff
 * @UNDERSCORE and more stuff
 */

So it seems that it's during rewritting operation that new tag names are
incorrectly inserted in document...

Assign to Martin as he owns rewritting code.
Comment 7 Martin Aeschlimann CLA 2005-05-24 04:48:32 EDT
fixed > 20050524
Comment 8 Olivier Thomann CLA 2005-05-27 10:53:26 EDT
Verified in I20050526-2000.