I am writing a tool for collecting class comments, and I would like to gather all comments that are logically attached to a class by developers:
public abstract class A {
private Integer d;
// comment line
/**
* javadoc comment
*/
class B {
int c;
}
}
or (reversed order of comments)
public abstract class A {
/**
* javadoc comment
*/
// comment line
class B {
int c;
}
}
my current implementation traverses recursively starting from CompilationUnit to each child (Node) and checks if it is a class(or interface) declaration. Then the comment is extracted from the Node through node.getComment()
. The problem is, that the other comment located on top of the first has no parent and therefore is not being counted.
Is there a way to somehow collect all of them? (lets consider they're located next to each other, without new line skips)