use of com.puppycrawl.tools.checkstyle.api.SeverityLevel in project checkstyle by checkstyle.
the class SeverityMatchFilterTest method testSeverity.
@Test
public void testSeverity() {
filter.setSeverity(SeverityLevel.INFO);
final AuditEvent ev = new AuditEvent(this, "Test.java");
// event with no message has severity level INFO
assertTrue("no message", filter.accept(ev));
final SeverityLevel errorLevel = SeverityLevel.ERROR;
final LocalizedMessage errorMessage = new LocalizedMessage(0, 0, "", "", null, errorLevel, null, getClass(), null);
final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
assertFalse("level:" + errorLevel, filter.accept(ev2));
final SeverityLevel infoLevel = SeverityLevel.INFO;
final LocalizedMessage infoMessage = new LocalizedMessage(0, 0, "", "", null, infoLevel, null, getClass(), null);
final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
assertTrue("level:" + infoLevel, filter.accept(ev3));
}
use of com.puppycrawl.tools.checkstyle.api.SeverityLevel in project checkstyle by checkstyle.
the class SeverityMatchFilterTest method testDefault.
@Test
public void testDefault() {
final AuditEvent ev = new AuditEvent(this, "Test.java");
assertFalse("no message", filter.accept(ev));
final SeverityLevel errorLevel = SeverityLevel.ERROR;
final LocalizedMessage errorMessage = new LocalizedMessage(0, 0, "", "", null, errorLevel, null, getClass(), null);
final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
assertTrue("level:" + errorLevel, filter.accept(ev2));
final SeverityLevel infoLevel = SeverityLevel.INFO;
final LocalizedMessage infoMessage = new LocalizedMessage(0, 0, "", "", null, infoLevel, null, getClass(), null);
final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
assertFalse("level:" + infoLevel, filter.accept(ev3));
}
use of com.puppycrawl.tools.checkstyle.api.SeverityLevel in project checkstyle by checkstyle.
the class DefaultLogger method addError.
/**
* Print an Emacs compliant line on the error stream.
* If the column number is non zero, then also display it.
* @see AuditListener
**/
@Override
public void addError(AuditEvent event) {
final SeverityLevel severityLevel = event.getSeverityLevel();
if (severityLevel != SeverityLevel.IGNORE) {
final String errorMessage = formatter.format(event);
errorWriter.println(errorMessage);
}
}
use of com.puppycrawl.tools.checkstyle.api.SeverityLevel in project checkstyle by checkstyle.
the class AuditEventDefaultFormatter method format.
@Override
public String format(AuditEvent event) {
final String fileName = event.getFileName();
final String message = event.getMessage();
final SeverityLevel severityLevel = event.getSeverityLevel();
final String severityLevelName;
if (severityLevel == SeverityLevel.WARNING) {
// We change the name of severity level intentionally
// to shorten the length of the log message.
severityLevelName = "WARN";
} else {
severityLevelName = severityLevel.getName().toUpperCase(Locale.US);
}
// Avoid StringBuffer.expandCapacity
final int bufLen = calculateBufferLength(event, severityLevelName.length());
final StringBuilder sb = new StringBuilder(bufLen);
sb.append('[').append(severityLevelName).append("] ").append(fileName).append(':').append(event.getLine());
if (event.getColumn() > 0) {
sb.append(':').append(event.getColumn());
}
sb.append(": ").append(message);
final String checkShortName = getCheckShortName(event);
sb.append(" [").append(checkShortName).append(']');
return sb.toString();
}
use of com.puppycrawl.tools.checkstyle.api.SeverityLevel in project maven-plugins by apache.
the class CheckstyleReportGenerator method doFileEvents.
private void doFileEvents(List<AuditEvent> eventList, String filename) {
for (AuditEvent event : eventList) {
SeverityLevel level = event.getSeverityLevel();
if ((getSeverityLevel() != null) && !(getSeverityLevel() != level)) {
continue;
}
sink.tableRow();
sink.tableCell();
iconTool.iconSeverity(level.getName(), IconTool.TEXT_SIMPLE);
sink.tableCell_();
sink.tableCell();
String category = RuleUtil.getCategory(event);
if (category != null) {
sink.text(category);
}
sink.tableCell_();
sink.tableCell();
String ruleName = RuleUtil.getName(event);
if (ruleName != null) {
sink.text(ruleName);
}
sink.tableCell_();
sink.tableCell();
sink.text(event.getMessage());
sink.tableCell_();
sink.tableCell();
int line = event.getLine();
if (getXrefLocation() != null && line != 0) {
sink.link(getXrefLocation() + "/" + filename.replaceAll("\\.java$", ".html") + "#L" + line);
sink.text(String.valueOf(line));
sink.link_();
} else if (line != 0) {
sink.text(String.valueOf(line));
}
sink.tableCell_();
sink.tableRow_();
}
}
Aggregations