use of org.antlr.v4.runtime.tree.ParseTree in project checkstyle by checkstyle.
the class JavadocParseTreeTest method oneSimpleHtmlTag.
@Test
public void oneSimpleHtmlTag() throws IOException {
final String filename = getHtmlPath("InputOneSimpleHtmlTag.txt");
final ParseTree generatedTree = parseJavadoc(getFileContent(new File(filename)));
final ParseTree expectedTree = ParseTreeBuilder.treeOneSimpleHtmlTag();
compareTrees(expectedTree, generatedTree);
}
use of org.antlr.v4.runtime.tree.ParseTree in project checkstyle by checkstyle.
the class JavadocParseTreeTest method authorWithMailto.
@Test
public void authorWithMailto() throws IOException {
final String filename = getDocPath("InputAuthorWithMailto.txt");
final ParseTree generatedTree = parseJavadoc(getFileContent(new File(filename)));
final ParseTree expectedTree = ParseTreeBuilder.treeAuthorWithMailto();
compareTrees(expectedTree, generatedTree);
}
use of org.antlr.v4.runtime.tree.ParseTree in project checkstyle by checkstyle.
the class JavadocParseTreeTest method textBeforeJavadocTags.
@Test
public void textBeforeJavadocTags() throws IOException {
final String filename = getDocPath("InputTextBeforeJavadocTags.txt");
final ParseTree generatedTree = parseJavadoc(getFileContent(new File(filename)));
final ParseTree expectedTree = ParseTreeBuilder.treeTextBeforeJavadocTags();
compareTrees(expectedTree, generatedTree);
}
use of org.antlr.v4.runtime.tree.ParseTree in project checkstyle by checkstyle.
the class JavadocDetailNodeParser method getNextSibling.
/**
* Gets next sibling of ParseTree node.
* @param node ParseTree node
* @return next sibling of ParseTree node.
*/
private static ParseTree getNextSibling(ParseTree node) {
ParseTree nextSibling = null;
if (node.getParent() != null) {
final ParseTree parent = node.getParent();
final int childCount = parent.getChildCount();
int index = 0;
while (true) {
final ParseTree currentNode = parent.getChild(index);
if (currentNode.equals(node)) {
if (index != childCount - 1) {
nextSibling = parent.getChild(index + 1);
}
break;
}
index++;
}
}
return nextSibling;
}
use of org.antlr.v4.runtime.tree.ParseTree in project checkstyle by checkstyle.
the class JavadocDetailNodeParser method convertParseTreeToDetailNode.
/**
* Converts ParseTree (that is generated by ANTLRv4) to DetailNode tree.
*
* @param parseTreeNode root node of ParseTree
* @return root of DetailNode tree
*/
private DetailNode convertParseTreeToDetailNode(ParseTree parseTreeNode) {
final JavadocNodeImpl rootJavadocNode = createRootJavadocNode(parseTreeNode);
JavadocNodeImpl currentJavadocParent = rootJavadocNode;
ParseTree parseTreeParent = parseTreeNode;
while (currentJavadocParent != null) {
// remove unnecessary children tokens
if (currentJavadocParent.getType() == JavadocTokenTypes.TEXT) {
currentJavadocParent.setChildren((DetailNode[]) JavadocNodeImpl.EMPTY_DETAIL_NODE_ARRAY);
}
final JavadocNodeImpl[] children = (JavadocNodeImpl[]) currentJavadocParent.getChildren();
insertChildrenNodes(children, parseTreeParent);
if (children.length > 0) {
currentJavadocParent = children[0];
parseTreeParent = parseTreeParent.getChild(0);
} else {
JavadocNodeImpl nextJavadocSibling = (JavadocNodeImpl) JavadocUtils.getNextSibling(currentJavadocParent);
ParseTree nextParseTreeSibling = getNextSibling(parseTreeParent);
if (nextJavadocSibling == null) {
JavadocNodeImpl tempJavadocParent = (JavadocNodeImpl) currentJavadocParent.getParent();
ParseTree tempParseTreeParent = parseTreeParent.getParent();
while (nextJavadocSibling == null && tempJavadocParent != null) {
nextJavadocSibling = (JavadocNodeImpl) JavadocUtils.getNextSibling(tempJavadocParent);
nextParseTreeSibling = getNextSibling(tempParseTreeParent);
tempJavadocParent = (JavadocNodeImpl) tempJavadocParent.getParent();
tempParseTreeParent = tempParseTreeParent.getParent();
}
}
currentJavadocParent = nextJavadocSibling;
parseTreeParent = nextParseTreeSibling;
}
}
return rootJavadocNode;
}
Aggregations