Java Code Examples for com.puppycrawl.tools.checkstyle.api.AuditEvent#getMessage()

The following examples show how to use com.puppycrawl.tools.checkstyle.api.AuditEvent#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Auditor.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String getMessage(AuditEvent error) {

      String moduleId = error.getModuleId();

      if (moduleId == null) {
        RuleMetadata metaData = MetadataFactory.getRuleMetadata(error.getSourceName());
        if (metaData != null) {
          moduleId = metaData.getInternalName();
        }
      }

      final String message = error.getMessage();

      StringBuffer prefix = new StringBuffer();
      if (mAddRuleName) {
        prefix.append(getRuleName(error));
      }
      if (mAddModuleId && error.getModuleId() != null) {
        if (prefix.length() > 0) {
          prefix.append(" - "); //$NON-NLS-1$
        }
        prefix.append(error.getModuleId());
      }

      StringBuffer buf = new StringBuffer();
      if (prefix.length() > 0) {
        buf.append(prefix).append(": "); //$NON-NLS-1$
      }
      buf.append(message);

      return buf.toString();
    }
 
Example 2
Source File: CheckstyleAuditListener.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@VisibleForTesting
static String getMessage(AuditEvent event) {
    String result;
    try {
        result = event.getMessage();

    }
    catch (Exception ex) {
        LOG.warn("AuditEvent is created incorrectly. Exception happen during getMessage()", ex);
        result = null;
    }
    return result;
}
 
Example 3
Source File: CommonsLoggingListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** @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());
        }
    }
}
 
Example 4
Source File: CommonsLoggingListener.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** @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());
        }
    }
}
 
Example 5
Source File: CoderadarAuditListener.java    From coderadar with MIT License 5 votes vote down vote up
@Override
public void addError(AuditEvent evt) {
  if (evt.getSeverityLevel() != SeverityLevel.IGNORE) {
    Metric metric = new Metric("checkstyle:" + evt.getSourceName());
    Finding finding =
        new Finding(
            evt.getLine(), evt.getLine(), evt.getColumn(), evt.getColumn(), evt.getMessage());
    Long metricCount = metricCountExtractor.extractMetricCount(evt);
    metrics.addFinding(metric, finding, metricCount);
  }
}
 
Example 6
Source File: RepositoryMinerAudit.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
@Override
public void addError(AuditEvent event) {
	int checkerIndex = event.getSourceName().lastIndexOf('.') + 1;
	
	StyleProblem sp = new StyleProblem(event.getLine(), event.getColumn(), event.getMessage(),
			event.getSeverityLevel().getName(), event.getSourceName().substring(checkerIndex));
	fileErrors.get(currFile).add(sp);
}