Bug 88126 - [ast rewrite] Inconsistent results in modifying TagElements
Summary: [ast rewrite] Inconsistent results in modifying TagElements
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC1   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-15 17:27 EST by Edwin Chan CLA
Modified: 2005-05-27 10:53 EDT (History)
0 users

See Also:


Attachments
A plugin to modify Javadoc tags (9.50 KB, application/zip)
2005-03-15 17:28 EST, Edwin Chan CLA
no flags Details
A project to be used as a test case (1.37 KB, application/zip)
2005-03-15 17:31 EST, Edwin Chan CLA
no flags Details
Sample output (193 bytes, text/plain)
2005-03-15 17:32 EST, Edwin Chan CLA
no flags Details
A project to be used as a test case (restored to how it should start out) (1.45 KB, application/zip)
2005-03-15 17:39 EST, Edwin Chan CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.