use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class XpathQueryGeneratorTest method testConstructorWithTreeWalkerAuditEvent.
@Test
public void testConstructorWithTreeWalkerAuditEvent() {
final Violation violation = new Violation(12, 1, "messages.properties", null, null, null, null, null, null);
final TreeWalkerAuditEvent event = new TreeWalkerAuditEvent(new FileContents(fileText), "InputXpathQueryGenerator", violation, rootAst);
final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(event, DEFAULT_TAB_WIDTH);
final List<String> actual = queryGenerator.generate();
final List<String> expected = Arrays.asList("/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]", "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]/MODIFIERS", "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]/MODIFIERS" + "/LITERAL_PUBLIC");
assertWithMessage("Generated queries do not match expected ones").that(actual).isEqualTo(expected);
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class JavadocMethodCheck method processAST.
/**
* Called to process an AST when visiting it.
*
* @param ast the AST to process. Guaranteed to not be PACKAGE_DEF or
* IMPORT tokens.
*/
// suppress deprecation until https://github.com/checkstyle/checkstyle/issues/11166
@SuppressWarnings("deprecation")
private void processAST(DetailAST ast) {
if (shouldCheck(ast)) {
final FileContents contents = getFileContents();
final TextBlock textBlock = contents.getJavadocBefore(ast.getLineNo());
if (textBlock != null) {
checkComment(ast, textBlock);
}
}
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilterTest method testAcceptNullViolation.
@Test
public void testAcceptNullViolation() {
final SuppressWithNearbyCommentFilter filter = new SuppressWithNearbyCommentFilter();
final FileContents contents = new FileContents(new FileText(new File("filename"), Collections.singletonList("//SUPPRESS CHECKSTYLE ignore")));
contents.reportSingleLineComment(1, 0);
final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(contents, null, null, null);
assertWithMessage("Filter should accept null violation").that(filter.accept(auditEvent)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilterTest method testAcceptNullFileContents.
@Test
public void testAcceptNullFileContents() {
final SuppressWithNearbyCommentFilter filter = new SuppressWithNearbyCommentFilter();
final FileContents contents = null;
final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(contents, null, new Violation(1, null, null, null, null, Object.class, null), null);
assertWithMessage("Filter should accept audit event").that(filter.accept(auditEvent)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.FileContents in project checkstyle by checkstyle.
the class SuppressionCommentFilterTest method testFindNearestMatchDontAllowSameColumn.
@Test
public void testFindNearestMatchDontAllowSameColumn() {
final SuppressionCommentFilter suppressionCommentFilter = new SuppressionCommentFilter();
final FileContents contents = new FileContents(new FileText(new File("filename"), Arrays.asList("//CHECKSTYLE:OFF: ConstantNameCheck", "line2")));
contents.reportSingleLineComment(1, 0);
final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, "filename", new Violation(1, null, null, null, null, Object.class, null), null);
final boolean result = suppressionCommentFilter.accept(dummyEvent);
assertWithMessage("Filter should not accept event").that(result).isFalse();
}
Aggregations