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

The following examples show how to use com.puppycrawl.tools.checkstyle.api.AuditEvent#getFileName() . 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
@Override
public void fileStarted(AuditEvent event) {

  if (mMonitor.isCanceled()) {
    throw new OperationCanceledException();
  }

  // get the current IFile reference
  mResource = getFile(event.getFileName());
  mMarkerCount = 0;

  if (mResource != null) {

    // begin subtask
    if (mMonitorCounter == 0) {
      mMonitor.subTask(NLS.bind(Messages.Auditor_msgCheckingFile, mResource.getName()));
    }

    // increment monitor-counter
    this.mMonitorCounter++;
  } else {

    IPath filePath = new Path(event.getFileName());
    IPath dirPath = filePath.removeFileExtension().removeLastSegments(1);

    IPath projectPath = mProject.getLocation();
    if (projectPath.isPrefixOf(dirPath)) {
      // find the resource with a project relative path
      mResource = mProject.findMember(dirPath.removeFirstSegments(projectPath.segmentCount()));
    } else {
      // if the resource is not inside the project, take project
      // as resource - this should not happen
      mResource = mProject;
    }
  }
}
 
Example 2
Source File: CheckstyleAuditListener.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initResource(AuditEvent event) {
    if (currentResource == null) {
        final String absoluteFilename = event.getFileName();
        currentResource = fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(
                absoluteFilename));
    }
}
 
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: FilesFilter.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean accept(AuditEvent aEvent)
{
    final String fileName = aEvent.getFileName();
    return ((fileName == null) || !mFileRegexp.match(fileName));
}
 
Example 6
Source File: FilesFilter.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean accept(AuditEvent aEvent)
{
    final String fileName = aEvent.getFileName();
    return ((fileName == null) || !mFileRegexp.match(fileName));
}