Prefixes, filters, #512

This commit is contained in:
alexkravin 2015-01-11 14:09:47 +04:00
parent bb1b29851f
commit 5cfe30d7ad
14 changed files with 487 additions and 487 deletions

View File

@ -33,15 +33,15 @@ import java.util.StringTokenizer;
class CSVFilter implements IntFilter
{
/** filter set */
private final Set<IntFilter> mFilters = Sets.newHashSet();
private final Set<IntFilter> filters = Sets.newHashSet();
/**
* Adds a IntFilter to the set.
* @param aFilter the IntFilter to add.
* @param filter the IntFilter to add.
*/
public void addFilter(IntFilter aFilter)
public void addFilter(IntFilter filter)
{
mFilters.add(aFilter);
filters.add(filter);
}
/**
@ -50,7 +50,7 @@ class CSVFilter implements IntFilter
*/
protected Set<IntFilter> getFilters()
{
return mFilters;
return filters;
}
/**
@ -58,14 +58,14 @@ class CSVFilter implements IntFilter
* string. Each value is an integer, or a range of integers. A range of
* integers is of the form integer-integer, such as 1-10.
* Note: integers must be non-negative.
* @param aPattern the CSV string.
* @param pattern the CSV string.
* @throws NumberFormatException if a component substring does not
* contain a parsable integer.
*/
public CSVFilter(String aPattern)
public CSVFilter(String pattern)
throws NumberFormatException
{
final StringTokenizer tokenizer = new StringTokenizer(aPattern, ",");
final StringTokenizer tokenizer = new StringTokenizer(pattern, ",");
while (tokenizer.hasMoreTokens()) {
final String token = tokenizer.nextToken().trim();
final int index = token.indexOf("-");
@ -85,14 +85,14 @@ class CSVFilter implements IntFilter
/**
* Determines whether an Integer matches a CSV integer value.
* @param aInt the Integer to check.
* @return true if aInt is an Integer that matches a CSV value.
* @param int the Integer to check.
* @return true if int is an Integer that matches a CSV value.
*/
@Override
public boolean accept(int aInt)
public boolean accept(int intValue)
{
for (IntFilter filter : getFilters()) {
if (filter.accept(aInt)) {
if (filter.accept(intValue)) {
return true;
}
}
@ -102,21 +102,21 @@ class CSVFilter implements IntFilter
@Override
public String toString()
{
return mFilters.toString();
return filters.toString();
}
@Override
public int hashCode()
{
return mFilters.hashCode();
return filters.hashCode();
}
@Override
public boolean equals(Object aObject)
public boolean equals(Object object)
{
if (aObject instanceof CSVFilter) {
final CSVFilter other = (CSVFilter) aObject;
return this.mFilters.equals(other.mFilters);
if (object instanceof CSVFilter) {
final CSVFilter other = (CSVFilter) object;
return this.filters.equals(other.filters);
}
return false;
}

View File

@ -27,8 +27,8 @@ interface IntFilter
{
/**
* Determines whether or not a filtered Integer is accepted.
* @param aInt the Integer to filter.
* @return true if the aInt is accepted.
* @param int the Integer to filter.
* @return true if the int is accepted.
*/
boolean accept(int aInt);
boolean accept(int intValue);
}

View File

@ -25,42 +25,42 @@ package com.puppycrawl.tools.checkstyle.filters;
class IntMatchFilter implements IntFilter
{
/** the matching Integer */
private final int mMatchValue;
private final int matchValue;
/**
* Constructs a MatchFilter for an int.
* @param aMatchValue the matching int.
* @param matchValue the matching int.
*/
public IntMatchFilter(int aMatchValue)
public IntMatchFilter(int matchValue)
{
mMatchValue = aMatchValue;
this.matchValue = matchValue;
}
/** {@inheritDoc} */
@Override
public boolean accept(int aInt)
public boolean accept(int intValue)
{
return mMatchValue == aInt;
return matchValue == intValue;
}
@Override
public String toString()
{
return "IntMatchFilter[" + mMatchValue + "]";
return "IntMatchFilter[" + matchValue + "]";
}
@Override
public int hashCode()
{
return Integer.valueOf(mMatchValue).hashCode();
return Integer.valueOf(matchValue).hashCode();
}
@Override
public boolean equals(Object aObject)
public boolean equals(Object object)
{
if (aObject instanceof IntMatchFilter) {
final IntMatchFilter other = (IntMatchFilter) aObject;
return this.mMatchValue == other.mMatchValue;
if (object instanceof IntMatchFilter) {
final IntMatchFilter other = (IntMatchFilter) object;
return this.matchValue == other.matchValue;
}
return false;
}

View File

@ -28,44 +28,44 @@ class IntRangeFilter implements IntFilter
private static final int HASH_MULT = 29;
/** lower bound of the range */
private final Integer mLowerBound;
private final Integer lowerBound;
/** upper bound of the range */
private final Integer mUpperBound;
private final Integer upperBound;
/**
* Constructs a <code>IntRangeFilter</code> with a
* lower bound and an upper bound for the range.
* @param aLowerBound the lower bound of the range.
* @param aUpperBound the upper bound of the range.
* @param lowerBound the lower bound of the range.
* @param upperBound the upper bound of the range.
*/
public IntRangeFilter(int aLowerBound, int aUpperBound)
public IntRangeFilter(int lowerBound, int upperBound)
{
mLowerBound = aLowerBound;
mUpperBound = aUpperBound;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
}
/** {@inheritDoc} */
@Override
public boolean accept(int aInt)
public boolean accept(int intValue)
{
return ((mLowerBound.compareTo(aInt) <= 0)
&& (mUpperBound.compareTo(aInt) >= 0));
return ((lowerBound.compareTo(intValue) <= 0)
&& (upperBound.compareTo(intValue) >= 0));
}
@Override
public int hashCode()
{
return HASH_MULT * mLowerBound.intValue() + mUpperBound.intValue();
return HASH_MULT * lowerBound.intValue() + upperBound.intValue();
}
@Override
public boolean equals(Object aObject)
public boolean equals(Object object)
{
if (aObject instanceof IntRangeFilter) {
final IntRangeFilter other = (IntRangeFilter) aObject;
return (this.mLowerBound.equals(other.mLowerBound)
&& this.mUpperBound.equals(other.mUpperBound));
if (object instanceof IntRangeFilter) {
final IntRangeFilter other = (IntRangeFilter) object;
return (this.lowerBound.equals(other.lowerBound)
&& this.upperBound.equals(other.upperBound));
}
return false;
}
@ -73,7 +73,7 @@ class IntRangeFilter implements IntFilter
@Override
public String toString()
{
return "IntRangeFilter[" + mLowerBound + "," + mUpperBound + "]";
return "IntRangeFilter[" + lowerBound + "," + upperBound + "]";
}
}

View File

@ -34,39 +34,39 @@ public class SeverityMatchFilter
implements Filter
{
/** the severity level to accept */
private SeverityLevel mSeverityLevel = SeverityLevel.ERROR;
private SeverityLevel severityLevel = SeverityLevel.ERROR;
/** whether to accept or reject on severity matches */
private boolean mAcceptOnMatch = true;
private boolean acceptOnMatch = true;
/**
* Sets the severity level. The string should be one of the names
* defined in the <code>SeverityLevel</code> class.
*
* @param aSeverity The new severity level
* @param severity The new severity level
* @see SeverityLevel
*/
public final void setSeverity(String aSeverity)
public final void setSeverity(String severity)
{
mSeverityLevel = SeverityLevel.getInstance(aSeverity);
severityLevel = SeverityLevel.getInstance(severity);
}
/**
* Sets whether to accept or reject on matching severity level.
* @param aAcceptOnMatch if true, accept on matches; if
* @param acceptOnMatch if true, accept on matches; if
* false, reject on matches.
*/
public final void setAcceptOnMatch(boolean aAcceptOnMatch)
public final void setAcceptOnMatch(boolean acceptOnMatch)
{
mAcceptOnMatch = aAcceptOnMatch;
this.acceptOnMatch = acceptOnMatch;
}
/** {@inheritDoc} */
@Override
public boolean accept(AuditEvent aEvent)
public boolean accept(AuditEvent event)
{
final boolean result = mSeverityLevel.equals(aEvent.getSeverityLevel());
if (mAcceptOnMatch) {
final boolean result = severityLevel.equals(event.getSeverityLevel());
if (acceptOnMatch) {
return result;
}
return !result;

View File

@ -44,122 +44,122 @@ public class SuppressElement
private static final int HASH_MULT = 29;
/** the regexp to match file names against */
private final Pattern mFileRegexp;
private final Pattern fileRegexp;
/** the pattern for file names*/
private final String mFilePattern;
private final String filePattern;
/** the regexp to match check names against */
private Pattern mCheckRegexp;
private Pattern checkRegexp;
/** the pattern for check class names*/
private String mCheckPattern;
private String checkPattern;
/** module id filter. */
private String mModuleId;
private String moduleId;
/** line number filter */
private CSVFilter mLineFilter;
private CSVFilter lineFilter;
/** CSV for line number filter */
private String mLinesCSV;
private String linesCSV;
/** column number filter */
private CSVFilter mColumnFilter;
private CSVFilter columnFilter;
/** CSV for column number filter */
private String mColumnsCSV;
private String columnsCSV;
/**
* Constructs a <code>SuppressElement</code> for a
* file name pattern. Must either call {@link #setColumns(String)} or
* {@link #setModuleId(String)} before using this object.
* @param aFiles regular expression for names of filtered files.
* @param files regular expression for names of filtered files.
* @throws PatternSyntaxException if there is an error.
*/
public SuppressElement(String aFiles)
public SuppressElement(String files)
throws PatternSyntaxException
{
mFilePattern = aFiles;
mFileRegexp = Utils.getPattern(aFiles);
filePattern = files;
fileRegexp = Utils.getPattern(files);
}
/**
* Set the check class pattern.
* @param aChecks regular expression for filtered check classes.
* @param checks regular expression for filtered check classes.
*/
public void setChecks(final String aChecks)
public void setChecks(final String checks)
{
mCheckPattern = aChecks;
mCheckRegexp = Utils.getPattern(aChecks);
checkPattern = checks;
checkRegexp = Utils.getPattern(checks);
}
/**
* Set the module id for filtering. Cannot be null.
* @param aModuleId the id
* @param moduleId the id
*/
public void setModuleId(final String aModuleId)
public void setModuleId(final String moduleId)
{
mModuleId = aModuleId;
this.moduleId = moduleId;
}
/**
* Sets the CSV values and ranges for line number filtering.
* E.g. "1,7-15,18".
* @param aLines CSV values and ranges for line number filtering.
* @param lines CSV values and ranges for line number filtering.
*/
public void setLines(String aLines)
public void setLines(String lines)
{
mLinesCSV = aLines;
if (aLines != null) {
mLineFilter = new CSVFilter(aLines);
linesCSV = lines;
if (lines != null) {
lineFilter = new CSVFilter(lines);
}
else {
mLineFilter = null;
lineFilter = null;
}
}
/**
* Sets the CSV values and ranges for column number filtering.
* E.g. "1,7-15,18".
* @param aColumns CSV values and ranges for column number filtering.
* @param columns CSV values and ranges for column number filtering.
*/
public void setColumns(String aColumns)
public void setColumns(String columns)
{
mColumnsCSV = aColumns;
if (aColumns != null) {
mColumnFilter = new CSVFilter(aColumns);
columnsCSV = columns;
if (columns != null) {
columnFilter = new CSVFilter(columns);
}
else {
mColumnFilter = null;
columnFilter = null;
}
}
/** {@inheritDoc} */
@Override
public boolean accept(AuditEvent aEvent)
public boolean accept(AuditEvent event)
{
// file and check match?
if ((aEvent.getFileName() == null)
|| !mFileRegexp.matcher(aEvent.getFileName()).find()
|| (aEvent.getLocalizedMessage() == null)
|| ((mModuleId != null) && !mModuleId.equals(aEvent
if ((event.getFileName() == null)
|| !fileRegexp.matcher(event.getFileName()).find()
|| (event.getLocalizedMessage() == null)
|| ((moduleId != null) && !moduleId.equals(event
.getModuleId()))
|| ((mCheckRegexp != null) && !mCheckRegexp.matcher(
aEvent.getSourceName()).find()))
|| ((checkRegexp != null) && !checkRegexp.matcher(
event.getSourceName()).find()))
{
return true;
}
// reject if no line/column matching
if ((mLineFilter == null) && (mColumnFilter == null)) {
if ((lineFilter == null) && (columnFilter == null)) {
return false;
}
if (mLineFilter != null && mLineFilter.accept(aEvent.getLine())) {
if (lineFilter != null && lineFilter.accept(event.getLine())) {
return false;
}
if (mColumnFilter != null && mColumnFilter.accept(aEvent.getColumn())) {
if (columnFilter != null && columnFilter.accept(event.getColumn())) {
return false;
}
return true;
@ -168,78 +168,78 @@ public class SuppressElement
@Override
public String toString()
{
return "SuppressElement[files=" + mFilePattern + ",checks="
+ mCheckPattern + ",lines=" + mLinesCSV + ",columns="
+ mColumnsCSV + "]";
return "SuppressElement[files=" + filePattern + ",checks="
+ checkPattern + ",lines=" + linesCSV + ",columns="
+ columnsCSV + "]";
}
@Override
public int hashCode()
{
int result = HASH_MULT * mFilePattern.hashCode();
if (mCheckPattern != null) {
result = HASH_MULT * result + mCheckPattern.hashCode();
int result = HASH_MULT * filePattern.hashCode();
if (checkPattern != null) {
result = HASH_MULT * result + checkPattern.hashCode();
}
if (mModuleId != null) {
result = HASH_MULT * result + mModuleId.hashCode();
if (moduleId != null) {
result = HASH_MULT * result + moduleId.hashCode();
}
if (mLinesCSV != null) {
result = HASH_MULT * result + mLinesCSV.hashCode();
if (linesCSV != null) {
result = HASH_MULT * result + linesCSV.hashCode();
}
if (mColumnsCSV != null) {
result = HASH_MULT * result + mColumnsCSV.hashCode();
if (columnsCSV != null) {
result = HASH_MULT * result + columnsCSV.hashCode();
}
return result;
}
@Override
public boolean equals(Object aObject)
public boolean equals(Object object)
{
if (aObject instanceof SuppressElement) {
final SuppressElement other = (SuppressElement) aObject;
if (object instanceof SuppressElement) {
final SuppressElement other = (SuppressElement) object;
// same file pattern?
if (!this.mFilePattern.equals(other.mFilePattern)) {
if (!this.filePattern.equals(other.filePattern)) {
return false;
}
// same check pattern?
if (mCheckPattern != null) {
if (!mCheckPattern.equals(other.mCheckPattern)) {
if (checkPattern != null) {
if (!checkPattern.equals(other.checkPattern)) {
return false;
}
}
else if (other.mCheckPattern != null) {
else if (other.checkPattern != null) {
return false;
}
// same module id?
if (mModuleId != null) {
if (!mModuleId.equals(other.mModuleId)) {
if (moduleId != null) {
if (!moduleId.equals(other.moduleId)) {
return false;
}
}
else if (other.mModuleId != null) {
else if (other.moduleId != null) {
return false;
}
// same line number filter?
if (mLineFilter != null) {
if (!mLineFilter.equals(other.mLineFilter)) {
if (lineFilter != null) {
if (!lineFilter.equals(other.lineFilter)) {
return false;
}
}
else if (other.mLineFilter != null) {
else if (other.lineFilter != null) {
return false;
}
// same column number filter?
if (mColumnFilter != null) {
if (!mColumnFilter.equals(other.mColumnFilter)) {
if (columnFilter != null) {
if (!columnFilter.equals(other.columnFilter)) {
return false;
}
}
else if (other.mColumnFilter != null) {
else if (other.columnFilter != null) {
return false;
}

View File

@ -34,9 +34,9 @@ public class SuppressWarningsFilter
{
/** {@inheritDoc} */
@Override
public boolean accept(AuditEvent aEvent)
public boolean accept(AuditEvent event)
{
return !SuppressWarningsHolder.isSuppressed(aEvent.getSourceName(),
aEvent.getLine(), aEvent.getColumn());
return !SuppressWarningsHolder.isSuppressed(event.getSourceName(),
event.getLine(), event.getColumn());
}
}

View File

@ -82,48 +82,48 @@ public class SuppressWithNearbyCommentFilter
public class Tag implements Comparable<Tag>
{
/** The text of the tag. */
private final String mText;
private final String text;
/** The first line where warnings may be suppressed. */
private int mFirstLine;
private int firstLine;
/** The last line where warnings may be suppressed. */
private int mLastLine;
private int lastLine;
/** The parsed check regexp, expanded for the text of this tag. */
private Pattern mTagCheckRegexp;
private Pattern tagCheckRegexp;
/** The parsed message regexp, expanded for the text of this tag. */
private Pattern mTagMessageRegexp;
private Pattern tagMessageRegexp;
/**
* Constructs a tag.
* @param aText the text of the suppression.
* @param aLine the line number.
* @throws ConversionException if unable to parse expanded aText.
* @param text the text of the suppression.
* @param line the line number.
* @throws ConversionException if unable to parse expanded text.
* on.
*/
public Tag(String aText, int aLine)
public Tag(String text, int line)
throws ConversionException
{
mText = aText;
this.text = text;
mTagCheckRegexp = mCheckRegexp;
tagCheckRegexp = checkRegexp;
//Expand regexp for check and message
//Does not intern Patterns with Utils.getPattern()
String format = "";
try {
format = expandFromComment(aText, mCheckFormat, mCommentRegexp);
mTagCheckRegexp = Pattern.compile(format);
if (mMessageFormat != null) {
format = expandFromComment(
aText, mMessageFormat, mCommentRegexp);
mTagMessageRegexp = Pattern.compile(format);
format = expandFrocomment(text, checkFormat, commentRegexp);
tagCheckRegexp = Pattern.compile(format);
if (messageFormat != null) {
format = expandFrocomment(
text, messageFormat, commentRegexp);
tagMessageRegexp = Pattern.compile(format);
}
int influence = 0;
if (mInfluenceFormat != null) {
format = expandFromComment(
aText, mInfluenceFormat, mCommentRegexp);
if (influenceFormat != null) {
format = expandFrocomment(
text, influenceFormat, commentRegexp);
try {
if (format.startsWith("+")) {
format = format.substring(1);
@ -132,17 +132,17 @@ public class SuppressWithNearbyCommentFilter
}
catch (final NumberFormatException e) {
throw new ConversionException(
"unable to parse influence from '" + aText
+ "' using " + mInfluenceFormat, e);
"unable to parse influence from '" + text
+ "' using " + influenceFormat, e);
}
}
if (influence >= 0) {
mFirstLine = aLine;
mLastLine = aLine + influence;
firstLine = line;
lastLine = line + influence;
}
else {
mFirstLine = aLine + influence;
mLastLine = aLine;
firstLine = line + influence;
lastLine = line;
}
}
catch (final PatternSyntaxException e) {
@ -155,63 +155,63 @@ public class SuppressWithNearbyCommentFilter
/** @return the text of the tag. */
public String getText()
{
return mText;
return text;
}
/** @return the line number of the first suppressed line. */
public int getFirstLine()
{
return mFirstLine;
return firstLine;
}
/** @return the line number of the last suppressed line. */
public int getLastLine()
{
return mLastLine;
return lastLine;
}
/**
* Compares the position of this tag in the file
* with the position of another tag.
* @param aOther the tag to compare with this one.
* @param other the tag to compare with this one.
* @return a negative number if this tag is before the other tag,
* 0 if they are at the same position, and a positive number if this
* tag is after the other tag.
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Tag aOther)
public int compareTo(Tag other)
{
if (mFirstLine == aOther.mFirstLine) {
return mLastLine - aOther.mLastLine;
if (firstLine == other.firstLine) {
return lastLine - other.lastLine;
}
return (mFirstLine - aOther.mFirstLine);
return (firstLine - other.firstLine);
}
/**
* Determines whether the source of an audit event
* matches the text of this tag.
* @param aEvent the <code>AuditEvent</code> to check.
* @return true if the source of aEvent matches the text of this tag.
* @param event the <code>AuditEvent</code> to check.
* @return true if the source of event matches the text of this tag.
*/
public boolean isMatch(AuditEvent aEvent)
public boolean isMatch(AuditEvent event)
{
final int line = aEvent.getLine();
if (line < mFirstLine) {
final int line = event.getLine();
if (line < firstLine) {
return false;
}
if (line > mLastLine) {
if (line > lastLine) {
return false;
}
final Matcher tagMatcher =
mTagCheckRegexp.matcher(aEvent.getSourceName());
tagCheckRegexp.matcher(event.getSourceName());
if (tagMatcher.find()) {
return true;
}
if (mTagMessageRegexp != null) {
if (tagMessageRegexp != null) {
final Matcher messageMatcher =
mTagMessageRegexp.matcher(aEvent.getMessage());
tagMessageRegexp.matcher(event.getMessage());
return messageMatcher.find();
}
return false;
@ -219,24 +219,24 @@ public class SuppressWithNearbyCommentFilter
/**
* Expand based on a matching comment.
* @param aComment the comment.
* @param aString the string to expand.
* @param aRegexp the parsed expander.
* @param comment the comment.
* @param string the string to expand.
* @param regexp the parsed expander.
* @return the expanded string
*/
private String expandFromComment(
String aComment,
String aString,
Pattern aRegexp)
private String expandFrocomment(
String comment,
String string,
Pattern regexp)
{
final Matcher matcher = aRegexp.matcher(aComment);
final Matcher matcher = regexp.matcher(comment);
// Match primarily for effect.
if (!matcher.find()) {
///CLOVER:OFF
return aString;
return string;
///CLOVER:ON
}
String result = aString;
String result = string;
for (int i = 0; i <= matcher.groupCount(); i++) {
// $n expands comment match like in Pattern.subst().
result = result.replaceAll("\\$" + i, matcher.group(i));
@ -267,30 +267,30 @@ public class SuppressWithNearbyCommentFilter
private static final String DEFAULT_INFLUENCE_FORMAT = "0";
/** Whether to look for trigger in C-style comments. */
private boolean mCheckC = true;
private boolean checkC = true;
/** Whether to look for trigger in C++-style comments. */
private boolean mCheckCPP = true;
private boolean checkCPP = true;
/** Parsed comment regexp that marks checkstyle suppression region. */
private Pattern mCommentRegexp;
private Pattern commentRegexp;
/** The comment pattern that triggers suppression. */
private String mCheckFormat;
private String checkFormat;
/** The parsed check regexp. */
private Pattern mCheckRegexp;
private Pattern checkRegexp;
/** The message format to suppress. */
private String mMessageFormat;
private String messageFormat;
/** The influence of the suppression comment. */
private String mInfluenceFormat;
private String influenceFormat;
//TODO: Investigate performance improvement with array
/** Tagged comments */
private final List<Tag> mTags = Lists.newArrayList();
private final List<Tag> tags = Lists.newArrayList();
/**
* References the current FileContents for this filter.
@ -299,7 +299,7 @@ public class SuppressWithNearbyCommentFilter
* and FileContentsHolder are reassigned to the next FileContents,
* at which time filtering for the current FileContents is finished.
*/
private WeakReference<FileContents> mFileContentsReference =
private WeakReference<FileContents> fileContentsReference =
new WeakReference<FileContents>(null);
/**
@ -325,112 +325,112 @@ public class SuppressWithNearbyCommentFilter
/**
* Set the format for a comment that turns off reporting.
* @param aFormat a <code>String</code> value.
* @throws ConversionException unable to parse aFormat.
* @param format a <code>String</code> value.
* @throws ConversionException unable to parse format.
*/
public void setCommentFormat(String aFormat)
public void setCommentFormat(String format)
throws ConversionException
{
try {
mCommentRegexp = Utils.getPattern(aFormat);
commentRegexp = Utils.getPattern(format);
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
}
/** @return the FileContents for this filter. */
public FileContents getFileContents()
{
return mFileContentsReference.get();
return fileContentsReference.get();
}
/**
* Set the FileContents for this filter.
* @param aFileContents the FileContents for this filter.
* @param fileContents the FileContents for this filter.
*/
public void setFileContents(FileContents aFileContents)
public void setFileContents(FileContents fileContents)
{
mFileContentsReference = new WeakReference<FileContents>(aFileContents);
fileContentsReference = new WeakReference<FileContents>(fileContents);
}
/**
* Set the format for a check.
* @param aFormat a <code>String</code> value
* @throws ConversionException unable to parse aFormat
* @param format a <code>String</code> value
* @throws ConversionException unable to parse format
*/
public void setCheckFormat(String aFormat)
public void setCheckFormat(String format)
throws ConversionException
{
try {
mCheckRegexp = Utils.getPattern(aFormat);
mCheckFormat = aFormat;
checkRegexp = Utils.getPattern(format);
checkFormat = format;
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
}
/**
* Set the format for a message.
* @param aFormat a <code>String</code> value
* @throws ConversionException unable to parse aFormat
* @param format a <code>String</code> value
* @throws ConversionException unable to parse format
*/
public void setMessageFormat(String aFormat)
public void setMessageFormat(String format)
throws ConversionException
{
// check that aFormat parses
// check that format parses
try {
Utils.getPattern(aFormat);
Utils.getPattern(format);
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
mMessageFormat = aFormat;
messageFormat = format;
}
/**
* Set the format for the influence of this check.
* @param aFormat a <code>String</code> value
* @throws ConversionException unable to parse aFormat
* @param format a <code>String</code> value
* @throws ConversionException unable to parse format
*/
public void setInfluenceFormat(String aFormat)
public void setInfluenceFormat(String format)
throws ConversionException
{
// check that aFormat parses
// check that format parses
try {
Utils.getPattern(aFormat);
Utils.getPattern(format);
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
mInfluenceFormat = aFormat;
influenceFormat = format;
}
/**
* Set whether to look in C++ comments.
* @param aCheckCPP <code>true</code> if C++ comments are checked.
* @param checkCPP <code>true</code> if C++ comments are checked.
*/
public void setCheckCPP(boolean aCheckCPP)
public void setCheckCPP(boolean checkCPP)
{
mCheckCPP = aCheckCPP;
this.checkCPP = checkCPP;
}
/**
* Set whether to look in C comments.
* @param aCheckC <code>true</code> if C comments are checked.
* @param checkC <code>true</code> if C comments are checked.
*/
public void setCheckC(boolean aCheckC)
public void setCheckC(boolean checkC)
{
mCheckC = aCheckC;
this.checkC = checkC;
}
/** {@inheritDoc} */
@Override
public boolean accept(AuditEvent aEvent)
public boolean accept(AuditEvent event)
{
if (aEvent.getLocalizedMessage() == null) {
if (event.getLocalizedMessage() == null) {
return true; // A special event.
}
@ -446,9 +446,9 @@ public class SuppressWithNearbyCommentFilter
setFileContents(currentContents);
tagSuppressions();
}
for (final Iterator<Tag> iter = mTags.iterator(); iter.hasNext();) {
for (final Iterator<Tag> iter = tags.iterator(); iter.hasNext();) {
final Tag tag = iter.next();
if (tag.isMatch(aEvent)) {
if (tag.isMatch(event)) {
return false;
}
}
@ -461,29 +461,29 @@ public class SuppressWithNearbyCommentFilter
*/
private void tagSuppressions()
{
mTags.clear();
tags.clear();
final FileContents contents = getFileContents();
if (mCheckCPP) {
if (checkCPP) {
tagSuppressions(contents.getCppComments().values());
}
if (mCheckC) {
if (checkC) {
final Collection<List<TextBlock>> cComments =
contents.getCComments().values();
for (final List<TextBlock> element : cComments) {
tagSuppressions(element);
}
}
Collections.sort(mTags);
Collections.sort(tags);
}
/**
* Appends the suppressions in a collection of comments to the full
* set of suppression tags.
* @param aComments the set of comments.
* @param comments the set of comments.
*/
private void tagSuppressions(Collection<TextBlock> aComments)
private void tagSuppressions(Collection<TextBlock> comments)
{
for (final TextBlock comment : aComments) {
for (final TextBlock comment : comments) {
final int startLineNo = comment.getStartLineNo();
final String[] text = comment.getText();
tagCommentLine(text[0], startLineNo);
@ -496,25 +496,25 @@ public class SuppressWithNearbyCommentFilter
/**
* Tags a string if it matches the format for turning
* checkstyle reporting on or the format for turning reporting off.
* @param aText the string to tag.
* @param aLine the line number of aText.
* @param text the string to tag.
* @param line the line number of text.
*/
private void tagCommentLine(String aText, int aLine)
private void tagCommentLine(String text, int line)
{
final Matcher matcher = mCommentRegexp.matcher(aText);
final Matcher matcher = commentRegexp.matcher(text);
if (matcher.find()) {
addTag(matcher.group(0), aLine);
addTag(matcher.group(0), line);
}
}
/**
* Adds a comment suppression <code>Tag</code> to the list of all tags.
* @param aText the text of the tag.
* @param aLine the line number of the tag.
* @param text the text of the tag.
* @param line the line number of the tag.
*/
private void addTag(String aText, int aLine)
private void addTag(String text, int line)
{
final Tag tag = new Tag(aText, aLine);
mTags.add(tag);
final Tag tag = new Tag(text, line);
tags.add(tag);
}
}

View File

@ -37,21 +37,21 @@ import org.apache.commons.beanutils.ConversionException;
/**
* <p>
* A filter that uses comments to suppress audit events.
* A filter that uses coonts to suppress audit events.
* </p>
* <p>
* Rationale:
* Sometimes there are legitimate reasons for violating a check. When
* this is a matter of the code in question and not personal
* preference, the best place to override the policy is in the code
* itself. Semi-structured comments can be associated with the check.
* itself. Semi-structured coonts can be associated with the check.
* This is sometimes superior to a separate suppressions file, which
* must be kept up-to-date as the source file is edited.
* </p>
* <p>
* Usage:
* This check only works in conjunction with the FileContentsHolder module
* since that module makes the suppression comments in the .java
* since that module makes the suppression coonts in the .java
* files available <i>sub rosa</i>.
* </p>
* @see FileContentsHolder
@ -63,7 +63,7 @@ public class SuppressionCommentFilter
implements Filter
{
/**
* A Tag holds a suppression comment and its location, and determines
* A Tag holds a suppression coont and its location, and deterones
* whether the supression turns checkstyle reporting on or off.
* @author Rick Giles
*/
@ -71,72 +71,72 @@ public class SuppressionCommentFilter
implements Comparable<Tag>
{
/** The text of the tag. */
private final String mText;
private final String text;
/** The line number of the tag. */
private final int mLine;
private final int line;
/** The column number of the tag. */
private final int mColumn;
private final int column;
/** Determines whether the suppression turns checkstyle reporting on. */
private final boolean mOn;
/** Deterones whether the suppression turns checkstyle reporting on. */
private final boolean on;
/** The parsed check regexp, expanded for the text of this tag. */
private Pattern mTagCheckRegexp;
private Pattern tagCheckRegexp;
/** The parsed message regexp, expanded for the text of this tag. */
private Pattern mTagMessageRegexp;
private Pattern tagMessageRegexp;
/**
* Constructs a tag.
* @param aLine the line number.
* @param aColumn the column number.
* @param aText the text of the suppression.
* @param aOn <code>true</code> if the tag turns checkstyle reporting.
* @throws ConversionException if unable to parse expanded aText.
* @param line the line number.
* @param column the column number.
* @param text the text of the suppression.
* @param on <code>true</code> if the tag turns checkstyle reporting.
* @throws ConversionException if unable to parse expanded text.
* on.
*/
public Tag(int aLine, int aColumn, String aText, boolean aOn)
public Tag(int line, int column, String text, boolean on)
throws ConversionException
{
mLine = aLine;
mColumn = aColumn;
mText = aText;
mOn = aOn;
this.line = line;
this.column = column;
this.text = text;
this.on = on;
mTagCheckRegexp = mCheckRegexp;
tagCheckRegexp = checkRegexp;
//Expand regexp for check and message
//Does not intern Patterns with Utils.getPattern()
String format = "";
try {
if (aOn) {
if (on) {
format =
expandFromComment(aText, mCheckFormat, mOnRegexp);
mTagCheckRegexp = Pattern.compile(format);
if (mMessageFormat != null) {
expandFromCoont(text, checkFormat, onRegexp);
tagCheckRegexp = Pattern.compile(format);
if (messageFormat != null) {
format =
expandFromComment(aText, mMessageFormat, mOnRegexp);
mTagMessageRegexp = Pattern.compile(format);
expandFromCoont(text, messageFormat, onRegexp);
tagMessageRegexp = Pattern.compile(format);
}
}
else {
format =
expandFromComment(aText, mCheckFormat, mOffRegexp);
mTagCheckRegexp = Pattern.compile(format);
if (mMessageFormat != null) {
expandFromCoont(text, checkFormat, offRegexp);
tagCheckRegexp = Pattern.compile(format);
if (messageFormat != null) {
format =
expandFromComment(
aText,
mMessageFormat,
mOffRegexp);
mTagMessageRegexp = Pattern.compile(format);
expandFromCoont(
text,
messageFormat,
offRegexp);
tagMessageRegexp = Pattern.compile(format);
}
}
}
catch (final PatternSyntaxException e) {
throw new ConversionException(
"unable to parse expanded comment " + format,
"unable to parse expanded coont " + format,
e);
}
}
@ -144,69 +144,69 @@ public class SuppressionCommentFilter
/** @return the text of the tag. */
public String getText()
{
return mText;
return text;
}
/** @return the line number of the tag in the source file. */
public int getLine()
{
return mLine;
return line;
}
/**
* Determines the column number of the tag in the source file.
* Will be 0 for all lines of multiline comment, except the
* Deterones the column number of the tag in the source file.
* Will be 0 for all lines of multiline coont, except the
* first line.
* @return the column number of the tag in the source file.
*/
public int getColumn()
{
return mColumn;
return column;
}
/**
* Determines whether the suppression turns checkstyle reporting on or
* Deterones whether the suppression turns checkstyle reporting on or
* off.
* @return <code>true</code>if the suppression turns reporting on.
*/
public boolean isOn()
{
return mOn;
return on;
}
/**
* Compares the position of this tag in the file
* with the position of another tag.
* @param aObject the tag to compare with this one.
* @return a negative number if this tag is before the other tag,
* @param object the tag to compare with this one.
* @return onegative number if this tag is before the other tag,
* 0 if they are at the same position, and a positive number if this
* tag is after the other tag.
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Tag aObject)
public int compareTo(Tag object)
{
if (mLine == aObject.mLine) {
return mColumn - aObject.mColumn;
if (line == object.line) {
return column - object.column;
}
return (mLine - aObject.mLine);
return (line - object.line);
}
/**
* Determines whether the source of an audit event
* Deterones whether the source of an audit event
* matches the text of this tag.
* @param aEvent the <code>AuditEvent</code> to check.
* @return true if the source of aEvent matches the text of this tag.
* @param event the <code>AuditEvent</code> to check.
* @return true if the source of event matches the text of this tag.
*/
public boolean isMatch(AuditEvent aEvent)
public boolean isMatch(AuditEvent event)
{
final Matcher tagMatcher =
mTagCheckRegexp.matcher(aEvent.getSourceName());
tagCheckRegexp.matcher(event.getSourceName());
if (tagMatcher.find()) {
if (mTagMessageRegexp != null) {
if (tagMessageRegexp != null) {
final Matcher messageMatcher =
mTagMessageRegexp.matcher(aEvent.getMessage());
tagMessageRegexp.matcher(event.getMessage());
return messageMatcher.find();
}
return true;
@ -215,27 +215,27 @@ public class SuppressionCommentFilter
}
/**
* Expand based on a matching comment.
* @param aComment the comment.
* @param aString the string to expand.
* @param aRegexp the parsed expander.
* Expand based on a matching coont.
* @param coont the comont.
* @param string the string to expand.
* @param regexp the parsed expander.
* @return the expanded string
*/
private String expandFromComment(
String aComment,
String aString,
Pattern aRegexp)
private String expandFromCoont(
String coont,
String string,
Pattern regexp)
{
final Matcher matcher = aRegexp.matcher(aComment);
final Matcher matcher = regexp.matcher(coont);
// Match primarily for effect.
if (!matcher.find()) {
///CLOVER:OFF
return aString;
return string;
///CLOVER:ON
}
String result = aString;
String result = string;
for (int i = 0; i <= matcher.groupCount(); i++) {
// $n expands comment match like in Pattern.subst().
// $n expands coont match like in Pattern.subst().
result = result.replaceAll("\\$" + i, matcher.group(i));
}
return result;
@ -258,30 +258,30 @@ public class SuppressionCommentFilter
/** Control all checks */
private static final String DEFAULT_CHECK_FORMAT = ".*";
/** Whether to look in comments of the C type. */
private boolean mCheckC = true;
/** Whether to look in coonts of the C type. */
private boolean checkC = true;
/** Whether to look in comments of the C++ type. */
private boolean mCheckCPP = true;
/** Whether to look in coonts of the C++ type. */
private boolean checkCPP = true;
/** Parsed comment regexp that turns checkstyle reporting off. */
private Pattern mOffRegexp;
/** Parsed coont regexp that turns checkstyle reporting off. */
private Pattern offRegexp;
/** Parsed comment regexp that turns checkstyle reporting on. */
private Pattern mOnRegexp;
/** Parsed coont regexp that turns checkstyle reporting on. */
private Pattern onRegexp;
/** The check format to suppress. */
private String mCheckFormat;
private String checkFormat;
/** The parsed check regexp. */
private Pattern mCheckRegexp;
private Pattern checkRegexp;
/** The message format to suppress. */
private String mMessageFormat;
private String messageFormat;
//TODO: Investigate performance improvement with array
/** Tagged comments */
private final List<Tag> mTags = Lists.newArrayList();
//TODO: Investigate perforonce improveont with array
/** Tagged coonts */
private final List<Tag> tags = Lists.newArrayList();
/**
* References the current FileContents for this filter.
@ -290,12 +290,12 @@ public class SuppressionCommentFilter
* and FileContentsHolder are reassigned to the next FileContents,
* at which time filtering for the current FileContents is finished.
*/
private WeakReference<FileContents> mFileContentsReference =
private WeakReference<FileContents> fileContentsReference =
new WeakReference<FileContents>(null);
/**
* Constructs a SuppressionCommentFilter.
* Initializes comment on, comment off, and check formats
* Constructs a SuppressionCoontFilter.
* Initializes coont on, comont off, and check formats
* to defaults.
*/
public SuppressionCommentFilter()
@ -306,111 +306,111 @@ public class SuppressionCommentFilter
}
/**
* Set the format for a comment that turns off reporting.
* @param aFormat a <code>String</code> value.
* @throws ConversionException unable to parse aFormat.
* Set the format for a coont that turns off reporting.
* @param format a <code>String</code> value.
* @throws ConversionException unable to parse format.
*/
public void setOffCommentFormat(String aFormat)
public void setOffCommentFormat(String format)
throws ConversionException
{
try {
mOffRegexp = Utils.getPattern(aFormat);
offRegexp = Utils.getPattern(format);
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
}
/**
* Set the format for a comment that turns on reporting.
* @param aFormat a <code>String</code> value
* @throws ConversionException unable to parse aFormat
* Set the format for a coont that turns on reporting.
* @param format a <code>String</code> value
* @throws ConversionException unable to parse format
*/
public void setOnCommentFormat(String aFormat)
public void setOnCommentFormat(String format)
throws ConversionException
{
try {
mOnRegexp = Utils.getPattern(aFormat);
onRegexp = Utils.getPattern(format);
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
}
/** @return the FileContents for this filter. */
public FileContents getFileContents()
{
return mFileContentsReference.get();
return fileContentsReference.get();
}
/**
* Set the FileContents for this filter.
* @param aFileContents the FileContents for this filter.
* @param fileContents the FileContents for this filter.
*/
public void setFileContents(FileContents aFileContents)
public void setFileContents(FileContents fileContents)
{
mFileContentsReference = new WeakReference<FileContents>(aFileContents);
fileContentsReference = new WeakReference<FileContents>(fileContents);
}
/**
* Set the format for a check.
* @param aFormat a <code>String</code> value
* @throws ConversionException unable to parse aFormat
* @param format a <code>String</code> value
* @throws ConversionException unable to parse format
*/
public void setCheckFormat(String aFormat)
public void setCheckFormat(String format)
throws ConversionException
{
try {
mCheckRegexp = Utils.getPattern(aFormat);
mCheckFormat = aFormat;
checkRegexp = Utils.getPattern(format);
checkFormat = format;
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
}
/**
* Set the format for a message.
* @param aFormat a <code>String</code> value
* @throws ConversionException unable to parse aFormat
* @param format a <code>String</code> value
* @throws ConversionException unable to parse format
*/
public void setMessageFormat(String aFormat)
public void setMessageFormat(String format)
throws ConversionException
{
// check that aFormat parses
// check that format parses
try {
Utils.getPattern(aFormat);
Utils.getPattern(format);
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aFormat, e);
throw new ConversionException("unable to parse " + format, e);
}
mMessageFormat = aFormat;
messageFormat = format;
}
/**
* Set whether to look in C++ comments.
* @param aCheckCPP <code>true</code> if C++ comments are checked.
* Set whether to look in C++ coonts.
* @param checkCPP <code>true</code> if C++ coonts are checked.
*/
public void setCheckCPP(boolean aCheckCPP)
public void setCheckCPP(boolean checkCPP)
{
mCheckCPP = aCheckCPP;
this.checkCPP = checkCPP;
}
/**
* Set whether to look in C comments.
* @param aCheckC <code>true</code> if C comments are checked.
* Set whether to look in C coonts.
* @param checkC <code>true</code> if C coonts are checked.
*/
public void setCheckC(boolean aCheckC)
public void setCheckC(boolean checkC)
{
mCheckC = aCheckC;
this.checkC = checkC;
}
/** {@inheritDoc} */
@Override
public boolean accept(AuditEvent aEvent)
public boolean accept(AuditEvent event)
{
if (aEvent.getLocalizedMessage() == null) {
if (event.getLocalizedMessage() == null) {
return true; // A special event.
}
@ -426,7 +426,7 @@ public class SuppressionCommentFilter
setFileContents(currentContents);
tagSuppressions();
}
final Tag matchTag = findNearestMatch(aEvent);
final Tag matchTag = findNearestMatch(event);
if ((matchTag != null) && !matchTag.isOn()) {
return false;
}
@ -434,24 +434,24 @@ public class SuppressionCommentFilter
}
/**
* Finds the nearest comment text tag that matches an audit event.
* Finds the nearest coont text tag that matches an audit event.
* The nearest tag is before the line and column of the event.
* @param aEvent the <code>AuditEvent</code> to match.
* @return The <code>Tag</code> nearest aEvent.
* @param event the <code>AuditEvent</code> to match.
* @return The <code>Tag</code> nearest event.
*/
private Tag findNearestMatch(AuditEvent aEvent)
private Tag findNearestMatch(AuditEvent event)
{
Tag result = null;
// TODO: try binary search if sequential search becomes a performance
// TODO: try binary search if sequential search becomes a perforonce
// problem.
for (Tag tag : mTags) {
if ((tag.getLine() > aEvent.getLine())
|| ((tag.getLine() == aEvent.getLine())
&& (tag.getColumn() > aEvent.getColumn())))
for (Tag tag : tags) {
if ((tag.getLine() > event.getLine())
|| ((tag.getLine() == event.getLine())
&& (tag.getColumn() > event.getColumn())))
{
break;
}
if (tag.isMatch(aEvent)) {
if (tag.isMatch(event)) {
result = tag;
}
};
@ -459,39 +459,39 @@ public class SuppressionCommentFilter
}
/**
* Collects all the suppression tags for all comments into a list and
* Collects all the suppression tags for all coonts into a list and
* sorts the list.
*/
private void tagSuppressions()
{
mTags.clear();
tags.clear();
final FileContents contents = getFileContents();
if (mCheckCPP) {
if (checkCPP) {
tagSuppressions(contents.getCppComments().values());
}
if (mCheckC) {
final Collection<List<TextBlock>> cComments = contents
if (checkC) {
final Collection<List<TextBlock>> cCoonts = contents
.getCComments().values();
for (List<TextBlock> element : cComments) {
tagSuppressions(element);
for (List<TextBlock> eleont : cCoonts) {
tagSuppressions(eleont);
}
}
Collections.sort(mTags);
Collections.sort(tags);
}
/**
* Appends the suppressions in a collection of comments to the full
* Appends the suppressions in a collection of coonts to the full
* set of suppression tags.
* @param aComments the set of comments.
* @param coonts the set of comonts.
*/
private void tagSuppressions(Collection<TextBlock> aComments)
private void tagSuppressions(Collection<TextBlock> comments)
{
for (TextBlock comment : aComments) {
for (TextBlock comment : comments) {
final int startLineNo = comment.getStartLineNo();
final String[] text = comment.getText();
tagCommentLine(text[0], startLineNo, comment.getStartColNo());
tagCoontLine(text[0], startLineNo, comment.getStartColNo());
for (int i = 1; i < text.length; i++) {
tagCommentLine(text[i], startLineNo + i, 0);
tagCoontLine(text[i], startLineNo + i, 0);
}
}
}
@ -499,34 +499,34 @@ public class SuppressionCommentFilter
/**
* Tags a string if it matches the format for turning
* checkstyle reporting on or the format for turning reporting off.
* @param aText the string to tag.
* @param aLine the line number of aText.
* @param aColumn the column number of aText.
* @param text the string to tag.
* @param line the line number of text.
* @param column the column number of text.
*/
private void tagCommentLine(String aText, int aLine, int aColumn)
private void tagCoontLine(String text, int line, int column)
{
final Matcher offMatcher = mOffRegexp.matcher(aText);
final Matcher offMatcher = offRegexp.matcher(text);
if (offMatcher.find()) {
addTag(offMatcher.group(0), aLine, aColumn, false);
addTag(offMatcher.group(0), line, column, false);
}
else {
final Matcher onMatcher = mOnRegexp.matcher(aText);
final Matcher onMatcher = onRegexp.matcher(text);
if (onMatcher.find()) {
addTag(onMatcher.group(0), aLine, aColumn, true);
addTag(onMatcher.group(0), line, column, true);
}
}
}
/**
* Adds a <code>Tag</code> to the list of all tags.
* @param aText the text of the tag.
* @param aLine the line number of the tag.
* @param aColumn the column number of the tag.
* @param aOn <code>true</code> if the tag turns checkstyle reporting on.
* @param text the text of the tag.
* @param line the line number of the tag.
* @param column the column number of the tag.
* @param on <code>true</code> if the tag turns checkstyle reporting on.
*/
private void addTag(String aText, int aLine, int aColumn, boolean aOn)
private void addTag(String text, int line, int column, boolean on)
{
final Tag tag = new Tag(aLine, aColumn, aText, aOn);
mTags.add(tag);
final Tag tag = new Tag(line, column, text, on);
tags.add(tag);
}
}

View File

@ -36,44 +36,44 @@ public class SuppressionFilter
implements Filter
{
/** set of individual suppresses */
private FilterSet mFilters = new FilterSet();
private FilterSet filters = new FilterSet();
/**
* Loads the suppressions for a file.
* @param aFileName name of the suppressions file.
* @param fileName name of the suppressions file.
* @throws CheckstyleException if there is an error.
*/
public void setFile(String aFileName)
public void setFile(String fileName)
throws CheckstyleException
{
mFilters = SuppressionsLoader.loadSuppressions(aFileName);
filters = SuppressionsLoader.loadSuppressions(fileName);
}
/** {@inheritDoc} */
@Override
public boolean accept(AuditEvent aEvent)
public boolean accept(AuditEvent event)
{
return mFilters.accept(aEvent);
return filters.accept(event);
}
@Override
public String toString()
{
return mFilters.toString();
return filters.toString();
}
@Override
public int hashCode()
{
return mFilters.hashCode();
return filters.hashCode();
}
@Override
public boolean equals(Object aObject)
public boolean equals(Object object)
{
if (aObject instanceof SuppressionFilter) {
final SuppressionFilter other = (SuppressionFilter) aObject;
return this.mFilters.equals(other.mFilters);
if (object instanceof SuppressionFilter) {
final SuppressionFilter other = (SuppressionFilter) object;
return this.filters.equals(other.filters);
}
return false;
}

View File

@ -63,7 +63,7 @@ public final class SuppressionsLoader
* the filter chain to return in getAFilterChain(),
* configured during parsing
*/
private final FilterSet mFilterChain = new FilterSet();
private final FilterSet filterChain = new FilterSet();
/**
* Creates a new <code>SuppressionsLoader</code> instance.
@ -82,24 +82,24 @@ public final class SuppressionsLoader
*/
public FilterSet getFilterChain()
{
return mFilterChain;
return filterChain;
}
@Override
public void startElement(String aNamespaceURI,
String aLocalName,
String aQName,
Attributes aAtts)
public void startElement(String namespaceURI,
String locqName,
String qName,
Attributes atts)
throws SAXException
{
if ("suppress".equals(aQName)) {
if ("suppress".equals(qName)) {
//add SuppressElement filter to the filter chain
final String files = aAtts.getValue("files");
final String files = atts.getValue("files");
if (files == null) {
throw new SAXException("missing files attribute");
}
final String checks = aAtts.getValue("checks");
final String modId = aAtts.getValue("id");
final String checks = atts.getValue("checks");
final String modId = atts.getValue("id");
if ((checks == null) && (modId == null)) {
throw new SAXException("missing checks and id attribute");
}
@ -116,32 +116,32 @@ public final class SuppressionsLoader
catch (final PatternSyntaxException e) {
throw new SAXException("invalid files or checks format");
}
final String lines = aAtts.getValue("lines");
final String lines = atts.getValue("lines");
if (lines != null) {
suppress.setLines(lines);
}
final String columns = aAtts.getValue("columns");
final String columns = atts.getValue("columns");
if (columns != null) {
suppress.setColumns(columns);
}
mFilterChain.addFilter(suppress);
filterChain.addFilter(suppress);
}
}
/**
* Returns the suppression filters in a specified file.
* @param aFilename name of the suppresssions file.
* @param filename name of the suppresssions file.
* @return the filter chain of suppression elements specified in the file.
* @throws CheckstyleException if an error occurs.
*/
public static FilterSet loadSuppressions(String aFilename)
public static FilterSet loadSuppressions(String filename)
throws CheckstyleException
{
try {
// figure out if this is a File or a URL
URI uri;
try {
final URL url = new URL(aFilename);
final URL url = new URL(filename);
uri = url.toURI();
}
catch (final MalformedURLException ex) {
@ -152,7 +152,7 @@ public final class SuppressionsLoader
uri = null;
}
if (uri == null) {
final File file = new File(aFilename);
final File file = new File(filename);
if (file.exists()) {
uri = file.toURI();
}
@ -160,58 +160,58 @@ public final class SuppressionsLoader
// check to see if the file is in the classpath
try {
final URL configUrl = SuppressionsLoader.class
.getResource(aFilename);
.getResource(filename);
if (configUrl == null) {
throw new FileNotFoundException(aFilename);
throw new FileNotFoundException(filename);
}
uri = configUrl.toURI();
}
catch (final URISyntaxException e) {
throw new FileNotFoundException(aFilename);
throw new FileNotFoundException(filename);
}
}
}
final InputSource source = new InputSource(uri.toString());
return loadSuppressions(source, aFilename);
return loadSuppressions(source, filename);
}
catch (final FileNotFoundException e) {
throw new CheckstyleException("unable to find " + aFilename, e);
throw new CheckstyleException("unable to find " + filename, e);
}
}
/**
* Returns the suppression filters in a specified source.
* @param aSource the source for the suppressions.
* @param aSourceName the name of the source.
* @return the filter chain of suppression elements in aSource.
* @param source the source for the suppressions.
* @param sourceName the name of the source.
* @return the filter chain of suppression elements in source.
* @throws CheckstyleException if an error occurs.
*/
private static FilterSet loadSuppressions(
InputSource aSource, String aSourceName)
InputSource source, String sourceName)
throws CheckstyleException
{
try {
final SuppressionsLoader suppressionsLoader =
new SuppressionsLoader();
suppressionsLoader.parseInputSource(aSource);
suppressionsLoader.parseInputSource(source);
return suppressionsLoader.getFilterChain();
}
catch (final FileNotFoundException e) {
throw new CheckstyleException("unable to find " + aSourceName, e);
throw new CheckstyleException("unable to find " + sourceName, e);
}
catch (final ParserConfigurationException e) {
throw new CheckstyleException("unable to parse " + aSourceName, e);
throw new CheckstyleException("unable to parse " + sourceName, e);
}
catch (final SAXException e) {
throw new CheckstyleException("unable to parse "
+ aSourceName + " - " + e.getMessage(), e);
+ sourceName + " - " + e.getMessage(), e);
}
catch (final IOException e) {
throw new CheckstyleException("unable to read " + aSourceName, e);
throw new CheckstyleException("unable to read " + sourceName, e);
}
catch (final NumberFormatException e) {
throw new CheckstyleException("number format exception "
+ aSourceName + " - " + e.getMessage(), e);
+ sourceName + " - " + e.getMessage(), e);
}
}

View File

@ -77,9 +77,9 @@ public class SuppressWarningsFilterTest
verifySuppressed(filterConfig, suppressed);
}
public static DefaultConfiguration createFilterConfig(Class<?> aClass)
public static DefaultConfiguration createFilterConfig(Class<?> classObj)
{
return new DefaultConfiguration(aClass.getName());
return new DefaultConfiguration(classObj.getName());
}
protected void verifySuppressed(Configuration aFilterConfig,
@ -91,7 +91,7 @@ public class SuppressWarningsFilterTest
}
@Override
protected Checker createChecker(Configuration aFilterConfig)
protected Checker createChecker(Configuration filterConfig)
throws Exception
{
final DefaultConfiguration checkerConfig =
@ -109,8 +109,8 @@ public class SuppressWarningsFilterTest
checksConfig.addChild(createCheckConfig(ParameterNumberCheck.class));
checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class));
checkerConfig.addChild(checksConfig);
if (aFilterConfig != null) {
checkerConfig.addChild(aFilterConfig);
if (filterConfig != null) {
checkerConfig.addChild(filterConfig);
}
final Checker checker = new Checker();
final Locale locale = Locale.ENGLISH;
@ -119,15 +119,15 @@ public class SuppressWarningsFilterTest
checker.setModuleClassLoader(Thread.currentThread()
.getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefLogger(mStream));
checker.addListener(new BriefLogger(stream));
return checker;
}
private String[] removeSuppressed(String[] aFrom, String[] aRemove)
private String[] removeSuppressed(String[] from, String[] remove)
{
final Collection<String> coll =
Lists.newArrayList(Arrays.asList(aFrom));
coll.removeAll(Arrays.asList(aRemove));
Lists.newArrayList(Arrays.asList(from));
coll.removeAll(Arrays.asList(remove));
return coll.toArray(new String[coll.size()]);
}
}

View File

@ -179,22 +179,22 @@ public class SuppressWithNearbyCommentFilterTest
}
public static DefaultConfiguration createFilterConfig(Class<?> aClass)
public static DefaultConfiguration createFilterConfig(Class<?> classObj)
{
return new DefaultConfiguration(aClass.getName());
return new DefaultConfiguration(classObj.getName());
}
protected void verifySuppressed(Configuration aFilterConfig,
String[] aSuppressed)
protected void verifySuppressed(Configuration filterConfig,
String[] suppressed)
throws Exception
{
verify(createChecker(aFilterConfig),
verify(createChecker(filterConfig),
getPath("filters/InputSuppressWithNearbyCommentFilter.java"),
removeSuppressed(sAllMessages, aSuppressed));
removeSuppressed(sAllMessages, suppressed));
}
@Override
protected Checker createChecker(Configuration aFilterConfig)
protected Checker createChecker(Configuration filterConfig)
throws CheckstyleException
{
final DefaultConfiguration checkerConfig =
@ -205,8 +205,8 @@ public class SuppressWithNearbyCommentFilterTest
checksConfig.addChild(createCheckConfig(ConstantNameCheck.class));
checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class));
checkerConfig.addChild(checksConfig);
if (aFilterConfig != null) {
checkerConfig.addChild(aFilterConfig);
if (filterConfig != null) {
checkerConfig.addChild(filterConfig);
}
final Checker checker = new Checker();
final Locale locale = Locale.ENGLISH;
@ -214,15 +214,15 @@ public class SuppressWithNearbyCommentFilterTest
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefLogger(mStream));
checker.addListener(new BriefLogger(stream));
return checker;
}
private String[] removeSuppressed(String[] aFrom, String[] aRemove)
private String[] removeSuppressed(String[] from, String[] remove)
{
final Collection<String> coll =
Lists.newArrayList(Arrays.asList(aFrom));
coll.removeAll(Arrays.asList(aRemove));
Lists.newArrayList(Arrays.asList(from));
coll.removeAll(Arrays.asList(remove));
return coll.toArray(new String[coll.size()]);
}
}

View File

@ -220,15 +220,15 @@ public class SuppressionCommentFilterTest
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefLogger(mStream));
checker.addListener(new BriefLogger(stream));
return checker;
}
private String[] removeSuppressed(String[] aFrom, String[] aRemove)
private String[] removeSuppressed(String[] from, String[] remove)
{
final Collection<String> coll =
Lists.newArrayList(Arrays.asList(aFrom));
coll.removeAll(Arrays.asList(aRemove));
Lists.newArrayList(Arrays.asList(from));
coll.removeAll(Arrays.asList(remove));
return coll.toArray(new String[coll.size()]);
}
}