use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class ImportOrderCheckTest 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
* @param tokenRow token position in a file (row)
* @param tokenColumn token position in a file (column)
* @return AST node for the token
*/
private static DetailAST mockAST(final int tokenType, final String tokenText, final String tokenFileName, final int tokenRow, final int tokenColumn) {
final CommonHiddenStreamToken tokenImportSemi = new CommonHiddenStreamToken();
tokenImportSemi.setType(tokenType);
tokenImportSemi.setText(tokenText);
tokenImportSemi.setLine(tokenRow);
tokenImportSemi.setColumn(tokenColumn);
tokenImportSemi.setFilename(tokenFileName);
final DetailAST astSemi = new DetailAST();
astSemi.initialize(tokenImportSemi);
return astSemi;
}
use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class BooleanExpressionComplexityCheckTest method testWrongToken.
@Test
public void testWrongToken() {
final BooleanExpressionComplexityCheck booleanExpressionComplexityCheckObj = new BooleanExpressionComplexityCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
try {
booleanExpressionComplexityCheckObj.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 ClassDataAbstractionCouplingCheckTest method testWrongToken.
@Test
public void testWrongToken() {
final ClassDataAbstractionCouplingCheck classDataAbstractionCouplingCheckObj = new ClassDataAbstractionCouplingCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CTOR_DEF, "ctor"));
try {
classDataAbstractionCouplingCheckObj.visitToken(ast);
fail("exception expected");
} catch (IllegalArgumentException ex) {
assertEquals("Unknown type: ctor[0x-1]", ex.getMessage());
}
}
use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testDefaultHooks.
@Test
public void testDefaultHooks() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
npathComplexityCheckObj.visitToken(ast);
npathComplexityCheckObj.leaveToken(ast);
}
use of antlr.CommonHiddenStreamToken in project processing by processing.
the class PdeEmitter method printIfThenElse.
private void printIfThenElse(final AST literalIf) throws SketchException {
out.print(literalIf.getText());
dumpHiddenAfter(literalIf);
final AST condition = literalIf.getFirstChild();
// the "if" condition: an EXPR
print(condition);
// the "then" clause is either an SLIST or an EXPR
final AST thenPath = condition.getNextSibling();
print(thenPath);
// optional "else" clause: an SLIST or an EXPR
// what could be simpler?
final AST elsePath = thenPath.getNextSibling();
if (elsePath != null) {
out.print("else");
final AST bestPrintableNode = getBestPrintableNode(elsePath, true);
dumpHiddenBefore(bestPrintableNode);
final CommonHiddenStreamToken hiddenBefore = ((CommonASTWithHiddenTokens) elsePath).getHiddenBefore();
if (elsePath.getType() == PdeTokenTypes.SLIST && elsePath.getNumberOfChildren() == 0 && hiddenBefore == null) {
out.print("{");
final CommonHiddenStreamToken hiddenAfter = ((CommonASTWithHiddenTokens) elsePath).getHiddenAfter();
if (hiddenAfter == null) {
out.print("}");
} else {
dumpHiddenTokens(hiddenAfter);
}
} else {
print(elsePath);
}
}
}
Aggregations