Prefixes, regexp, #512
This commit is contained in:
parent
50c9bb69bc
commit
075b3084de
|
|
@ -28,23 +28,23 @@ import com.puppycrawl.tools.checkstyle.api.FileContents;
|
|||
class CommentSuppressor implements MatchSuppressor
|
||||
{
|
||||
/** File contents to check for comments. */
|
||||
private FileContents mCurrentContents;
|
||||
private FileContents currentContents;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean shouldSuppress(int aStartLineNo, int aStartColNo,
|
||||
int aEndLineNo, int aEndColNo)
|
||||
public boolean shouldSuppress(int startLineNo, int startColNo,
|
||||
int endLineNo, int endColNo)
|
||||
{
|
||||
return (null != mCurrentContents)
|
||||
&& mCurrentContents.hasIntersectionWithComment(aStartLineNo,
|
||||
aStartColNo, aEndLineNo, aEndColNo);
|
||||
return (null != currentContents)
|
||||
&& currentContents.hasIntersectionWithComment(startLineNo,
|
||||
startColNo, endLineNo, endColNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current file contents.
|
||||
* @param aCurrentContents the new contents.
|
||||
* @param currentContents the new contents.
|
||||
*/
|
||||
public void setCurrentContents(FileContents aCurrentContents)
|
||||
public void setCurrentContents(FileContents currentContents)
|
||||
{
|
||||
mCurrentContents = aCurrentContents;
|
||||
this.currentContents = currentContents;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,97 +32,97 @@ class DetectorOptions
|
|||
* Flags to compile a regular expression with.
|
||||
* See {@link Pattern#flags()}.
|
||||
*/
|
||||
private final int mCompileFlags;
|
||||
private final int compileFlags;
|
||||
/** Used for reporting violations. */
|
||||
private final AbstractViolationReporter mReporter;
|
||||
private final AbstractViolationReporter reporter;
|
||||
/** Format of the regular expression to check for. */
|
||||
private String mFormat;
|
||||
private String format;
|
||||
/** The message to report on detection. If blank, then use the format. */
|
||||
private String mMessage = "";
|
||||
private String message = "";
|
||||
/** Minimum number of times regular expression should occur in a file. */
|
||||
private int mMinimum;
|
||||
private int minimum;
|
||||
/** Maximum number of times regular expression should occur in a file. */
|
||||
private int mMaximum;
|
||||
private int maximum;
|
||||
/** Whether to ignore case when matching. */
|
||||
private boolean mIgnoreCase;
|
||||
private boolean ignoreCase;
|
||||
/** Used to determine whether to suppress a detected match. */
|
||||
private MatchSuppressor mSuppressor = NeverSuppress.INSTANCE;
|
||||
private MatchSuppressor suppressor = NeverSuppress.INSTANCE;
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
* @param aCompileFlags the flags to create the regular expression with.
|
||||
* @param aReporter used to report violations.
|
||||
* @param compileFlags the flags to create the regular expression with.
|
||||
* @param reporter used to report violations.
|
||||
*/
|
||||
public DetectorOptions(int aCompileFlags,
|
||||
AbstractViolationReporter aReporter)
|
||||
public DetectorOptions(int compileFlags,
|
||||
AbstractViolationReporter reporter)
|
||||
{
|
||||
mCompileFlags = aCompileFlags;
|
||||
mReporter = aReporter;
|
||||
this.compileFlags = compileFlags;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* The format to use when matching lines.
|
||||
* @param aFormat the format to use when matching lines.
|
||||
* @param format the format to use when matching lines.
|
||||
* @return current instance
|
||||
*/
|
||||
public DetectorOptions setFormat(String aFormat)
|
||||
public DetectorOptions setFormat(String format)
|
||||
{
|
||||
mFormat = aFormat;
|
||||
this.format = format;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message to use when reporting a match.
|
||||
* @param aMessage message to use when reporting a match.
|
||||
* @param message message to use when reporting a match.
|
||||
* @return current instance.
|
||||
*/
|
||||
public DetectorOptions setMessage(String aMessage)
|
||||
public DetectorOptions setMessage(String message)
|
||||
{
|
||||
mMessage = aMessage;
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum allowed number of detections.
|
||||
* @param aMinimum the minimum allowed number of detections.
|
||||
* @param minimum the minimum allowed number of detections.
|
||||
* @return current instance
|
||||
*/
|
||||
public DetectorOptions setMinimum(int aMinimum)
|
||||
public DetectorOptions setMinimum(int minimum)
|
||||
{
|
||||
mMinimum = aMinimum;
|
||||
this.minimum = minimum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum allowed number of detections.
|
||||
* @param aMaximum the maximum allowed number of detections.
|
||||
* @param maximum the maximum allowed number of detections.
|
||||
* @return current instance
|
||||
*/
|
||||
public DetectorOptions setMaximum(int aMaximum)
|
||||
public DetectorOptions setMaximum(int maximum)
|
||||
{
|
||||
mMaximum = aMaximum;
|
||||
this.maximum = maximum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the suppressor to use.
|
||||
* @param aSup the suppressor to use.
|
||||
* @param sup the suppressor to use.
|
||||
* @return current instance
|
||||
*/
|
||||
public DetectorOptions setSuppressor(MatchSuppressor aSup)
|
||||
public DetectorOptions setSuppressor(MatchSuppressor sup)
|
||||
{
|
||||
mSuppressor = aSup;
|
||||
suppressor = sup;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to ignore case when matching.
|
||||
* @param aIgnore whether to ignore case when matching.
|
||||
* @param ignore whether to ignore case when matching.
|
||||
* @return current instance
|
||||
*/
|
||||
public DetectorOptions setIgnoreCase(boolean aIgnore)
|
||||
public DetectorOptions setIgnoreCase(boolean ignore)
|
||||
{
|
||||
mIgnoreCase = aIgnore;
|
||||
ignoreCase = ignore;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ class DetectorOptions
|
|||
*/
|
||||
public String getFormat()
|
||||
{
|
||||
return mFormat;
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -141,7 +141,7 @@ class DetectorOptions
|
|||
*/
|
||||
public AbstractViolationReporter getReporter()
|
||||
{
|
||||
return mReporter;
|
||||
return reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -150,7 +150,7 @@ class DetectorOptions
|
|||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return mMessage;
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -159,7 +159,7 @@ class DetectorOptions
|
|||
*/
|
||||
public int getMinimum()
|
||||
{
|
||||
return mMinimum;
|
||||
return minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -168,7 +168,7 @@ class DetectorOptions
|
|||
*/
|
||||
public int getMaximum()
|
||||
{
|
||||
return mMaximum;
|
||||
return maximum;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -177,7 +177,7 @@ class DetectorOptions
|
|||
*/
|
||||
public MatchSuppressor getSuppressor()
|
||||
{
|
||||
return mSuppressor;
|
||||
return suppressor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -186,7 +186,7 @@ class DetectorOptions
|
|||
*/
|
||||
public boolean isIgnoreCase()
|
||||
{
|
||||
return mIgnoreCase;
|
||||
return ignoreCase;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,8 +195,8 @@ class DetectorOptions
|
|||
*/
|
||||
public Pattern getPattern()
|
||||
{
|
||||
final int options = (mIgnoreCase) ? mCompileFlags
|
||||
| Pattern.CASE_INSENSITIVE : mCompileFlags;
|
||||
return Utils.getPattern(mFormat, options);
|
||||
final int options = (ignoreCase) ? compileFlags
|
||||
| Pattern.CASE_INSENSITIVE : compileFlags;
|
||||
return Utils.getPattern(format, options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ interface MatchSuppressor
|
|||
{
|
||||
/**
|
||||
* Checks if the specified selection should be suppressed.
|
||||
* @param aStartLineNo the starting line number
|
||||
* @param aStartColNo the starting column number
|
||||
* @param aEndLineNo the ending line number
|
||||
* @param aEndColNo the ending column number
|
||||
* @param startLineNo the starting line number
|
||||
* @param startColNo the starting column number
|
||||
* @param endLineNo the ending line number
|
||||
* @param endColNo the ending column number
|
||||
* @return true if the positions intersects with a comment.
|
||||
**/
|
||||
boolean shouldSuppress(int aStartLineNo, int aStartColNo, int aEndLineNo,
|
||||
int aEndColNo);
|
||||
boolean shouldSuppress(int startLineNo, int startColNo, int endLineNo,
|
||||
int endColNo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,32 +29,32 @@ import com.puppycrawl.tools.checkstyle.api.LineColumn;
|
|||
class MultilineDetector
|
||||
{
|
||||
/** The detection options to use. */
|
||||
private final DetectorOptions mOptions;
|
||||
private final DetectorOptions options;
|
||||
/** Tracks the number of matches. */
|
||||
private int mCurrentMatches;
|
||||
/** The mMatcher */
|
||||
private Matcher mMatcher;
|
||||
private int currentMatches;
|
||||
/** The matcher */
|
||||
private Matcher matcher;
|
||||
/** The file text content */
|
||||
private FileText mText;
|
||||
private FileText text;
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
* @param aOptions the options to use.
|
||||
* @param options the options to use.
|
||||
*/
|
||||
public MultilineDetector(DetectorOptions aOptions)
|
||||
public MultilineDetector(DetectorOptions options)
|
||||
{
|
||||
mOptions = aOptions;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes an entire text file looking for matches.
|
||||
* @param aText the text to process
|
||||
* @param text the text to process
|
||||
*/
|
||||
public void processLines(FileText aText)
|
||||
public void processLines(FileText text)
|
||||
{
|
||||
mText = aText;
|
||||
this.text = text;
|
||||
resetState();
|
||||
mMatcher = mOptions.getPattern().matcher(mText.getFullText());
|
||||
matcher = options.getPattern().matcher(text.getFullText());
|
||||
findMatch();
|
||||
finish();
|
||||
}
|
||||
|
|
@ -62,26 +62,26 @@ class MultilineDetector
|
|||
/** recursive method that finds the matches. */
|
||||
private void findMatch()
|
||||
{
|
||||
final boolean foundMatch = mMatcher.find();
|
||||
final boolean foundMatch = matcher.find();
|
||||
if (!foundMatch) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LineColumn start = mText.lineColumn(mMatcher.start());
|
||||
final LineColumn end = mText.lineColumn(mMatcher.end());
|
||||
final LineColumn start = text.lineColumn(matcher.start());
|
||||
final LineColumn end = text.lineColumn(matcher.end());
|
||||
|
||||
if (!mOptions.getSuppressor().shouldSuppress(start.getLine(),
|
||||
if (!options.getSuppressor().shouldSuppress(start.getLine(),
|
||||
start.getColumn(), end.getLine(), end.getColumn()))
|
||||
{
|
||||
mCurrentMatches++;
|
||||
if (mCurrentMatches > mOptions.getMaximum()) {
|
||||
if ("".equals(mOptions.getMessage())) {
|
||||
mOptions.getReporter().log(start.getLine(),
|
||||
"regexp.exceeded", mMatcher.pattern().toString());
|
||||
currentMatches++;
|
||||
if (currentMatches > options.getMaximum()) {
|
||||
if ("".equals(options.getMessage())) {
|
||||
options.getReporter().log(start.getLine(),
|
||||
"regexp.exceeded", matcher.pattern().toString());
|
||||
}
|
||||
else {
|
||||
mOptions.getReporter()
|
||||
.log(start.getLine(), mOptions.getMessage());
|
||||
options.getReporter()
|
||||
.log(start.getLine(), options.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -90,13 +90,13 @@ class MultilineDetector
|
|||
/** Perform processing at the end of a set of lines. */
|
||||
private void finish()
|
||||
{
|
||||
if (mCurrentMatches < mOptions.getMinimum()) {
|
||||
if ("".equals(mOptions.getMessage())) {
|
||||
mOptions.getReporter().log(0, "regexp.minimum",
|
||||
mOptions.getMinimum(), mOptions.getFormat());
|
||||
if (currentMatches < options.getMinimum()) {
|
||||
if ("".equals(options.getMessage())) {
|
||||
options.getReporter().log(0, "regexp.minimum",
|
||||
options.getMinimum(), options.getFormat());
|
||||
}
|
||||
else {
|
||||
mOptions.getReporter().log(0, mOptions.getMessage());
|
||||
options.getReporter().log(0, options.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,6 +106,6 @@ class MultilineDetector
|
|||
*/
|
||||
private void resetState()
|
||||
{
|
||||
mCurrentMatches = 0;
|
||||
currentMatches = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ public final class NeverSuppress implements MatchSuppressor
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean shouldSuppress(int aStartLineNo, int aStartColNo,
|
||||
int aEndLineNo, int aEndColNo)
|
||||
public boolean shouldSuppress(int startLineNo, int startColNo,
|
||||
int endLineNo, int endColNo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,66 +33,66 @@ import java.util.List;
|
|||
public class RegexpMultilineCheck extends AbstractFileSetCheck
|
||||
{
|
||||
/** The detection options to use. */
|
||||
private DetectorOptions mOptions = new DetectorOptions(Pattern.MULTILINE,
|
||||
private DetectorOptions options = new DetectorOptions(Pattern.MULTILINE,
|
||||
this);
|
||||
/** The detector to use. */
|
||||
private MultilineDetector mDetector;
|
||||
private MultilineDetector detector;
|
||||
|
||||
@Override
|
||||
public void beginProcessing(String aCharset)
|
||||
public void beginProcessing(String charset)
|
||||
{
|
||||
super.beginProcessing(aCharset);
|
||||
mDetector = new MultilineDetector(mOptions);
|
||||
super.beginProcessing(charset);
|
||||
detector = new MultilineDetector(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processFiltered(File aFile, List<String> aLines)
|
||||
protected void processFiltered(File file, List<String> lines)
|
||||
{
|
||||
mDetector.processLines(FileText.fromLines(aFile, aLines));
|
||||
detector.processLines(FileText.fromLines(file, lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of the regular expression to match.
|
||||
* @param aFormat the format of the regular expression to match.
|
||||
* @param format the format of the regular expression to match.
|
||||
*/
|
||||
public void setFormat(String aFormat)
|
||||
public void setFormat(String format)
|
||||
{
|
||||
mOptions.setFormat(aFormat);
|
||||
options.setFormat(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message to report for a match.
|
||||
* @param aMessage the message to report for a match.
|
||||
* @param message the message to report for a match.
|
||||
*/
|
||||
public void setMessage(String aMessage)
|
||||
public void setMessage(String message)
|
||||
{
|
||||
mOptions.setMessage(aMessage);
|
||||
options.setMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum number of matches required per file.
|
||||
* @param aMinimum the minimum number of matches required per file.
|
||||
* @param minimum the minimum number of matches required per file.
|
||||
*/
|
||||
public void setMinimum(int aMinimum)
|
||||
public void setMinimum(int minimum)
|
||||
{
|
||||
mOptions.setMinimum(aMinimum);
|
||||
options.setMinimum(minimum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of matches required per file.
|
||||
* @param aMaximum the maximum number of matches required per file.
|
||||
* @param maximum the maximum number of matches required per file.
|
||||
*/
|
||||
public void setMaximum(int aMaximum)
|
||||
public void setMaximum(int maximum)
|
||||
{
|
||||
mOptions.setMaximum(aMaximum);
|
||||
options.setMaximum(maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to ignore case when matching.
|
||||
* @param aIgnore whether to ignore case when matching.
|
||||
* @param ignore whether to ignore case when matching.
|
||||
*/
|
||||
public void setIgnoreCase(boolean aIgnore)
|
||||
public void setIgnoreCase(boolean ignore)
|
||||
{
|
||||
mOptions.setIgnoreCase(aIgnore);
|
||||
options.setIgnoreCase(ignore);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,65 +29,65 @@ import java.util.List;
|
|||
public class RegexpSinglelineCheck extends AbstractFileSetCheck
|
||||
{
|
||||
/** The detection options to use. */
|
||||
private DetectorOptions mOptions = new DetectorOptions(0, this);
|
||||
private DetectorOptions options = new DetectorOptions(0, this);
|
||||
/** The detector to use. */
|
||||
private SinglelineDetector mDetector;
|
||||
private SinglelineDetector detector;
|
||||
|
||||
@Override
|
||||
public void beginProcessing(String aCharset)
|
||||
public void beginProcessing(String charset)
|
||||
{
|
||||
super.beginProcessing(aCharset);
|
||||
mDetector = new SinglelineDetector(mOptions);
|
||||
super.beginProcessing(charset);
|
||||
detector = new SinglelineDetector(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processFiltered(File aFile, List<String> aLines)
|
||||
protected void processFiltered(File file, List<String> lines)
|
||||
{
|
||||
mDetector.processLines(aLines);
|
||||
detector.processLines(lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of the regular expression to match.
|
||||
* @param aFormat the format of the regular expression to match.
|
||||
* @param format the format of the regular expression to match.
|
||||
*/
|
||||
public void setFormat(String aFormat)
|
||||
public void setFormat(String format)
|
||||
{
|
||||
mOptions.setFormat(aFormat);
|
||||
options.setFormat(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message to report for a match.
|
||||
* @param aMessage the message to report for a match.
|
||||
* @param message the message to report for a match.
|
||||
*/
|
||||
public void setMessage(String aMessage)
|
||||
public void setMessage(String message)
|
||||
{
|
||||
mOptions.setMessage(aMessage);
|
||||
options.setMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum number of matches required per file.
|
||||
* @param aMinimum the minimum number of matches required per file.
|
||||
* @param minimum the minimum number of matches required per file.
|
||||
*/
|
||||
public void setMinimum(int aMinimum)
|
||||
public void setMinimum(int minimum)
|
||||
{
|
||||
mOptions.setMinimum(aMinimum);
|
||||
options.setMinimum(minimum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of matches required per file.
|
||||
* @param aMaximum the maximum number of matches required per file.
|
||||
* @param maximum the maximum number of matches required per file.
|
||||
*/
|
||||
public void setMaximum(int aMaximum)
|
||||
public void setMaximum(int maximum)
|
||||
{
|
||||
mOptions.setMaximum(aMaximum);
|
||||
options.setMaximum(maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to ignore case when matching.
|
||||
* @param aIgnore whether to ignore case when matching.
|
||||
* @param ignore whether to ignore case when matching.
|
||||
*/
|
||||
public void setIgnoreCase(boolean aIgnore)
|
||||
public void setIgnoreCase(boolean ignore)
|
||||
{
|
||||
mOptions.setIgnoreCase(aIgnore);
|
||||
options.setIgnoreCase(ignore);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ import java.util.Arrays;
|
|||
public class RegexpSinglelineJavaCheck extends Check
|
||||
{
|
||||
/** The detection options to use. */
|
||||
private DetectorOptions mOptions = new DetectorOptions(0, this);
|
||||
private DetectorOptions options = new DetectorOptions(0, this);
|
||||
/** The detector to use. */
|
||||
private SinglelineDetector mDetector;
|
||||
private SinglelineDetector detector;
|
||||
/** The suppressor to use. */
|
||||
private final CommentSuppressor mSuppressor = new CommentSuppressor();
|
||||
private final CommentSuppressor suppressor = new CommentSuppressor();
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
|
|
@ -46,72 +46,72 @@ public class RegexpSinglelineJavaCheck extends Check
|
|||
public void init()
|
||||
{
|
||||
super.init();
|
||||
mDetector = new SinglelineDetector(mOptions);
|
||||
detector = new SinglelineDetector(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginTree(DetailAST aRootAST)
|
||||
public void beginTree(DetailAST rootAST)
|
||||
{
|
||||
mSuppressor.setCurrentContents(getFileContents());
|
||||
mDetector.processLines(Arrays.asList(getLines()));
|
||||
suppressor.setCurrentContents(getFileContents());
|
||||
detector.processLines(Arrays.asList(getLines()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of the regular expression to match.
|
||||
* @param aFormat the format of the regular expression to match.
|
||||
* @param format the format of the regular expression to match.
|
||||
*/
|
||||
public void setFormat(String aFormat)
|
||||
public void setFormat(String format)
|
||||
{
|
||||
mOptions.setFormat(aFormat);
|
||||
options.setFormat(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message to report for a match.
|
||||
* @param aMessage the message to report for a match.
|
||||
* @param message the message to report for a match.
|
||||
*/
|
||||
public void setMessage(String aMessage)
|
||||
public void setMessage(String message)
|
||||
{
|
||||
mOptions.setMessage(aMessage);
|
||||
options.setMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum number of matches required per file.
|
||||
* @param aMinimum the minimum number of matches required per file.
|
||||
* @param minimum the minimum number of matches required per file.
|
||||
*/
|
||||
public void setMinimum(int aMinimum)
|
||||
public void setMinimum(int minimum)
|
||||
{
|
||||
mOptions.setMinimum(aMinimum);
|
||||
options.setMinimum(minimum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of matches required per file.
|
||||
* @param aMaximum the maximum number of matches required per file.
|
||||
* @param maximum the maximum number of matches required per file.
|
||||
*/
|
||||
public void setMaximum(int aMaximum)
|
||||
public void setMaximum(int maximum)
|
||||
{
|
||||
mOptions.setMaximum(aMaximum);
|
||||
options.setMaximum(maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to ignore case when matching.
|
||||
* @param aIgnore whether to ignore case when matching.
|
||||
* @param ignore whether to ignore case when matching.
|
||||
*/
|
||||
public void setIgnoreCase(boolean aIgnore)
|
||||
public void setIgnoreCase(boolean ignore)
|
||||
{
|
||||
mOptions.setIgnoreCase(aIgnore);
|
||||
options.setIgnoreCase(ignore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to ignore comments when matching.
|
||||
* @param aIgnore whether to ignore comments when matching.
|
||||
* @param ignore whether to ignore comments when matching.
|
||||
*/
|
||||
public void setIgnoreComments(boolean aIgnore)
|
||||
public void setIgnoreComments(boolean ignore)
|
||||
{
|
||||
if (aIgnore) {
|
||||
mOptions.setSuppressor(mSuppressor);
|
||||
if (ignore) {
|
||||
options.setSuppressor(suppressor);
|
||||
}
|
||||
else {
|
||||
mOptions.setSuppressor(NeverSuppress.INSTANCE);
|
||||
options.setSuppressor(NeverSuppress.INSTANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,30 +28,30 @@ import java.util.regex.Matcher;
|
|||
class SinglelineDetector
|
||||
{
|
||||
/** The detection options to use. */
|
||||
private final DetectorOptions mOptions;
|
||||
private final DetectorOptions options;
|
||||
/** Tracks the number of matches. */
|
||||
private int mCurrentMatches;
|
||||
private int currentMatches;
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
* @param aOptions the options to use.
|
||||
* @param options the options to use.
|
||||
*/
|
||||
public SinglelineDetector(DetectorOptions aOptions)
|
||||
public SinglelineDetector(DetectorOptions options)
|
||||
{
|
||||
mOptions = aOptions;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a set of lines looking for matches.
|
||||
* @param aLines the lines to process.
|
||||
* @param lines the lines to process.
|
||||
*/
|
||||
public void processLines(List<String> aLines)
|
||||
public void processLines(List<String> lines)
|
||||
{
|
||||
resetState();
|
||||
int lineno = 0;
|
||||
for (String line : aLines) {
|
||||
for (String line : lines) {
|
||||
lineno++;
|
||||
checkLine(lineno, line, mOptions.getPattern().matcher(line), 0);
|
||||
checkLine(lineno, line, options.getPattern().matcher(line), 0);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
|
@ -59,13 +59,13 @@ class SinglelineDetector
|
|||
/** Perform processing at the end of a set of lines. */
|
||||
private void finish()
|
||||
{
|
||||
if (mCurrentMatches < mOptions.getMinimum()) {
|
||||
if ("".equals(mOptions.getMessage())) {
|
||||
mOptions.getReporter().log(0, "regexp.minimum",
|
||||
mOptions.getMinimum(), mOptions.getFormat());
|
||||
if (currentMatches < options.getMinimum()) {
|
||||
if ("".equals(options.getMessage())) {
|
||||
options.getReporter().log(0, "regexp.minimum",
|
||||
options.getMinimum(), options.getFormat());
|
||||
}
|
||||
else {
|
||||
mOptions.getReporter().log(0, mOptions.getMessage());
|
||||
options.getReporter().log(0, options.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -75,49 +75,49 @@ class SinglelineDetector
|
|||
*/
|
||||
private void resetState()
|
||||
{
|
||||
mCurrentMatches = 0;
|
||||
currentMatches = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a line for matches.
|
||||
* @param aLineno the line number of the line to check
|
||||
* @param aLine the line to check
|
||||
* @param aMatcher the matcher to use
|
||||
* @param aStartPosition the position to start searching from.
|
||||
* @param lineno the line number of the line to check
|
||||
* @param line the line to check
|
||||
* @param matcher the matcher to use
|
||||
* @param startPosition the position to start searching from.
|
||||
*/
|
||||
private void checkLine(int aLineno, String aLine, Matcher aMatcher,
|
||||
int aStartPosition)
|
||||
private void checkLine(int lineno, String line, Matcher matcher,
|
||||
int startPosition)
|
||||
{
|
||||
final boolean foundMatch = aMatcher.find(aStartPosition);
|
||||
final boolean foundMatch = matcher.find(startPosition);
|
||||
if (!foundMatch) {
|
||||
return;
|
||||
}
|
||||
|
||||
// match is found, check for intersection with comment
|
||||
final int startCol = aMatcher.start(0);
|
||||
final int endCol = aMatcher.end(0);
|
||||
final int startCol = matcher.start(0);
|
||||
final int endCol = matcher.end(0);
|
||||
// Note that Matcher.end(int) returns the offset AFTER the
|
||||
// last matched character, but shouldSuppress()
|
||||
// needs column number of the last character.
|
||||
// So we need to use (endCol - 1) here.
|
||||
if (mOptions.getSuppressor()
|
||||
.shouldSuppress(aLineno, startCol, aLineno, endCol - 1))
|
||||
if (options.getSuppressor()
|
||||
.shouldSuppress(lineno, startCol, lineno, endCol - 1))
|
||||
{
|
||||
if (endCol < aLine.length()) {
|
||||
if (endCol < line.length()) {
|
||||
// check if the expression is on the rest of the line
|
||||
checkLine(aLineno, aLine, aMatcher, endCol);
|
||||
checkLine(lineno, line, matcher, endCol);
|
||||
}
|
||||
return; // end processing here
|
||||
}
|
||||
|
||||
mCurrentMatches++;
|
||||
if (mCurrentMatches > mOptions.getMaximum()) {
|
||||
if ("".equals(mOptions.getMessage())) {
|
||||
mOptions.getReporter().log(aLineno, "regexp.exceeded",
|
||||
aMatcher.pattern().toString());
|
||||
currentMatches++;
|
||||
if (currentMatches > options.getMaximum()) {
|
||||
if ("".equals(options.getMessage())) {
|
||||
options.getReporter().log(lineno, "regexp.exceeded",
|
||||
matcher.pattern().toString());
|
||||
}
|
||||
else {
|
||||
mOptions.getReporter().log(aLineno, mOptions.getMessage());
|
||||
options.getReporter().log(lineno, options.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,23 +26,23 @@ import org.junit.Test;
|
|||
|
||||
public class RegexpMultilineCheckTest extends BaseFileSetCheckTestSupport
|
||||
{
|
||||
private DefaultConfiguration mCheckConfig;
|
||||
private DefaultConfiguration checkConfig;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
mCheckConfig = createCheckConfig(RegexpMultilineCheck.class);
|
||||
checkConfig = createCheckConfig(RegexpMultilineCheck.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIt() throws Exception
|
||||
{
|
||||
final String illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
final String[] expected = {
|
||||
"69: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -51,47 +51,47 @@ public class RegexpMultilineCheckTest extends BaseFileSetCheckTestSupport
|
|||
{
|
||||
final String illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
|
||||
final String message = "Bad line :(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("message", message);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("message", message);
|
||||
final String[] expected = {
|
||||
"69: " + message,
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCaseTrue() throws Exception
|
||||
{
|
||||
final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreCase", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreCase", "true");
|
||||
final String[] expected = {
|
||||
"69: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCaseFalse() throws Exception
|
||||
{
|
||||
final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreCase", "false");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreCase", "false");
|
||||
final String[] expected = {};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalFailBelowErrorLimit() throws Exception
|
||||
{
|
||||
final String illegal = "^import";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
final String[] expected = {
|
||||
"7: Line matches the illegal pattern '" + illegal + "'.",
|
||||
"8: Line matches the illegal pattern '" + illegal + "'.",
|
||||
"9: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
// Need to fix the line endings in the input file
|
||||
|
|
@ -99,14 +99,14 @@ public class RegexpMultilineCheckTest extends BaseFileSetCheckTestSupport
|
|||
public void testCarriageReturn() throws Exception
|
||||
{
|
||||
final String illegal = "\\r";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
final String[] expected = {
|
||||
"14: Line matches the illegal pattern '" + illegal + "'.",
|
||||
"16: Line matches the illegal pattern '" + illegal + "'.",
|
||||
"19: Line matches the illegal pattern '" + illegal + "'.",
|
||||
"21: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputLineBreaks.java"), expected);
|
||||
verify(checkConfig, getPath("InputLineBreaks.java"), expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,23 +25,23 @@ import org.junit.Test;
|
|||
|
||||
public class RegexpSinglelineCheckTest extends BaseFileSetCheckTestSupport
|
||||
{
|
||||
private DefaultConfiguration mCheckConfig;
|
||||
private DefaultConfiguration checkConfig;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
mCheckConfig = createCheckConfig(RegexpSinglelineCheck.class);
|
||||
checkConfig = createCheckConfig(RegexpSinglelineCheck.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIt() throws Exception
|
||||
{
|
||||
final String illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
final String[] expected = {
|
||||
"69: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -50,33 +50,33 @@ public class RegexpSinglelineCheckTest extends BaseFileSetCheckTestSupport
|
|||
{
|
||||
final String illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
|
||||
final String message = "Bad line :(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("message", message);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("message", message);
|
||||
final String[] expected = {
|
||||
"69: " + message,
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCaseTrue() throws Exception
|
||||
{
|
||||
final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreCase", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreCase", "true");
|
||||
final String[] expected = {
|
||||
"69: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCaseFalse() throws Exception
|
||||
{
|
||||
final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreCase", "false");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreCase", "false");
|
||||
final String[] expected = {};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,23 +25,23 @@ import org.junit.Test;
|
|||
|
||||
public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
||||
{
|
||||
private DefaultConfiguration mCheckConfig;
|
||||
private DefaultConfiguration checkConfig;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
mCheckConfig = createCheckConfig(RegexpSinglelineJavaCheck.class);
|
||||
checkConfig = createCheckConfig(RegexpSinglelineJavaCheck.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIt() throws Exception
|
||||
{
|
||||
final String illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
final String[] expected = {
|
||||
"69: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -50,34 +50,34 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
|||
{
|
||||
final String illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
|
||||
final String message = "Bad line :(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("message", message);
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("message", message);
|
||||
final String[] expected = {
|
||||
"69: " + message,
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCaseTrue() throws Exception
|
||||
{
|
||||
final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreCase", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreCase", "true");
|
||||
final String[] expected = {
|
||||
"69: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCaseFalse() throws Exception
|
||||
{
|
||||
final String illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreCase", "false");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreCase", "false");
|
||||
final String[] expected = {};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -85,11 +85,11 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
|||
{
|
||||
// See if the comment is removed properly
|
||||
final String illegal = "don't use trailing comments";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -97,12 +97,12 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
|||
{
|
||||
// See if the comment is removed properly
|
||||
final String illegal = "don't use trailing comments";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "false");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "false");
|
||||
final String[] expected = {
|
||||
"4: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -110,23 +110,23 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
|||
{
|
||||
// See if the comment is removed properly
|
||||
final String illegal = "c-style 1";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCommentsFalseCStyle() throws Exception
|
||||
{
|
||||
final String illegal = "c-style 1";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "false");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "false");
|
||||
final String[] expected = {
|
||||
"19: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -134,57 +134,57 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
|||
{
|
||||
// See if a second comment on the same line is removed properly
|
||||
final String illegal = "c-style 2";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCommentsMultiLine() throws Exception
|
||||
{
|
||||
final String illegal = "Let's check multi-line comments";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCommentsInlineStart() throws Exception
|
||||
{
|
||||
final String illegal = "long ms /";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCommentsInlineEnd() throws Exception
|
||||
{
|
||||
final String illegal = "int z";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
"22: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreCommentsInlineMiddle() throws Exception
|
||||
{
|
||||
final String illegal = "int y";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
"23: Line matches the illegal pattern '" + illegal + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -192,11 +192,11 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
|||
{
|
||||
// make sure the comment is not turned into spaces
|
||||
final String illegal = "long ms ";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -204,47 +204,47 @@ public class RegexpSinglelineJavaCheckTest extends BaseCheckTestSupport
|
|||
{
|
||||
// StackOverflowError with trailing space and ignoreComments
|
||||
final String illegal = "\\s+$";
|
||||
mCheckConfig.addAttribute("format", illegal);
|
||||
mCheckConfig.addAttribute("ignoreComments", "true");
|
||||
checkConfig.addAttribute("format", illegal);
|
||||
checkConfig.addAttribute("ignoreComments", "true");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
|
||||
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingInDoc() throws Exception
|
||||
{
|
||||
final String required = "Test case file";
|
||||
mCheckConfig.addAttribute("format", required);
|
||||
mCheckConfig.addAttribute("minimum", "1");
|
||||
mCheckConfig.addAttribute("maximum", "1000");
|
||||
checkConfig.addAttribute("format", required);
|
||||
checkConfig.addAttribute("minimum", "1");
|
||||
checkConfig.addAttribute("maximum", "1000");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingInCode() throws Exception
|
||||
{
|
||||
final String required = "package";
|
||||
mCheckConfig.addAttribute("format", required);
|
||||
mCheckConfig.addAttribute("minimum", "1");
|
||||
mCheckConfig.addAttribute("maximum", "1000");
|
||||
checkConfig.addAttribute("format", required);
|
||||
checkConfig.addAttribute("minimum", "1");
|
||||
checkConfig.addAttribute("maximum", "1000");
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissing() throws Exception
|
||||
{
|
||||
final String required = "This text is not in the file";
|
||||
mCheckConfig.addAttribute("format", required);
|
||||
mCheckConfig.addAttribute("minimum", "1");
|
||||
mCheckConfig.addAttribute("maximum", "1000");
|
||||
checkConfig.addAttribute("format", required);
|
||||
checkConfig.addAttribute("minimum", "1");
|
||||
checkConfig.addAttribute("maximum", "1000");
|
||||
final String[] expected = {
|
||||
"0: File does not contain at least 1 matches for pattern '" + required + "'.",
|
||||
};
|
||||
verify(mCheckConfig, getPath("InputSemantic.java"), expected);
|
||||
verify(checkConfig, getPath("InputSemantic.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue