all! I'm not sure whether you guys meet questions when using SPOON to get Java code comments. According to the description in the following website,
We know the diversity kinds of Java comments that SPOON can deal with, but when I use either the function CtElement.getDocComment()
or the interface spoon.reflect.code.CtComment
, I CANNOT get any comment content.
There only one Launcher object in main function,
Launcher launcher = new Launcher();
launcher.addInputResource("src/main/java/org/xxx/A.java");
CtModel model = launcher.buildModel();
model.processWith(new CLSProsessor());
the processor CLSProcessor
is as follows,
class COMProcessore extends AbstractProcessor<CtComment>{
@Override
public boolean isToBeProcessed(CtComment candidate) {
// only process Javadoc
if (candidate.getCommentType() == CtComment.CommentType.JAVADOC) {
return true;
}
return false;
}
@Override
public void process(CtComment arg0) {
System.out.println(">>" + arg0.getContent());
}
}
Looking for your kind help, and any comments are welcome!
By default Spoon does not take into account the comment from the source code. In order to make them available you have to switch an option to activate them.
This can be done using the following code:
Launcher launcher = new Launcher();
launcher.getEnvironment().setCommentEnabled(true);
And now it should work.