From d3f39e6b87a10ee26aa8da532b545e54090e7761 Mon Sep 17 00:00:00 2001
From: Oliver Burn
Date: Sun, 5 Aug 2001 06:41:59 +0000
Subject: [PATCH] Added support for public member patterns.
---
ChangeLog | 5 +
build.xml | 467 +++++++++---------
docs/anttask.html | 51 +-
docs/cmdline.html | 8 +-
docs/index.html | 10 +
.../tools/checkstyle/CheckStyleTask.java | 12 +
.../tools/checkstyle/Configuration.java | 33 ++
.../com/puppycrawl/tools/checkstyle/Defn.java | 2 +
.../tools/checkstyle/VerifierImpl.java | 12 +-
.../tools/checkstyle/CheckerTest.java | 26 +-
.../tools/checkstyle/InputInner.java | 4 +-
.../tools/checkstyle/InputSimple.java | 4 +-
12 files changed, 365 insertions(+), 269 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b0e723883..297f6e2b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2001-08-05 Oliver Burn
+
+ * src/checkstyle/com/puppycrawl/tools/checkstyle/VerifierImpl.java, src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java, src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java:
+ Added support for public member patterns.
+
2001-07-02 Oliver Burn
* docs/index.html: Added that can ignore checking braces.
diff --git a/build.xml b/build.xml
index 42e48f1cf..aafa639af 100644
--- a/build.xml
+++ b/build.xml
@@ -1,233 +1,234 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/anttask.html b/docs/anttask.html
index 7f66f9d46..69af375ee 100644
--- a/docs/anttask.html
+++ b/docs/anttask.html
@@ -16,9 +16,9 @@
This task is included in the checkstyle distribution.
Installation
-The easiest way is to include checkstyle-all-1.1.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:
+The easiest way is to include checkstyle-all-@@VERSION@@.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:
- - checkstyle-1.1.jar
+ - checkstyle-@@VERSION@@.jar
- ANTLR 2.7.1 classes. antlr.jar is included in the distribution.
- Jakarta Regexp 1.2 classes. jakarta-regexp-1.2.jar is included in the distribution.
@@ -43,77 +43,82 @@ This task is included in the checkstyle distribution.
One of either file or at least one nested fileset element |
- | allowtabs |
+ allowTabs |
Indicates whether to allow tabs. Defaults to "false". |
No |
- | allowprotected |
+ allowProtected |
Indicates whether to allow protected data. Defaults to "false". |
No |
- | allownoauthor |
+ allowNoAuthor |
Indicates whether to allow no @author tag to be defined for class and interface Javadoc comments. Defaults to "false". |
No |
- | maxlinelen |
+ maxLineLen |
Specifies the maximum line length. Default value is defined here. |
No |
- | memberpattern |
+ memberPattern |
Specifies the regular expression to match against member variables. Default value is defined here. |
No |
- | parampattern |
+ publicMemberPattern |
+ Specifies the regular expression to match against public member variables. Default value is defined here. |
+ No |
+
+
+ | paramPattern |
Specifies the regular expression to match against parameters. Default value is defined here. |
No |
- | constpattern |
+ constPattern |
Specifies the regular expression to match against static/final variables. Default value is defined here. |
No |
- | staticpattern |
+ staticPattern |
Specifies the regular expression to match against static variables. Default value is defined here. |
No |
- | typepattern |
+ typePattern |
Specifies the regular expression to match against type names. Default value is defined here. |
No |
- | headerfile |
+ headerFile |
Specifies the file containing the header lines. Default is to not check. |
No |
- | headerignoreline |
+ headerIgnoreLine |
Specifies the line in the header to ignore when comparing. Default it to not ignore any line. |
No |
- | relaxjavadoc |
+ relaxJavadoc |
Specifies whether to relax checking Javadoc comments. Defaults to "false". |
No |
- | ignoreimports |
+ ignoreImports |
Specifies whether to ignore checking import statements. Defaults to "false". |
No |
- | ignorewhitespace |
+ ignoreWhitespace |
Specifies whether to ignore checking whitespace. Defaults to "false". |
No |
- | ignorebraces |
+ ignoreBraces |
Specifies whether to ignore checking braces. Defaults to "false". |
No |
@@ -134,18 +139,18 @@ This task is included in the checkstyle distribution.
Run checkstyle on a set of Java files and allow tabs
- <checkstyle allowtabs="yes">
+ <checkstyle allowTabs="yes">
<fileset dir="src/checkstyle" includes="**/*.java"/>
</checkstyle>
Run checkstyle on a set of Java files and disable pattern matching
- <checkstyle allowtabs="yes">
- parampattern="."
- constpattern="."
- staticpattern="."
- memberpattern="."
+ <checkstyle allowTabs="yes">
+ paramPattern="."
+ constPattern="."
+ staticPattern="."
+ memberPattern="."
<fileset dir="src/checkstyle" includes="**/*.java"/>
</checkstyle>
diff --git a/docs/cmdline.html b/docs/cmdline.html
index 930219f31..3a04b50da 100644
--- a/docs/cmdline.html
+++ b/docs/cmdline.html
@@ -18,9 +18,9 @@ This command line tool is included in the checkstyle distribution.
Installation
-The easiest way is to include checkstyle-all-1.0.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:
+The easiest way is to include checkstyle-all-@@VERSION@@.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:
- - checkstyle-1.0.jar
+ - checkstyle-@@VERSION@@.jar
- ANTLR 2.7.1 classes. antlr.jar is included in the distribution.
- Jakarta Regexp 1.2 classes. jakarta-regexp-1.2.jar is included in the distribution.
@@ -59,6 +59,10 @@ This command line tool is included in the checkstyle distribution.
checkstyle.pattern.member |
Specifies the regular expression to match against member variables. Default value is defined here. |
+
+ | checkstyle.pattern.publicmember |
+ Specifies the regular expression to match against public member variables. Default value is defined here. |
+
| checkstyle.pattern.parameter |
Specifies the regular expression to match against parameters. Default value is defined here. |
diff --git a/docs/index.html b/docs/index.html
index 80516bf24..d28074d29 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -169,6 +169,11 @@ div.tip {margin-left : 5%;margin-right : 5%;padding-left: 2%; padding-right: 2%;
^m[A-Z][a-zA-Z0-9]*$ |
private int mNumCreated = 0; |
+
+ | non static public |
+ ^f[A-Z][a-zA-Z0-9]*$ |
+ public int fCMPField; |
+
@@ -185,6 +190,11 @@ div.tip {margin-left : 5%;margin-right : 5%;padding-left: 2%; padding-right: 2%;
Note: you can turn on allowing protected data members.
+
+
Tip
+
Container Managed Persistence EJBs require that managed fields are declared public. This will cause checkstyle to complain that the fields should be declared private. Hence checkstyle supports ignoring public that match a specified regular expression. The default is ^f[A-Z][a-zA-Z0-9]*$.
+
+
White space
Checks for the following use of white space:
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java
index c35242db3..f174406fd 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java
@@ -99,6 +99,18 @@ public class CheckStyleTask
}
}
+ /** @param aPat pattern for public member variables **/
+ public void setPublicMemberPattern(String aPat)
+ {
+ try {
+ mConfig.setPublicMemberPat(aPat);
+ }
+ catch (RESyntaxException ex) {
+ throw new BuildException("Unable to parse publicmemberpattern - " +
+ ex.getMessage());
+ }
+ }
+
/** @param aPat pattern for parameters **/
public void setParamPattern(String aPat)
{
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
index 2bcf5d435..1756ef798 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
@@ -47,6 +47,8 @@ class Configuration
private static final String CONST_PATTERN = "^[A-Z]([A-Z0-9_]*[A-Z0-9])?$";
/** the pattern to match against member names **/
private static final String MEMBER_PATTERN = "^m[A-Z][a-zA-Z0-9]*$";
+ /** the pattern to match against public member names **/
+ private static final String PUBLIC_MEMBER_PATTERN = "^f[A-Z][a-zA-Z0-9]*$";
/** the pattern to match against type names **/
private static final String TYPE_PATTERN = "^[A-Z][a-zA-Z0-9]*$";
/** The maximum line length **/
@@ -76,6 +78,11 @@ class Configuration
/** regexp to match member variables **/
private RE mMemberRegexp;
+ /** pattern to match public member variables **/
+ private String mPublicMemberPat;
+ /** regexp to match public member variables **/
+ private RE mPublicMemberRegexp;
+
/** pattern to match type names **/
private String mTypePat;
/** regexp to match type names **/
@@ -127,6 +134,8 @@ class Configuration
CONST_PATTERN));
setMemberPat(aProps.getProperty(MEMBER_PATTERN_PROP,
MEMBER_PATTERN));
+ setPublicMemberPat(aProps.getProperty(PUBLIC_MEMBER_PATTERN_PROP,
+ PUBLIC_MEMBER_PATTERN));
setTypePat(aProps.getProperty(TYPE_PATTERN_PROP,
TYPE_PATTERN));
setMaxLineLength(getIntProperty(
@@ -172,6 +181,7 @@ class Configuration
setStaticPat(STATIC_PATTERN);
setStaticFinalPat(CONST_PATTERN);
setMemberPat(MEMBER_PATTERN);
+ setPublicMemberPat(PUBLIC_MEMBER_PATTERN);
setTypePat(TYPE_PATTERN);
}
catch (RESyntaxException ex) {
@@ -233,6 +243,18 @@ class Configuration
return mMemberRegexp;
}
+ /** @return pattern to match public member variables **/
+ String getPublicMemberPat()
+ {
+ return mPublicMemberPat;
+ }
+
+ /** @return regexp to match public member variables **/
+ RE getPublicMemberRegexp()
+ {
+ return mPublicMemberRegexp;
+ }
+
/** @return pattern to match type names **/
String getTypePat()
{
@@ -353,6 +375,17 @@ class Configuration
mMemberPat = aMemberPat;
}
+ /**
+ * @param aPublicMemberPat pattern to match public member variables
+ * @throws RESyntaxException if an error occurs
+ */
+ void setPublicMemberPat(String aPublicMemberPat)
+ throws RESyntaxException
+ {
+ mPublicMemberRegexp = new RE(aPublicMemberPat);
+ mPublicMemberPat = aPublicMemberPat;
+ }
+
/**
* @param aTypePat pattern to match type names
* @throws RESyntaxException if an error occurs
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
index d5290e12d..1cdb91886 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
@@ -32,6 +32,8 @@ interface Defn
String CONST_PATTERN_PROP = "checkstyle.pattern.const";
/** property name for the member variable pattern **/
String MEMBER_PATTERN_PROP = "checkstyle.pattern.member";
+ /** property name for the public member variable pattern **/
+ String PUBLIC_MEMBER_PATTERN_PROP = "checkstyle.pattern.publicmember";
/** property name for the type pattern **/
String TYPE_PATTERN_PROP = "checkstyle.pattern.type";
/** property name for the maximum line length **/
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/VerifierImpl.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/VerifierImpl.java
index 60a60466c..d5bb0bd92 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/VerifierImpl.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/VerifierImpl.java
@@ -264,9 +264,10 @@ class VerifierImpl
else {
final MyModifierSet mods = aVar.getModifierSet();
- if (mods.containsPrivate()) {
- System.out.println("Need to check for " + aVar.getText());
- }
+ // Logic to detect unused variables
+ //if (mods.containsPrivate()) {
+ // System.out.println("Need to check for " + aVar.getText());
+ //}
// Checks for Javadoc
if (mods.containsStatic()) {
@@ -301,6 +302,11 @@ class VerifierImpl
mConfig.getMemberRegexp(),
mConfig.getMemberPat());
}
+ else if (mods.containsPublic() &&
+ mConfig.getPublicMemberRegexp().match(aVar.getText()))
+ {
+ // silently allow
+ }
else {
log(aVar.getLineNo(),
"variable '" + aVar.getText() +
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
index fab35ecf0..6e612c7e4 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
@@ -155,14 +155,32 @@ public class CheckerTest
assertNotNull(c);
final String[] expected = {
"InputInner.java:14: type is missing a Javadoc comment.",
- "InputInner.java:17: variable 'data' missing Javadoc.",
- "InputInner.java:17: variable 'data' must be private and have accessor methods.",
+ "InputInner.java:17: variable 'fData' missing Javadoc.",
"InputInner.java:21: type is missing a Javadoc comment.",
"InputInner.java:24: variable 'data' missing Javadoc.",
"InputInner.java:24: variable 'data' must match pattern '^[A-Z]([A-Z0-9_]*[A-Z0-9])?$'.",
"InputInner.java:27: type is missing a Javadoc comment.",
- "InputInner.java:30: variable 'data' missing Javadoc.",
- "InputInner.java:30: variable 'data' must be private and have accessor methods."
+ "InputInner.java:30: variable 'rData' missing Javadoc.",
+ "InputInner.java:30: variable 'rData' must be private and have accessor methods."
+ };
+ verify(c, "InputInner.java", expected);
+ }
+
+ public void testIgnorePublic()
+ throws Exception
+ {
+ mConfig.setPublicMemberPat("^r[A-Z]");
+ final Checker c = new Checker(mConfig, mStream);
+ assertNotNull(c);
+ final String[] expected = {
+ "InputInner.java:14: type is missing a Javadoc comment.",
+ "InputInner.java:17: variable 'fData' missing Javadoc.",
+ "InputInner.java:17: variable 'fData' must be private and have accessor methods.",
+ "InputInner.java:21: type is missing a Javadoc comment.",
+ "InputInner.java:24: variable 'data' missing Javadoc.",
+ "InputInner.java:24: variable 'data' must match pattern '^[A-Z]([A-Z0-9_]*[A-Z0-9])?$'.",
+ "InputInner.java:27: type is missing a Javadoc comment.",
+ "InputInner.java:30: variable 'rData' missing Javadoc.",
};
verify(c, "InputInner.java", expected);
}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputInner.java b/src/tests/com/puppycrawl/tools/checkstyle/InputInner.java
index 150689a33..4e5283626 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/InputInner.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/InputInner.java
@@ -14,7 +14,7 @@ class InputInner
class InnerInner2
{
// Ignore
- public int data;
+ public int fData;
}
// Ignore - 2 errors
@@ -27,7 +27,7 @@ class InputInner
class InnerInterfaceInnerClass
{
// Ignore - need Javadoc and made private
- int data;
+ public int rData;
}
}
}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputSimple.java b/src/tests/com/puppycrawl/tools/checkstyle/InputSimple.java
index 111fe7e63..a5968aa61 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/InputSimple.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/InputSimple.java
@@ -49,9 +49,9 @@ class InputSimple
static int sTest2;
/** should be private **/
- public int mTest1;
+ int mTest1;
/** should be private **/
- int mTest2;
+ public int mTest2;
//
// Parameter name format tests