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);
}
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);
}
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
}
}
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());
}
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()));
}
Aggregations