当前位置: 首页>>代码示例>>Java>>正文


Java AuditEvent类代码示例

本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.AuditEvent的典型用法代码示例。如果您正苦于以下问题:Java AuditEvent类的具体用法?Java AuditEvent怎么用?Java AuditEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuditEvent类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了AuditEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addError

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
@Override
public void addError(AuditEvent event) {
    final String ruleKey = getRuleKey(event);
    if (ruleKey != null) {
        final String message = getMessage(event);
        // In Checkstyle 5.5 exceptions are reported as an events from
        // TreeWalker
        if ("com.puppycrawl.tools.checkstyle.TreeWalker".equals(ruleKey)) {
            LOG.warn("{} : {}", event.getFileName(), message);
        }
        initResource(event);
        final Issuable issuable = perspectives.as(Issuable.class, currentResource);
        final Rule rule = ruleFinder.findByKey(CheckstyleConstants.REPOSITORY_KEY, ruleKey);
        if (rule != null && issuable != null) {
            final IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(rule.ruleKey())
                    .message(message).line(getLineId(event));
            issuable.addIssue(issueBuilder.build());
        }
    }
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:21,代码来源:CheckstyleAuditListener.java

示例2: isSuppressed

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
/**
 * Checks for a suppression of a check with the given source name and
 * location in the last file processed.
 * @param event audit event.
 * @return whether the check with the given name is suppressed at the given
 *         source location
 */
public static boolean isSuppressed(AuditEvent event) {
    final List<Entry> entries = ENTRIES.get();
    final String sourceName = event.getSourceName();
    final String checkAlias = getAlias(sourceName);
    final int line = event.getLine();
    final int column = event.getColumn();
    boolean suppressed = false;
    for (Entry entry : entries) {
        final boolean afterStart = isSuppressedAfterEventStart(line, column, entry);
        final boolean beforeEnd = isSuppressedBeforeEventEnd(line, column, entry);
        final boolean nameMatches =
            ALL_WARNING_MATCHING_ID.equals(entry.getCheckName())
                || entry.getCheckName().equalsIgnoreCase(checkAlias);
        final boolean idMatches = event.getModuleId() != null
            && event.getModuleId().equals(entry.getCheckName());
        if (afterStart && beforeEnd && (nameMatches || idMatches)) {
            suppressed = true;
            break;
        }
    }
    return suppressed;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:30,代码来源:SuppressWarningsHolder.java

示例3: writeFileError

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
/**
 * Outputs the given event to the writer.
 * @param event An event to print.
 */
private void writeFileError(AuditEvent event) {
    writer.print("<error" + " line=\"" + event.getLine() + "\"");
    if (event.getColumn() > 0) {
        writer.print(" column=\"" + event.getColumn() + "\"");
    }
    writer.print(" severity=\""
            + event.getSeverityLevel().getName()
            + "\"");
    writer.print(" message=\""
            + encode(event.getMessage())
            + "\"");
    writer.print(" source=\"");
    if (event.getModuleId() == null) {
        writer.print(encode(event.getSourceName()));
    }
    else {
        writer.print(encode(event.getModuleId()));
    }
    writer.println("\"/>");
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:XMLLogger.java

示例4: getCheckShortName

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
/**
 * Returns check name without 'Check' suffix.
 * @param event audit event.
 * @return check name without 'Check' suffix.
 */
private static String getCheckShortName(AuditEvent event) {
    final String checkFullName = event.getSourceName();
    final String checkShortName;
    final int lastDotIndex = checkFullName.lastIndexOf('.');
    if (lastDotIndex == -1) {
        if (checkFullName.endsWith(SUFFIX)) {
            checkShortName = checkFullName.substring(0, checkFullName.lastIndexOf(SUFFIX));
        }
        else {
            checkShortName = checkFullName.substring(0, checkFullName.length());
        }
    }
    else {
        if (checkFullName.endsWith(SUFFIX)) {
            checkShortName = checkFullName.substring(lastDotIndex + 1,
                checkFullName.lastIndexOf(SUFFIX));
        }
        else {
            checkShortName = checkFullName.substring(lastDotIndex + 1, checkFullName.length());
        }
    }
    return checkShortName;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:AuditEventDefaultFormatter.java

示例5: isMatch

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
/**
 * Checks whether the suppression matches the given {@link AuditEvent}.
 * @param event {@link AuditEvent} instance.
 * @return true if the suppression matches {@link AuditEvent}.
 */
private boolean isMatch(AuditEvent event) {
    boolean match = false;
    if (isInScopeOfSuppression(event)) {
        final Matcher sourceNameMatcher = eventSourceRegexp.matcher(event.getSourceName());
        if (sourceNameMatcher.find()) {
            match = eventMessageRegexp == null
                || eventMessageRegexp.matcher(event.getMessage()).find();
        }
        else {
            match = event.getModuleId() != null
                && eventSourceRegexp.matcher(event.getModuleId()).find();
        }
    }
    return match;
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:SuppressWithPlainTextCommentFilter.java

示例6: fireErrors

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
/**
 * Notify all listeners about the errors in a file.
 *
 * @param fileName the audited file
 * @param errors the audit errors from the file
 */
@Override
public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
    final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
    boolean hasNonFilteredViolations = false;
    for (final LocalizedMessage element : errors) {
        final AuditEvent event = new AuditEvent(this, stripped, element);
        if (filters.accept(event)) {
            hasNonFilteredViolations = true;
            for (final AuditListener listener : listeners) {
                listener.addError(event);
            }
        }
    }
    if (hasNonFilteredViolations && cache != null) {
        cache.remove(fileName);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:Checker.java

示例7: testIsSuppressedWithAllArgument

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
@Test
public void testIsSuppressedWithAllArgument() throws Exception {
    createHolder("all", 100, 100, 350, 350);

    final Checker source = new Checker();
    final LocalizedMessage firstMessageForTest =
        new LocalizedMessage(100, 10, null, null, null, "id", MemberNameCheck.class, "msg");
    final AuditEvent firstEventForTest =
        new AuditEvent(source, "fileName", firstMessageForTest);
    assertFalse("Event is suppressed",
            SuppressWarningsHolder.isSuppressed(firstEventForTest));

    final LocalizedMessage secondMessageForTest =
        new LocalizedMessage(100, 150, null, null, null, "id", MemberNameCheck.class, "msg");
    final AuditEvent secondEventForTest =
        new AuditEvent(source, "fileName", secondMessageForTest);
    assertTrue("Event is not suppressed",
            SuppressWarningsHolder.isSuppressed(secondEventForTest));

    final LocalizedMessage thirdMessageForTest =
        new LocalizedMessage(200, 1, null, null, null, "id", MemberNameCheck.class, "msg");
    final AuditEvent thirdEventForTest =
        new AuditEvent(source, "fileName", thirdMessageForTest);
    assertTrue("Event is not suppressed",
            SuppressWarningsHolder.isSuppressed(thirdEventForTest));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:SuppressWarningsHolderTest.java

示例8: testAcceptOnMatch

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的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));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:SeverityMatchFilterTest.java

示例9: testAddErrorOnZeroColumns

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的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());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:XMLLoggerTest.java

示例10: testAddExceptionAfterFileStarted

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
@Test
public void testAddExceptionAfterFileStarted()
        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", null, null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", message);
    logger.addException(ev, new TestException("msg", new RuntimeException("msg")));

    logger.fileFinished(ev);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerException2.xml"), outStream);
    assertEquals("Invalid close count", 1, outStream.getCloseCount());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:XMLLoggerTest.java

示例11: testAddExceptionBeforeFileFinished

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
@Test
public void testAddExceptionBeforeFileFinished()
        throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, true);
    logger.auditStarted(null);
    final LocalizedMessage message =
            new LocalizedMessage(1, 1,
                    "messages.properties", null, null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", message);
    logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
    final AuditEvent fileFinishedEvent = new AuditEvent(this, "Test.java");
    logger.fileFinished(fileFinishedEvent);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerException3.xml"), outStream);
    assertEquals("Invalid close count", 1, outStream.getCloseCount());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:XMLLoggerTest.java

示例12: testAddExceptionBetweenFileStartedAndFinished

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
@Test
public void testAddExceptionBetweenFileStartedAndFinished()
        throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, true);
    logger.auditStarted(null);
    final LocalizedMessage message =
            new LocalizedMessage(1, 1,
                    "messages.properties", null, null, null, getClass(), null);
    final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
    logger.fileStarted(fileStartedEvent);
    final AuditEvent ev = new AuditEvent(this, "Test.java", message);
    logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
    final AuditEvent fileFinishedEvent = new AuditEvent(this, "Test.java");
    logger.fileFinished(fileFinishedEvent);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerException2.xml"), outStream);
    assertEquals("Invalid close count", 1, outStream.getCloseCount());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:XMLLoggerTest.java

示例13: testCtor

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
@Test
public void testCtor() throws UnsupportedEncodingException {
    final OutputStream infoStream = new ByteArrayOutputStream();
    final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
    final DefaultLogger dl = new DefaultLogger(infoStream, true, errorStream, true);
    dl.addException(new AuditEvent(5000, "myfile"), new IllegalStateException("upsss"));
    dl.auditFinished(new AuditEvent(6000, "myfile"));
    final String output = errorStream.toString(StandardCharsets.UTF_8.name());
    final LocalizedMessage addExceptionMessage = new LocalizedMessage(0,
            Definitions.CHECKSTYLE_BUNDLE, DefaultLogger.ADD_EXCEPTION_MESSAGE,
            new String[] {"myfile"}, null,
            getClass(), null);

    assertTrue("Invalid exception", output.contains(addExceptionMessage.getMessage()));
    assertTrue("Invalid exception class",
        output.contains("java.lang.IllegalStateException: upsss"));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:DefaultLoggerTest.java

示例14: testAcceptThrowsIllegalStateExceptionAsFileNotFound

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的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

示例15: format

import com.puppycrawl.tools.checkstyle.api.AuditEvent; //导入依赖的package包/类
@Override
public String format(AuditEvent event) {
    final String fileName = event.getFileName();
    final String message = event.getMessage();

    // avoid StringBuffer.expandCapacity
    final int bufLen = event.getFileName().length() + event.getMessage().length()
        + LENGTH_OF_ALL_SEPARATORS;
    final StringBuilder sb = new StringBuilder(bufLen);

    sb.append(fileName).append(':').append(event.getLine());
    if (event.getColumn() > 0) {
        sb.append(':').append(event.getColumn());
    }
    sb.append(": ").append(message);

    return sb.toString();
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:AuditEventUtFormatter.java


注:本文中的com.puppycrawl.tools.checkstyle.api.AuditEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。