use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class UncommentedMainCheckTest method testIllegalStateException.
@Test
public void testIllegalStateException() {
final UncommentedMainCheck check = new UncommentedMainCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CTOR_DEF, "ctor"));
try {
check.visitToken(ast);
Assert.fail("IllegalStateException is expected");
} catch (IllegalStateException ex) {
assertEquals(ast.toString(), ex.getMessage());
}
}
use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class GenericWhitespaceCheckTest method testWrongTokenType.
@Test
public void testWrongTokenType() {
final GenericWhitespaceCheck genericWhitespaceCheckObj = new GenericWhitespaceCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
try {
genericWhitespaceCheckObj.visitToken(ast);
fail("exception expected");
} catch (IllegalArgumentException ex) {
assertEquals("Unknown type interface[0x-1]", ex.getMessage());
}
}
use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class NoWhitespaceAfterCheckTest method mockAST.
/**
* Creates MOCK lexical token and returns AST node for this token
* @param tokenType type of token
* @param tokenText text of token
* @param tokenFileName file name of token
* @return AST node for the token
*/
private static DetailAST mockAST(final int tokenType, final String tokenText, final String tokenFileName) {
final CommonHiddenStreamToken tokenImportSemi = new CommonHiddenStreamToken();
tokenImportSemi.setType(tokenType);
tokenImportSemi.setText(tokenText);
tokenImportSemi.setFilename(tokenFileName);
final DetailAST astSemi = new DetailAST();
astSemi.initialize(tokenImportSemi);
return astSemi;
}
use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class TreeWalker method appendHiddenCommentNodes.
/**
* Appends comment nodes to existing AST.
* It traverses each node in AST, looks for hidden comment tokens
* and appends found comment tokens as nodes in AST.
* @param root
* root of AST.
* @return root of AST with comment nodes.
*/
private static DetailAST appendHiddenCommentNodes(DetailAST root) {
DetailAST result = root;
DetailAST curNode = root;
DetailAST lastNode = root;
while (curNode != null) {
if (isPositionGreater(curNode, lastNode)) {
lastNode = curNode;
}
CommonHiddenStreamToken tokenBefore = curNode.getHiddenBefore();
DetailAST currentSibling = curNode;
while (tokenBefore != null) {
final DetailAST newCommentNode = createCommentAstFromToken(tokenBefore);
currentSibling.addPreviousSibling(newCommentNode);
if (currentSibling == result) {
result = newCommentNode;
}
currentSibling = newCommentNode;
tokenBefore = tokenBefore.getHiddenBefore();
}
DetailAST toVisit = curNode.getFirstChild();
while (curNode != null && toVisit == null) {
toVisit = curNode.getNextSibling();
if (toVisit == null) {
curNode = curNode.getParent();
}
}
curNode = toVisit;
}
if (lastNode != null) {
CommonHiddenStreamToken tokenAfter = lastNode.getHiddenAfter();
DetailAST currentSibling = lastNode;
while (tokenAfter != null) {
final DetailAST newCommentNode = createCommentAstFromToken(tokenAfter);
currentSibling.addNextSibling(newCommentNode);
currentSibling = newCommentNode;
tokenAfter = tokenAfter.getHiddenAfter();
}
}
return result;
}
use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class ExecutableStatementCountCheckTest method testLeaveTokenWithWrongTokenType.
@Test
public void testLeaveTokenWithWrongTokenType() {
final ExecutableStatementCountCheck checkObj = new ExecutableStatementCountCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.ENUM, "ENUM"));
try {
checkObj.leaveToken(ast);
fail("exception expected");
} catch (IllegalStateException ex) {
assertEquals("ENUM[0x-1]", ex.getMessage());
}
}
Aggregations