Getting text of non-Javadoc tag inside doc comment with Spoon

91 views Asked by At

I would like to use inria-spoon to process Java source files having custom non-Javadoc tags inside Doc comments. However, when Spoon processes Doc comments the String returned using CtMethod#getDocComment() will have replaced the text of non-Javadoc tags with @unknown. I need to keep the original text of the tag for further filtering and processing.

The two classes below shows an example where the output is

@unknown some-value
@return name of husband

and desired is

@abc:xyz some-value
@return name of husband

Class with main method for running is Spooner, source being processed is Carrie.java.

Spooner.java:

package tryspoon;

import spoon.Launcher;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.visitor.filter.TypeFilter;

public class Spooner
{
    private static final String SAMPLE_SOURCE_PATH = "full_local_path_to_source";


    public static void main(String[] args)
    {
        Launcher launcher = new Launcher();
        launcher.addInputResource(SAMPLE_SOURCE_PATH);
        launcher.buildModel();

        String firstDocComment = launcher.getModel()
          .getElements(new TypeFilter<>(CtMethod.class))
          .get(0).getDocComment();

        System.out.println("First Doc comment contents: " + firstDocComment);

    }
}

Carrie.java:

package tryspoon;

public class Carrie {
  /**
   * @abc:xyz some-value
   * @return name of husband
   */
  public String husband()
  {
    return "Doug";
  }
}
1

There are 1 answers

0
Martin Monperrus On BEST ANSWER

This will be soon be fixed in master when https://github.com/INRIA/spoon/pull/3513 is merged.