英文:
Getting text of non-Javadoc tag inside doc comment with Spoon
问题
我想要使用inria-spoon来处理带有自定义非Javadoc标签的Java源文件中的文档注释。然而,当Spoon处理文档注释时,使用`CtMethod#getDocComment()`返回的`String`将会将非Javadoc标签的文本替换为`@unknown`。
我需要保留标签的原始文本以进行进一步的过滤和处理。
下面的两个类展示了一个输出示例,其中输出为
@unknown some-value
@return name of husband
而期望的输出是
@abc:xyz some-value
@return name of husband
具有主方法以运行的类是`Spooner`,要处理的源代码是`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";
}
}
英文:
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
得分: 1
这将很快在主代码分支中得到修复,当https://github.com/INRIA/spoon/pull/3513合并时。
英文:
This will be soon be fixed in master when https://github.com/INRIA/spoon/pull/3513 is merged.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论