patch to ignore all javadoc and line length

This commit is contained in:
Oliver Burn 2001-10-31 20:58:37 +00:00
parent 85a53ccdaf
commit 517e2450ca
5 changed files with 99 additions and 15 deletions

View File

@ -1,3 +1,13 @@
2001-11-01 Oliver Burn <oliver@cortexebusiness.com.au>
* src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java
* src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java:
* src/checkstyle/com/puppycrawl/tools/checkstyle/VerifierImpl.java:
* src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java:
Included patch to optionally ignore line length on import statements
and to totally ignore Javadoc. From John Hohlen [ JHohlen _AT_ erac
_DOT_ com ].
2001-10-31 Oliver Burn <checkstyle@puppycrawl.com>
* src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java:

View File

@ -114,6 +114,14 @@ public class CheckStyleTask
mConfig.setMaxLineLength(aLen);
}
/** @param aIgnore whether max line length should be ignored for
* import statements
*/
public void setIgnoreImportLength(boolean aIgnore)
{
mConfig.setIgnoreImportLength(aIgnore);
}
/** @param aPat pattern for member variables **/
public void setMemberPattern(String aPat)
{
@ -210,6 +218,14 @@ public class CheckStyleTask
mConfig.setRelaxJavadoc(aRelax);
}
/** @param aIgnore whether Javadoc comments should be checked. This
* takes precedence over the "Relax Javadoc" setting.
*/
public void setIgnoreJavadoc(boolean aIgnore)
{
mConfig.setIgnoreJavadoc(aIgnore);
}
/** @param aIgnore whether to ignore import statements **/
public void setIgnoreImports(boolean aIgnore)
{

View File

@ -98,6 +98,8 @@ class Configuration
private boolean mAllowNoAuthor = false;
/** whether to relax javadoc checking **/
private boolean mRelaxJavadoc = false;
/** whether to ignore javadoc checking **/
private boolean mIgnoreJavadoc = false;
/** whether to ignore imports **/
private boolean mIgnoreImports = false;
/** whether to ignore whitespace **/
@ -106,6 +108,8 @@ class Configuration
private boolean mIgnoreBraces = false;
/** name of the cache file **/
private String mCacheFile = null;
/** whether to ignore max line length of import statements **/
private boolean mIgnoreImportLength = false;
/** the header lines to check for **/
private String[] mHeaderLines = {};
@ -150,6 +154,8 @@ class Configuration
getBooleanProperty(aProps, ALLOW_NO_AUTHOR_PROP, mAllowNoAuthor));
setRelaxJavadoc(
getBooleanProperty(aProps, RELAX_JAVADOC_PROP, mRelaxJavadoc));
setIgnoreJavadoc(
getBooleanProperty(aProps, IGNORE_JAVADOC_PROP, mIgnoreJavadoc));
setIgnoreImports(
getBooleanProperty(aProps, IGNORE_IMPORTS_PROP, mIgnoreImports));
setIgnoreWhitespace(
@ -160,6 +166,8 @@ class Configuration
IGNORE_BRACES_PROP,
mIgnoreBraces));
setCacheFile(aProps.getProperty(CACHE_FILE_PROP));
setIgnoreImportLength(getBooleanProperty(
aProps, IGNORE_IMPORT_LENGTH_PROP, mIgnoreImportLength));
setHeaderIgnoreLineNo(
getIntProperty(aProps, aLog, HEADER_IGNORE_LINE_PROP,
mHeaderIgnoreLineNo));
@ -300,6 +308,12 @@ class Configuration
return mRelaxJavadoc;
}
/** @return whether to ignore javadoc checking **/
boolean isIgnoreJavadoc()
{
return mIgnoreJavadoc;
}
/** @return whether to process imports **/
boolean isIgnoreImports()
{
@ -318,6 +332,12 @@ class Configuration
return mIgnoreBraces;
}
/** @return whether to ignore max line length for import statements **/
boolean isIgnoreImportLength()
{
return mIgnoreImportLength;
}
/** @return the header lines to check for **/
String[] getHeaderLines()
{
@ -414,6 +434,14 @@ class Configuration
mMaxLineLength = aMaxLineLength;
}
/**
* @param aIgnoreImportLength whether to allow tabs
*/
void setIgnoreImportLength(boolean aIgnoreImportLength)
{
mIgnoreImportLength = aIgnoreImportLength;
}
/**
* @param aAllowTabs whether to allow tabs
*/
@ -446,6 +474,14 @@ class Configuration
mRelaxJavadoc = aRelaxJavadoc;
}
/**
* @param aIgnoreJavadoc whether to ignore javadoc checking
*/
void setIgnoreJavadoc(boolean aIgnoreJavadoc)
{
mIgnoreJavadoc = aIgnoreJavadoc;
}
/**
* @param aIgnoreImports whether to process imports
*/

View File

@ -50,6 +50,8 @@ interface Defn
String HEADER_IGNORE_LINE_PROP = "checkstyle.header.ignoreline";
/** property name for relaxing checking on Javadoc **/
String RELAX_JAVADOC_PROP = "checkstyle.javadoc.relax";
/** property name for ignoring checking on Javadoc **/
String IGNORE_JAVADOC_PROP = "checkstyle.javadoc.ignore";
/** property name for ignoring import statements **/
String IGNORE_IMPORTS_PROP = "checkstyle.ignore.imports";
/** property name for ignoring whitespace **/
@ -58,4 +60,6 @@ interface Defn
String IGNORE_BRACES_PROP = "checkstyle.ignore.braces";
/** property name for cache file **/
String CACHE_FILE_PROP = "checkstyle.cache.file";
/** property name for ignoring line length of import statements **/
String IGNORE_IMPORT_LENGTH_PROP = "checkstyle.ignore.importlength";
}

View File

@ -142,13 +142,18 @@ class VerifierImpl
{
mLines = aLines;
// Iterate over the lines looking for long lines and tabs
// Iterate over the lines looking for long lines and tabs.
for (int i = 0; i < mLines.length; i++) {
if (mLines[i].length() > mConfig.getMaxLineLength()) {
// check for long line, but possibly allow imports
if ((mLines[i].length() > mConfig.getMaxLineLength()) &&
!(mConfig.isIgnoreImportLength() &&
mLines[i].trim().startsWith("import")))
{
log(i + 1,
"line longer than " + mConfig.getMaxLineLength() +
" characters");
}
if (!mConfig.isAllowTabs() && (mLines[i].indexOf('\t') != -1)) {
log(i + 1, "line contains a tab character");
}
@ -163,6 +168,10 @@ class VerifierImpl
MyCommonAST aReturnType,
MethodSignature aSig)
{
if (mConfig.isIgnoreJavadoc()) {
return; // no need to really check anything
}
// Calculate line number. Unfortunately aReturnType does not contain a
// valid line number
final int lineNo = (aMods.size() > 0)
@ -217,6 +226,19 @@ class VerifierImpl
/** @see Verifier **/
public void verifyType(MyModifierSet aMods, MyCommonAST aType)
{
if (!mConfig.getTypeRegexp().match(aType.getText())) {
log(aType.getLineNo(),
"type name '" + aType.getText() +
"' must match pattern '" + mConfig.getTypePat() + "'.");
}
//
// Only Javadoc testing below
//
if (mConfig.isIgnoreJavadoc()) {
return;
}
final int lineNo = (aMods.size() > 0)
? aMods.getFirstLineNo()
: aType.getLineNo();
@ -231,25 +253,21 @@ class VerifierImpl
{
log(lineNo, "type Javadoc comment is missing an @author tag.");
}
if (!mConfig.getTypeRegexp().match(aType.getText())) {
log(aType.getLineNo(),
"type name '" + aType.getText() +
"' must match pattern '" + mConfig.getTypePat() + "'.");
}
}
/** @see Verifier **/
public void verifyVariable(MyVariable aVar, boolean aInInterface)
{
if (getJavadocBefore(aVar.getLineNo() - 1) == null) {
if (!mConfig.isRelaxJavadoc() || inInterfaceBlock() ||
(aVar.getModifierSet().containsProtected() ||
aVar.getModifierSet().containsPublic()))
{
log(aVar.getLineNo(),
"variable '" + aVar.getText() + "' missing Javadoc.");
if (!mConfig.isIgnoreJavadoc()) {
if (getJavadocBefore(aVar.getLineNo() - 1) == null) {
if (!mConfig.isRelaxJavadoc() || inInterfaceBlock() ||
(aVar.getModifierSet().containsProtected() ||
aVar.getModifierSet().containsPublic()))
{
log(aVar.getLineNo(),
"variable '" + aVar.getText() + "' missing Javadoc.");
}
}
}