use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testDefaultHooks.
@Test
public void testDefaultHooks() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.INTERFACE_DEF, "interface"));
npathComplexityCheckObj.visitToken(ast);
final SortedSet<Violation> violations1 = npathComplexityCheckObj.getViolations();
assertWithMessage("No exception violations expected").that(violations1).isEmpty();
npathComplexityCheckObj.leaveToken(ast);
final SortedSet<Violation> violations2 = npathComplexityCheckObj.getViolations();
assertWithMessage("No exception violations expected").that(violations2).isEmpty();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testTokenEndIsAfterSameLineColumn.
/**
* This must be a reflection test as it is too difficult to hit normally and
* the responsible code can't be removed without failing tests.
* TokenEnd is only used for processingTokenEnd and it is only set during visitConditional
* and visitUnitaryOperator. For it to be the same line/column, it must be the exact same
* token or a token who has the same line/column as it's child and we visit. We never
* visit the same token twice and we are only visiting on very specific tokens.
* The line can't be removed or reworked as other tests fail, and regression shows us no
* use cases to create a UT for.
*
* @throws Exception if there is an error.
*/
@Test
public void testTokenEndIsAfterSameLineColumn() throws Exception {
final NPathComplexityCheck check = new NPathComplexityCheck();
final Object tokenEnd = TestUtil.getInternalState(check, "processingTokenEnd");
final DetailAstImpl token = new DetailAstImpl();
token.setLineNo(0);
token.setColumnNo(0);
assertWithMessage("isAfter must be true for same line/column").that(TestUtil.<Boolean>invokeMethod(tokenEnd, "isAfter", token)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testStatefulFieldsClearedOnBeginTree1.
@Test
@SuppressWarnings("unchecked")
public void testStatefulFieldsClearedOnBeginTree1() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.LITERAL_ELSE);
final NPathComplexityCheck check = new NPathComplexityCheck();
assertWithMessage("Stateful field is not cleared after beginTree").that(TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "rangeValues", rangeValues -> ((Collection<Context>) rangeValues).isEmpty())).isTrue();
assertWithMessage("Stateful field is not cleared after beginTree").that(TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "expressionValues", expressionValues -> ((Collection<Context>) expressionValues).isEmpty())).isTrue();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method mockAST.
/**
* Creates MOCK lexical token and returns AST node for this token.
*
* @param tokenType type of token
* @param tokenText text 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 DetailAstImpl mockAST(final int tokenType, final String tokenText, final int tokenRow, final int tokenColumn) {
final CommonToken tokenImportSemi = new CommonToken(tokenType, tokenText);
tokenImportSemi.setLine(tokenRow);
tokenImportSemi.setCharPositionInLine(tokenColumn);
final DetailAstImpl astSemi = new DetailAstImpl();
astSemi.initialize(tokenImportSemi);
return astSemi;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testStatefulFieldsClearedOnBeginTree2.
@Test
@SuppressWarnings("unchecked")
public void testStatefulFieldsClearedOnBeginTree2() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.LITERAL_RETURN);
ast.setLineNo(5);
final DetailAstImpl child = new DetailAstImpl();
child.setType(TokenTypes.SEMI);
ast.addChild(child);
final NPathComplexityCheck check = new NPathComplexityCheck();
assertWithMessage("Stateful field is not cleared after beginTree").that(TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "afterValues", isAfterValues -> ((Collection<Context>) isAfterValues).isEmpty())).isTrue();
}
Aggregations