本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.SeverityLevel类的典型用法代码示例。如果您正苦于以下问题:Java SeverityLevel类的具体用法?Java SeverityLevel怎么用?Java SeverityLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SeverityLevel类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了SeverityLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toSeverity
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
public static String toSeverity(RulePriority priority) {
final String result;
switch (priority) {
case BLOCKER:
case CRITICAL:
result = SeverityLevel.ERROR.getName();
break;
case MAJOR:
result = SeverityLevel.WARNING.getName();
break;
case MINOR:
case INFO:
result = SeverityLevel.INFO.getName();
break;
default:
throw new IllegalArgumentException("Priority not supported: " + priority);
}
return result;
}
示例2: fromSeverity
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
public static RulePriority fromSeverity(String severity) {
RulePriority result = null;
try {
final SeverityLevel severityLevel = SeverityLevel.getInstance(severity);
switch (severityLevel) {
case ERROR:
result = RulePriority.BLOCKER;
break;
case WARNING:
result = RulePriority.MAJOR;
break;
case INFO:
case IGNORE:
result = RulePriority.INFO;
break;
default:
}
}
catch (Exception exc) {
LOG.warn("Smth wrong severity", exc);
}
return result;
}
示例3: realExecute
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
/**
* Helper implementation to perform execution.
* @param checkstyleVersion Checkstyle compile version.
*/
private void realExecute(String checkstyleVersion) {
// Create the root module
RootModule rootModule = null;
try {
rootModule = createRootModule();
// setup the listeners
final AuditListener[] listeners = getListeners();
for (AuditListener element : listeners) {
rootModule.addListener(element);
}
final SeverityLevelCounter warningCounter =
new SeverityLevelCounter(SeverityLevel.WARNING);
rootModule.addListener(warningCounter);
processFiles(rootModule, warningCounter, checkstyleVersion);
}
finally {
destroyRootModule(rootModule);
}
}
示例4: testLogIoExceptionFileNotFound
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testLogIoExceptionFileNotFound() throws Exception {
//I can't put wrong file here. Checkstyle fails before check started.
//I saw some usage of file or handling of wrong file in Checker, or somewhere
//in checks running part. So I had to do it with reflection to improve coverage.
final TranslationCheck check = new TranslationCheck();
final DefaultConfiguration checkConfig = createModuleConfig(TranslationCheck.class);
check.configure(checkConfig);
final Checker checker = createChecker(checkConfig);
final SeverityLevelCounter counter = new SeverityLevelCounter(SeverityLevel.ERROR);
checker.addListener(counter);
check.setMessageDispatcher(checker);
final Method loadKeys =
check.getClass().getDeclaredMethod("getTranslationKeys", File.class);
loadKeys.setAccessible(true);
final Set<String> keys = (Set<String>) loadKeys.invoke(check, new File(""));
assertTrue("Translation keys should be empty when File is not found", keys.isEmpty());
assertEquals("Invalid error count", 1, counter.getCount());
}
示例5: testAddErrorOnZeroColumns
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@Test
public void testAddErrorOnZeroColumns() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message =
new LocalizedMessage(1, 0,
"messages.properties", "key", null, SeverityLevel.ERROR, null,
getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.fileStarted(ev);
logger.addError(ev);
logger.fileFinished(ev);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerErrorZeroColumn.xml"), outStream,
message.getMessage());
}
示例6: testAuditFinishedWithoutFileFinished
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@Test
public void testAuditFinishedWithoutFileFinished() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
logger.fileStarted(fileStartedEvent);
final LocalizedMessage message =
new LocalizedMessage(1, 1,
"messages.properties", "key", null, SeverityLevel.ERROR, null,
getClass(), null);
final AuditEvent errorEvent = new AuditEvent(this, "Test.java", message);
logger.addError(errorEvent);
logger.fileFinished(errorEvent);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerError.xml"), outStream, message.getMessage());
}
示例7: testDefault
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@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));
}
示例8: testSeverity
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@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));
}
示例9: testAcceptOnMatch
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@Test
public void testAcceptOnMatch() {
filter.setSeverity(SeverityLevel.INFO);
filter.setAcceptOnMatch(false);
final AuditEvent ev = new AuditEvent(this, "Test.java");
// event with no message has severity level INFO
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));
}
示例10: testAcceptThrowsIllegalStateExceptionAsFileNotFound
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@Test
public void testAcceptThrowsIllegalStateExceptionAsFileNotFound() {
final LocalizedMessage message = new LocalizedMessage(1, 1, 1, TokenTypes.CLASS_DEF,
"messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final String fileName = "nonexisting_file";
final AuditEvent auditEvent = new AuditEvent(this, fileName, message);
final SuppressWithPlainTextCommentFilter filter = new SuppressWithPlainTextCommentFilter();
try {
filter.accept(auditEvent);
fail(IllegalStateException.class.getSimpleName() + " is expected");
}
catch (IllegalStateException ex) {
assertEquals("Invalid exception message",
"Cannot read source file: " + fileName, ex.getMessage());
final Throwable cause = ex.getCause();
assertTrue("Exception cause has invalid type",
cause instanceof FileNotFoundException);
assertEquals("Invalid exception message",
fileName + " (No such file or directory)", cause.getMessage());
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:SuppressWithPlainTextCommentFilterTest.java
示例11: checkstyle
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@Test
public void checkstyle() {
// Analyze all sources in src/main/java
AnalyzerConfig config = AnalyzerConfig.maven().main();
// Only treat issues with severity WARNING or higher
StyleEventCollector collector = new StyleEventCollector().severity(SeverityLevel.WARNING)
.just(In.everywhere().ignore("import.avoidStar", "javadoc.missing"))
.because("in tests, long lines are ok", In.classes("*Test").ignore("maxLineLen"));
//use google checks, but adjust max line length
final StyleChecks checks = StyleChecks.google().maxLineLen(120);
CheckstyleResult result = new CheckstyleAnalyzer(config, checks, collector).analyze();
assertThat(result, hasNoCheckstyleIssues());
}
示例12: addError
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */
public void addError(AuditEvent aEvt)
{
printEvent(aEvt);
if (SeverityLevel.ERROR.equals(aEvt.getSeverityLevel())) {
mErrors++;
mTotalErrors++;
}
}
示例13: addError
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */
public void addError(AuditEvent aEvt)
{
final SeverityLevel severityLevel = aEvt.getSeverityLevel();
if (mInitialized && !SeverityLevel.IGNORE.equals(severityLevel)) {
final Log log = mLogFactory.getInstance(aEvt.getSourceName());
final String fileName = aEvt.getFileName();
final String message = aEvt.getMessage();
// avoid StringBuffer.expandCapacity
final int bufLen = message.length() + BUFFER_CUSHION;
final StringBuffer sb = new StringBuffer(bufLen);
sb.append("Line: ").append(aEvt.getLine());
if (aEvt.getColumn() > 0) {
sb.append(" Column: ").append(aEvt.getColumn());
}
sb.append(" Message: ").append(message);
if (aEvt.getSeverityLevel().equals(SeverityLevel.WARNING)) {
log.warn(sb.toString());
}
else if (aEvt.getSeverityLevel().equals(SeverityLevel.INFO)) {
log.info(sb.toString());
}
else {
log.error(sb.toString());
}
}
}
示例14: addError
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */
public void addError(AuditEvent aEvt)
{
if (SeverityLevel.ERROR.equals(aEvt.getSeverityLevel())) {
mLogger.addError(aEvt);
mErrors++;
}
}
示例15: endElement
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; //导入依赖的package包/类
@Override
public void endElement(String uri,
String localName,
String qName) throws SAXException {
if (qName.equals(MODULE)) {
final Configuration recentModule =
configStack.pop();
// get severity attribute if it exists
SeverityLevel level = null;
if (containsAttribute(recentModule, SEVERITY)) {
try {
final String severity = recentModule.getAttribute(SEVERITY);
level = SeverityLevel.getInstance(severity);
}
catch (final CheckstyleException ex) {
// [email protected][IllegalInstantiation] SAXException is in the overridden
// method signature
throw new SAXException(
"Problem during accessing '" + SEVERITY + "' attribute for "
+ recentModule.getName(), ex);
}
}
// omit this module if these should be omitted and the module
// has the severity 'ignore'
final boolean omitModule = omitIgnoredModules
&& level == SeverityLevel.IGNORE;
if (omitModule && !configStack.isEmpty()) {
final DefaultConfiguration parentModule =
configStack.peek();
parentModule.removeChild(recentModule);
}
}
}