Search in sources :

Example 11 with CommonHiddenStreamToken

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;
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 12 with CommonHiddenStreamToken

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());
    }
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 13 with CommonHiddenStreamToken

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());
    }
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 14 with CommonHiddenStreamToken

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);
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 15 with CommonHiddenStreamToken

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);
        }
    }
}
Also used : AST(antlr.collections.AST) CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) CommonASTWithHiddenTokens(antlr.CommonASTWithHiddenTokens)

Aggregations

CommonHiddenStreamToken (antlr.CommonHiddenStreamToken)15 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)14 Test (org.junit.Test)11 CommonASTWithHiddenTokens (antlr.CommonASTWithHiddenTokens)1 AST (antlr.collections.AST)1