use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideByMessage.
@Test
public void testDecideByMessage() {
final Violation violation = new Violation(1, 0, "", "", null, null, getClass(), "Test");
final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
final SuppressFilterElement filter1 = new SuppressFilterElement(null, null, "Test", null, null, null);
final SuppressFilterElement filter2 = new SuppressFilterElement(null, null, "Bad", null, null, null);
assertWithMessage("Message match").that(filter1.accept(ev)).isFalse();
assertWithMessage("Message not match").that(filter2.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingRegExpNotMatch.
@Test
public void testDecideByFileNameAndModuleMatchingRegExpNotMatch() {
final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "T1est", message);
assertWithMessage("Filter should accept valid event").that(filter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideByColumn.
@Test
public void testDecideByColumn() {
final Violation violation = new Violation(10, 10, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
final SuppressFilterElement filter1 = new SuppressFilterElement("Test", "Test", null, null, null, "1-10");
final SuppressFilterElement filter2 = new SuppressFilterElement("Test", "Test", null, null, null, "1-9, 11");
// deny because there are matches on file name, check name, and column
assertWithMessage("In range 1-10").that(filter1.accept(ev)).isFalse();
assertWithMessage("Not in 1-9, 1)").that(filter2.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class TreeWalker method processFiltered.
@Override
protected void processFiltered(File file, FileText fileText) throws CheckstyleException {
// check if already checked and passed the file
if (!ordinaryChecks.isEmpty() || !commentChecks.isEmpty()) {
final FileContents contents = getFileContents();
final DetailAST rootAST = JavaParser.parse(contents);
if (!ordinaryChecks.isEmpty()) {
walk(rootAST, contents, AstState.ORDINARY);
}
if (!commentChecks.isEmpty()) {
final DetailAST astWithComments = JavaParser.appendHiddenCommentNodes(rootAST);
walk(astWithComments, contents, AstState.WITH_COMMENTS);
}
if (filters.isEmpty()) {
addViolations(violations);
} else {
final SortedSet<Violation> filteredViolations = getFilteredViolations(file.getAbsolutePath(), contents, rootAST);
addViolations(filteredViolations);
}
violations.clear();
}
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class TranslationCheckTest method testLogIllegalArgumentException.
@Test
public void testLogIllegalArgumentException() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(TranslationCheck.class);
checkConfig.addProperty("baseName", "^bad.*$");
final String[] expected = { "0: " + new Violation(1, Definitions.CHECKSTYLE_BUNDLE, "general.exception", new String[] { "Malformed \\uxxxx encoding." }, null, getClass(), null).getViolation(), "1: " + getCheckMessage(MSG_KEY, "test") };
final File[] propertyFiles = { new File(getPath("bad.properties")), new File(getPath("bad_es.properties")) };
verify(createChecker(checkConfig), propertyFiles, getPath("bad.properties"), expected);
}
Aggregations