use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.
the class XpathQueryGeneratorTest method testTextBlocksWithNewLine.
@Test
public void testTextBlocksWithNewLine() throws Exception {
final File testFile = new File(getNonCompilablePath("InputXpathQueryGeneratorTextBlockNewLine.java"));
final FileText testFileText = new FileText(testFile, StandardCharsets.UTF_8.name());
final DetailAST detailAst = JavaParser.parseFile(testFile, JavaParser.Options.WITHOUT_COMMENTS);
final int tabWidth = 8;
final int lineNumber = 6;
final int columnNumber = 25;
final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(detailAst, lineNumber, columnNumber, testFileText, tabWidth);
final List<String> actual = queryGenerator.generate();
final List<String> expected = Collections.singletonList("/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTextBlockNewLine']]/OBJBLOCK/" + "VARIABLE_DEF[./IDENT[@text='testOne']]/ASSIGN/EXPR/" + "TEXT_BLOCK_LITERAL_BEGIN/TEXT_BLOCK_CONTENT[@text='\\n " + "&1line\\n\\n >2line\\n <3line\\n ']");
assertWithMessage("Generated queries do not match expected ones").that(expected).isEqualTo(actual);
}
use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.
the class XpathQueryGeneratorTest method testTabWidthBeforeMethodDef.
@Test
public void testTabWidthBeforeMethodDef() throws Exception {
final File testFile = new File(getPath("InputXpathQueryGeneratorTabWidth.java"));
final FileText testFileText = new FileText(testFile, StandardCharsets.UTF_8.name());
final DetailAST detailAst = JavaParser.parseFile(testFile, JavaParser.Options.WITHOUT_COMMENTS);
final int lineNumber = 4;
final int columnNumber = 13;
final int tabWidth = 4;
final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(detailAst, lineNumber, columnNumber, testFileText, tabWidth);
final List<String> actual = queryGenerator.generate();
final List<String> expected = Arrays.asList("/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTabWidth']]/OBJBLOCK" + "/METHOD_DEF[./IDENT[@text='toString']]", "/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTabWidth']]/OBJBLOCK" + "/METHOD_DEF[./IDENT[@text='toString']]/MODIFIERS", "/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTabWidth']]/OBJBLOCK" + "/METHOD_DEF[./IDENT[@text='toString']]/MODIFIERS/LITERAL_PUBLIC");
assertWithMessage("Generated queries do not match expected ones").that(actual).isEqualTo(expected);
}
use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.
the class SuppressWithPlainTextCommentFilter method accept.
@Override
public boolean accept(AuditEvent event) {
boolean accepted = true;
if (event.getViolation() != null) {
final FileText fileText = getFileText(event.getFileName());
if (fileText != null) {
final List<Suppression> suppressions = getSuppressions(fileText);
accepted = getNearestSuppression(suppressions, event) == null;
}
}
return accepted;
}
use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.
the class AstTreeStringPrinterTest method testPrintAst.
@Test
public void testPrintAst() throws Exception {
final FileText text = new FileText(new File(getPath("InputAstTreeStringPrinterComments.java")).getAbsoluteFile(), System.getProperty("file.encoding", StandardCharsets.UTF_8.name()));
final String actual = toLfLineEnding(AstTreeStringPrinter.printAst(text, JavaParser.Options.WITHOUT_COMMENTS));
final String expected = toLfLineEnding(Files.readString(Paths.get(getPath("ExpectedAstTreeStringPrinter.txt"))));
assertWithMessage("Print AST output is invalid").that(actual).isEqualTo(expected);
}
use of com.puppycrawl.tools.checkstyle.api.FileText 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();
}
Aggregations