Search in sources :

Example 46 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class IllegalInstantiationCheckTest method testNullClassLoader.

@Test
public void testNullClassLoader() throws Exception {
    final DetailAST exprAst = new DetailAST();
    exprAst.setType(TokenTypes.EXPR);
    final DetailAST newAst = new DetailAST();
    newAst.setType(TokenTypes.LITERAL_NEW);
    newAst.setLineNo(1);
    newAst.setColumnNo(1);
    final DetailAST identAst = new DetailAST();
    identAst.setType(TokenTypes.IDENT);
    identAst.setText("Boolean");
    final DetailAST lparenAst = new DetailAST();
    lparenAst.setType(TokenTypes.LPAREN);
    final DetailAST elistAst = new DetailAST();
    elistAst.setType(TokenTypes.ELIST);
    final DetailAST rparenAst = new DetailAST();
    rparenAst.setType(TokenTypes.RPAREN);
    exprAst.addChild(newAst);
    newAst.addChild(identAst);
    identAst.setNextSibling(lparenAst);
    lparenAst.setNextSibling(elistAst);
    elistAst.setNextSibling(rparenAst);
    final IllegalInstantiationCheck check = new IllegalInstantiationCheck();
    final File inputFile = new File(getNonCompilablePath("InputIllegalInstantiationLang.java"));
    check.setFileContents(new FileContents(new FileText(inputFile, "UTF-8")));
    check.configure(createCheckConfig(IllegalInstantiationCheck.class));
    check.setMessages(new LocalizedMessages());
    check.setClasses("java.lang.Boolean");
    check.visitToken(newAst);
    check.finishTree(newAst);
}
Also used : LocalizedMessages(com.puppycrawl.tools.checkstyle.api.LocalizedMessages) FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.Test)

Example 47 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class DeclarationOrderCheckTest method testParents.

@Test
public void testParents() {
    final DetailAST parent = new DetailAST();
    parent.setType(TokenTypes.STATIC_INIT);
    final DetailAST method = new DetailAST();
    method.setType(TokenTypes.METHOD_DEF);
    parent.setFirstChild(method);
    final DetailAST ctor = new DetailAST();
    ctor.setType(TokenTypes.CTOR_DEF);
    method.setNextSibling(ctor);
    final DeclarationOrderCheck check = new DeclarationOrderCheck();
    check.visitToken(method);
    check.visitToken(ctor);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 48 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class FinalLocalVariableCheckTest method testImproperToken.

@Test
public void testImproperToken() {
    final FinalLocalVariableCheck check = new FinalLocalVariableCheck();
    final DetailAST lambdaAst = new DetailAST();
    lambdaAst.setType(TokenTypes.LAMBDA);
    try {
        check.visitToken(lambdaAst);
        Assert.fail("IllegalStateException is expected");
    } catch (IllegalStateException ex) {
    // it is OK
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 49 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class CodeSelectorPresentationTest method testDetailASTNoSelection.

@Test
public void testDetailASTNoSelection() {
    final DetailAST leaf = tree.getFirstChild();
    final CodeSelectorPresentation selector = new CodeSelectorPresentation(leaf, linesToPosition);
    selector.findSelectionPositions();
    Assert.assertEquals(23, selector.getSelectionStart());
    Assert.assertEquals(23, selector.getSelectionEnd());
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 50 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class ParseTreeTablePresentationTest method testGetIndexOfChild.

@Test
public void testGetIndexOfChild() {
    DetailAST ithChild = tree.getFirstChild();
    Assert.assertNotNull(ithChild);
    final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
    int index = 0;
    while (ithChild != null) {
        Assert.assertEquals(index, parseTree.getIndexOfChild(tree, ithChild));
        ithChild = ithChild.getNextSibling();
        index++;
    }
    Assert.assertEquals(-1, parseTree.getIndexOfChild(tree, new DetailAST()));
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Aggregations

DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)397 Test (org.junit.Test)74 CommonHiddenStreamToken (antlr.CommonHiddenStreamToken)14 FullIdent (com.puppycrawl.tools.checkstyle.api.FullIdent)14 ArrayList (java.util.ArrayList)13 AST (antlr.collections.AST)8 Method (java.lang.reflect.Method)7 LinkedList (java.util.LinkedList)7 Scope (com.puppycrawl.tools.checkstyle.api.Scope)6 HashSet (java.util.HashSet)6 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)5 ArrayDeque (java.util.ArrayDeque)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 DetailNode (com.puppycrawl.tools.checkstyle.api.DetailNode)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 AbstractCheck (com.puppycrawl.tools.checkstyle.api.AbstractCheck)3 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)3 TokenTypes (com.puppycrawl.tools.checkstyle.api.TokenTypes)3 SimpleEntry (java.util.AbstractMap.SimpleEntry)3 HashMap (java.util.HashMap)3