diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java
index 8dfb72a72..21e096b34 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckConfiguration.java
@@ -95,10 +95,13 @@ class CheckConfiguration
/**
* Create an instance of the check that is properly initialised.
*
+ * @param aLoader the ClassLoader to create the instance with
* @return the created check
* @throws ClassNotFoundException if an error occurs
* @throws InstantiationException if an error occurs
* @throws IllegalAccessException if an error occurs
+ * @throws InvocationTargetException if an error occurs
+ * @throws NoSuchMethodException if an error occurs
*/
Check createInstance(ClassLoader aLoader)
throws ClassNotFoundException, InstantiationException,
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java
index 8933ca3a4..bc818c75c 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java
@@ -148,11 +148,23 @@ public class Checker
/** vector of listeners */
private final ArrayList mListeners = new ArrayList();
- // TODO: delete me
+ /** used to collect messages TODO: delete */
private final LocalizedMessages mMessages;
+ /** used to walk an AST and notify the checks */
private final TreeWalker mWalker;
+ /**
+ * Creates a new Checker instance.
+ *
+ * @param aConfig the configuration to use
+ * @param aConfigs the configuation of the checks to use
+ * @throws ClassNotFoundException if an error occurs
+ * @throws InstantiationException if an error occurs
+ * @throws IllegalAccessException if an error occurs
+ * @throws InvocationTargetException if an error occurs
+ * @throws NoSuchMethodException if an error occurs
+ */
public Checker(Configuration aConfig, CheckConfiguration[] aConfigs)
throws ClassNotFoundException, InstantiationException,
IllegalAccessException, InvocationTargetException,
@@ -177,6 +189,13 @@ public class Checker
* @param aConfig contains the configuration to check with
* @throws RESyntaxException unable to create a regexp object
* @throws IOException if an error occurs
+ * @throws ParserConfigurationException if an error occurs
+ * @throws SAXException if an error occurs
+ * @throws ClassNotFoundException if an error occurs
+ * @throws InstantiationException if an error occurs
+ * @throws IllegalAccessException if an error occurs
+ * @throws InvocationTargetException if an error occurs
+ * @throws NoSuchMethodException if an error occurs
*/
public Checker(Configuration aConfig)
throws RESyntaxException, IOException,
@@ -441,9 +460,10 @@ public class Checker
"general.fileNotFound", null));
}
catch (IOException ioe) {
- mMessages.add(new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE,
- "general.exception",
- new String[] {ioe.getMessage()}));
+ mMessages.add(new LocalizedMessage(
+ 0, Defn.CHECKSTYLE_BUNDLE,
+ "general.exception",
+ new String[] {ioe.getMessage()}));
}
catch (RecognitionException re) {
mMessages.add(new LocalizedMessage(0, Defn.CHECKSTYLE_BUNDLE,
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
index fef7e7f60..d770802dc 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java
@@ -68,12 +68,10 @@ public class Configuration
PATTERN_DEFAULTS.put(Defn.MEMBER_PATTERN_PROP, "^[a-z][a-zA-Z0-9]*$");
PATTERN_DEFAULTS.put(Defn.PUBLIC_MEMBER_PATTERN_PROP,
"^f[A-Z][a-zA-Z0-9]*$");
- PATTERN_DEFAULTS.put(Defn.TYPE_PATTERN_PROP, "^[A-Z][a-zA-Z0-9]*$");
PATTERN_DEFAULTS.put(Defn.LOCAL_VAR_PATTERN_PROP,
"^[a-z][a-zA-Z0-9]*$");
PATTERN_DEFAULTS.put(Defn.LOCAL_FINAL_VAR_PATTERN_PROP,
"^[a-z][a-zA-Z0-9]*$");
- PATTERN_DEFAULTS.put(Defn.METHOD_PATTERN_PROP, "^[a-z][a-zA-Z0-9]*$");
PATTERN_DEFAULTS.put(Defn.IGNORE_LINE_LENGTH_PATTERN_PROP, "^$");
// Uppercase letters seem rather uncommon, but they're allowed in
@@ -456,18 +454,6 @@ public class Configuration
return getRegexpProperty(Defn.PUBLIC_MEMBER_PATTERN_PROP);
}
- /** @return pattern to match type names **/
- String getTypePat()
- {
- return getPatternProperty(Defn.TYPE_PATTERN_PROP);
- }
-
- /** @return regexp to match type names **/
- RE getTypeRegexp()
- {
- return getRegexpProperty(Defn.TYPE_PATTERN_PROP);
- }
-
/** @return pattern to match local variables **/
String getLocalVarPat()
{
@@ -492,18 +478,6 @@ public class Configuration
return getRegexpProperty(Defn.LOCAL_FINAL_VAR_PATTERN_PROP);
}
- /** @return pattern to match method names **/
- String getMethodPat()
- {
- return getPatternProperty(Defn.METHOD_PATTERN_PROP);
- }
-
- /** @return regexp to match method names **/
- RE getMethodRegexp()
- {
- return getRegexpProperty(Defn.METHOD_PATTERN_PROP);
- }
-
/** @return the maximum line length **/
int getMaxLineLength()
{
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
index ceeb707a6..f5c180789 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java
@@ -39,14 +39,10 @@ public interface Defn
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 method local variable pattern **/
String LOCAL_VAR_PATTERN_PROP = "checkstyle.pattern.localvar";
/** property name for the method local final variable pattern **/
String LOCAL_FINAL_VAR_PATTERN_PROP = "checkstyle.pattern.localfinalvar";
- /** property name for the method local variable pattern **/
- String METHOD_PATTERN_PROP = "checkstyle.pattern.method";
/** property name for the package name pattern **/
String PACKAGE_PATTERN_PROP = "checkstyle.pattern.package";
/** property name for the maximum line length **/
@@ -161,10 +157,8 @@ public interface Defn
MEMBER_PATTERN_PROP,
PUBLIC_MEMBER_PATTERN_PROP,
PACKAGE_PATTERN_PROP,
- TYPE_PATTERN_PROP,
LOCAL_VAR_PATTERN_PROP,
LOCAL_FINAL_VAR_PATTERN_PROP,
- METHOD_PATTERN_PROP,
IGNORE_LINE_LENGTH_PATTERN_PROP,
};
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java
index 6202af258..276a490ab 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java
@@ -27,7 +27,6 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import org.apache.regexp.RESyntaxException;
/**
* Wrapper command line program for the Checker.
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java
index 46e18194e..400ad3170 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java
@@ -77,6 +77,11 @@ class TreeWalker
}
+ /**
+ * Creates a new TreeWalker instance.
+ *
+ * @param aMessages used to collect messages
+ */
public TreeWalker(LocalizedMessages aMessages)
{
mMessages = aMessages;
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java
index 67ea88b0b..21529c451 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java
@@ -248,17 +248,6 @@ class Verifier
**/
void verifyMethod(MethodSignature aSig)
{
- // no need to check constructor names
- if (!aSig.isConstructor()
- && !mConfig.getMethodRegexp().match(aSig.getName().getText()))
- {
- mMessages.add(aSig.getName().getLineNo(),
- aSig.getName().getColumnNo(),
- "name.invalidPattern",
- aSig.getName().getText(),
- mConfig.getMethodPat());
- }
-
// Always check that the order of modifiers follows the JLS suggestion
checkModOrder(aSig.getModSet());
@@ -331,12 +320,6 @@ class Verifier
**/
void verifyType(MyModifierSet aMods, MyCommonAST aType)
{
- if (!mConfig.getTypeRegexp().match(aType.getText())) {
- mMessages.add(aType.getLineNo(), aType.getColumnNo(),
- "name.invalidPattern",
- aType.getText(), mConfig.getTypePat());
- }
-
// Always check that the order of modifiers follows the JLS suggestion
checkModOrder(aMods);
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java
index c12ce4050..d3bcc59a3 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java
@@ -290,7 +290,8 @@ public abstract class Check
* @param aLineNo line number to associate with the message
* @param aColNo column number to associate with the message
* @param aKey key to locale message format
- * @param aArgs arguments for message
+ * @param aArg0 an Object value
+ * @param aArg1 an Object value
*/
public void log(int aLineNo, int aColNo, String aKey,
Object aArg0, Object aArg1)
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessages.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessages.java
index eb1101f1f..4e8eb06a4 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessages.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessages.java
@@ -38,6 +38,9 @@ public class LocalizedMessages
private final int mTabWidth;
/** the lines of the file being checked **/
private String[] mLines;
+ /** Name of the exising resource bundle
+ * TODO: remove this
+ */
private static final String OLD_BUNDLE =
"com.puppycrawl.tools.checkstyle.messages";
@@ -239,6 +242,7 @@ public class LocalizedMessages
add(aLineNo, aColNo, aKey, new Object[] {aArg0, aArg1, aArg2});
}
+ /** @return the number of messages */
public int size()
{
return mMessages.size();
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractFormatCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractFormatCheck.java
new file mode 100644
index 000000000..112e44dae
--- /dev/null
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractFormatCheck.java
@@ -0,0 +1,79 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2002 Oliver Burn
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks;
+
+import com.puppycrawl.tools.checkstyle.api.Check;
+import com.puppycrawl.tools.checkstyle.api.Utils;
+import org.apache.regexp.RESyntaxException;
+import org.apache.regexp.RE;
+import org.apache.commons.beanutils.ConversionException;
+
+/**
+ * Abstract class for checks that verify a name matches a specified regular
+ * expression. Provides support for setting the format of the name.
+ *
+ * @author Oliver Burn
+ * @version 1.0
+ */
+public abstract class AbstractFormatCheck
+ extends Check
+{
+ /** the regexp to match against */
+ private RE mRegexp;
+ /** the format string of the regexp */
+ private String mFormat;
+
+ /**
+ * Creates a new AbstractFormatCheck instance.
+ * @param aDefaultFormat default format
+ * @throws ConversionException unable to parse aDefaultFormat
+ */
+ public AbstractFormatCheck(String aDefaultFormat)
+ {
+ setFormat(aDefaultFormat);
+ }
+
+ /**
+ * Set the format.
+ * @param aFormat a String value
+ * @throws ConversionException unable to parse aFormat
+ */
+ public void setFormat(String aFormat)
+ {
+ try {
+ mRegexp = Utils.getRE(aFormat);
+ mFormat = aFormat;
+ }
+ catch (RESyntaxException e) {
+ throw new ConversionException("unable to parse " + aFormat, e);
+ }
+ }
+
+ /** @return the regexp to match against */
+ public RE getRegexp()
+ {
+ return mRegexp;
+ }
+
+ /** @return the regexp format */
+ public String getFormat()
+ {
+ return mFormat;
+ }
+}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AvoidStarImport.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AvoidStarImport.java
index b2e474c17..6cf672c53 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AvoidStarImport.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AvoidStarImport.java
@@ -35,12 +35,14 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
public class AvoidStarImport
extends ImportCheck
{
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.IMPORT};
}
- public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
+ public void visitToken(DetailAST aAST)
{
final String name = getImportText(aAST);
if ((name != null) && name.endsWith(".*")) {
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EmptyBlockCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EmptyBlockCheck.java
index 6057d7be2..31f5a8d9e 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EmptyBlockCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EmptyBlockCheck.java
@@ -49,11 +49,13 @@ public class EmptyBlockCheck extends Check
// TODO: overwrite mCheckFor based on user settings in config file
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.SLIST};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
// defend against users that change the token set in the config file.
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java
index ae1fcafbf..8858e06a1 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java
@@ -1,3 +1,21 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2002 Oliver Burn
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.Check;
@@ -14,16 +32,16 @@ import com.puppycrawl.tools.checkstyle.api.Check;
*/
public class HeaderCheck extends Check
{
- /** @see Check */
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[0];
}
- /** @see Check */
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void beginTree()
{
String[] lines = getLines();
- log(0,"file has " + lines.length + " lines");
+ log(0, "file has " + lines.length + " lines");
}
}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ImportCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ImportCheck.java
index f873c8f11..f76aff81f 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ImportCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ImportCheck.java
@@ -32,8 +32,15 @@ import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
public abstract class ImportCheck
extends Check
{
+ /** key to store name of import as */
private static final String TEXT_KEY = "name";
+ /**
+ * Return the name of the import associated with a specifed DetailAST.
+ *
+ * @param aAST the node containing the import
+ * @return a String value
+ */
protected String getImportText(DetailAST aAST)
{
String text = (String) getTokenContext().get(TEXT_KEY);
@@ -48,6 +55,12 @@ public abstract class ImportCheck
return text;
}
+ /**
+ * Fills in the name of an import.
+ *
+ * @param aBuf the StringBuffer to add the name to
+ * @param aAST the node to operate on
+ */
private static void extractIdent(StringBuffer aBuf, DetailAST aAST)
{
if (aAST == null) {
@@ -62,7 +75,8 @@ public abstract class ImportCheck
(DetailAST) aAST.getFirstChild().getNextSibling());
}
else if ((aAST.getType() == JavaTokenTypes.IDENT)
- || (aAST.getType() == JavaTokenTypes.STAR)) {
+ || (aAST.getType() == JavaTokenTypes.STAR))
+ {
aBuf.append(aAST.getText());
}
else {
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MethodNameCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MethodNameCheck.java
new file mode 100644
index 000000000..0e8478ca7
--- /dev/null
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MethodNameCheck.java
@@ -0,0 +1,59 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2002 Oliver Burn
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks;
+
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
+
+/**
+ * Checks that method names conform to a specified format.
+ *
+ * @author Oliver Burn
+ * @version 1.0
+ */
+public class MethodNameCheck
+ extends AbstractFormatCheck
+{
+ /** Creates a new MethodNameCheck instance. */
+ public MethodNameCheck()
+ {
+ super("^[a-z][a-zA-Z0-9]*$");
+ }
+
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
+ public int[] getDefaultTokens()
+ {
+ return new int[] {JavaTokenTypes.METHOD_DEF};
+ }
+
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
+ public void visitToken(DetailAST aAST)
+ {
+ final DetailAST nameAST = (DetailAST)
+ aAST.getFirstChild().getNextSibling().getNextSibling();
+
+ if (!getRegexp().match(nameAST.getText())) {
+ log(nameAST.getLineNo(),
+ nameAST.getColumnNo(),
+ "name.invalidPattern",
+ nameAST.getText(),
+ getFormat());
+ }
+ }
+}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java
index 8fc1dfa79..6360184a2 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java
@@ -29,7 +29,8 @@ import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
-public class ModifierCheck extends Check
+public class ModifierCheck
+ extends Check
{
/**
* The order of modifiers as suggested in sections 8.1.1,
@@ -41,11 +42,13 @@ public class ModifierCheck extends Check
"transient", "volatile", "synchronized", "native", "strictfp"
};
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.MODIFIERS};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
final List mods = new ArrayList();
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PackageNameCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PackageNameCheck.java
new file mode 100644
index 000000000..b377127da
--- /dev/null
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PackageNameCheck.java
@@ -0,0 +1,79 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2002 Oliver Burn
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks;
+
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
+
+public class PackageNameCheck
+ extends AbstractFormatCheck
+{
+ /**
+ * Creates a new PackageNameCheck instance.
+ */
+ public PackageNameCheck()
+ {
+ // Uppercase letters seem rather uncommon, but they're allowed in
+ // http://java.sun.com/docs/books/jls/
+ // second_edition/html/packages.doc.html#40169
+ super("^[a-z]+(\\.[a-zA-Z_][a-zA-Z_0-9]*)*$");
+ }
+
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
+ public int[] getDefaultTokens()
+ {
+ return new int[] {JavaTokenTypes.PACKAGE_DEF};
+ }
+
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
+ public void visitToken(DetailAST aAST)
+ {
+ final DetailAST nameAST = (DetailAST) aAST.getFirstChild();
+ final StringBuffer buf = new StringBuffer();
+ extractIdent(buf, nameAST);
+ final String text = buf.toString();
+
+ if (!getRegexp().match(text)) {
+ log(nameAST.getLineNo(),
+ "name.invalidPattern",
+ text,
+ getFormat());
+ }
+ }
+
+ // TODO: refactor to Utils. It should return the text, plus the starting
+ // line and column
+ private static void extractIdent(StringBuffer aBuf, DetailAST aAST)
+ {
+ if (aAST == null) {
+ System.out.println("CALLED WITH NULL");
+ return;
+ }
+
+ if (aAST.getType() == JavaTokenTypes.DOT) {
+ extractIdent(aBuf, (DetailAST) aAST.getFirstChild());
+ aBuf.append(".");
+ extractIdent(aBuf,
+ (DetailAST) aAST.getFirstChild().getNextSibling());
+ }
+ else {
+ aBuf.append(aAST.getText());
+ }
+ }
+}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ParameterFormatCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ParameterFormatCheck.java
index eb2903e22..d5bf30748 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ParameterFormatCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ParameterFormatCheck.java
@@ -1,12 +1,25 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2002 Oliver Burn
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
-import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
-import com.puppycrawl.tools.checkstyle.api.Utils;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
-import org.apache.regexp.RE;
-import org.apache.regexp.RESyntaxException;
-import org.apache.commons.beanutils.ConversionException;
/**
* Checks that the header of the source file is correct.
@@ -19,44 +32,35 @@ import org.apache.commons.beanutils.ConversionException;
* @author Oliver Burn
*/
public class ParameterFormatCheck
- extends Check
+ extends AbstractFormatCheck
{
- private RE mRegexp;
- private String mFormat;
-
+ /**
+ * Creates a new ParameterFormatCheck instance.
+ */
public ParameterFormatCheck()
{
- setFormat("^[a-z][a-zA-Z0-9]*$");
+ super("^[a-z][a-zA-Z0-9]*$");
}
- /** @see Check */
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.PARAMETER_DEF};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
final DetailAST nameAST =
(DetailAST) aAST.getFirstChild().getNextSibling().getNextSibling();
- if (!mRegexp.match(nameAST.getText())) {
+ if (!getRegexp().match(nameAST.getText())) {
log(nameAST.getLineNo(),
nameAST.getColumnNo(),
"name.invalidPattern",
nameAST.getText(),
- mFormat);
+ getFormat());
}
}
- public void setFormat(String aFormat)
- {
- try {
- mRegexp = Utils.getRE(aFormat);
- mFormat = aFormat;
- }
- catch (RESyntaxException e) {
- throw new ConversionException("unable to parse " + aFormat, e);
- }
- }
}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RedundantModifierCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RedundantModifierCheck.java
index 05153bfc8..7230e6321 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RedundantModifierCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RedundantModifierCheck.java
@@ -1,3 +1,21 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2002 Oliver Burn
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
import java.util.Stack;
@@ -12,58 +30,60 @@ public class RedundantModifierCheck extends Check implements JavaTokenTypes
{
private final Stack mInInterface = new Stack();
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void beginTree()
{
super.beginTree();
mInInterface.clear();
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {MODIFIERS, INTERFACE_DEF, CLASS_DEF};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
- switch (aAST.getType())
- {
- case INTERFACE_DEF:
- mInInterface.push(Boolean.TRUE);
- break;
- case CLASS_DEF:
- mInInterface.push(Boolean.FALSE);
- break;
- case MODIFIERS:
+ switch (aAST.getType()) {
+ case INTERFACE_DEF:
+ mInInterface.push(Boolean.TRUE);
+ break;
+ case CLASS_DEF:
+ mInInterface.push(Boolean.FALSE);
+ break;
+ case MODIFIERS:
- // modifiers of the interface itself (public interface X)
- // will be below the INTERFACE_DEF node. Example:
+ // modifiers of the interface itself (public interface X)
+ // will be below the INTERFACE_DEF node. Example:
- // public interface X {void y();}
+ // public interface X {void y();}
- // INTERFACE_DEF
- // + MODUFIERS
- // + public
- // + OBJ_BLOCK
- // + ...
+ // INTERFACE_DEF
+ // + MODUFIERS
+ // + public
+ // + OBJ_BLOCK
+ // + ...
- if (inInterfaceBlock(aAST)) {
- DetailAST ast = (DetailAST) aAST.getFirstChild();
- while (ast != null) {
- String modifier = ast.getText();
- if ("public".equals(modifier)
- || "abstract".equals(modifier))
- {
- log(ast.getLineNo(),
- ast.getColumnNo(),
- "redundantModifier",
- new String[] {modifier});
- }
- ast = (DetailAST) ast.getNextSibling();
+ if (inInterfaceBlock(aAST)) {
+ DetailAST ast = (DetailAST) aAST.getFirstChild();
+ while (ast != null) {
+ String modifier = ast.getText();
+ if ("public".equals(modifier)
+ || "abstract".equals(modifier))
+ {
+ log(ast.getLineNo(),
+ ast.getColumnNo(),
+ "redundantModifier",
+ new String[] {modifier});
}
+ ast = (DetailAST) ast.getNextSibling();
}
- break;
- default:
- return;
+ }
+ break;
+ default:
+ return;
}
}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java
index b4f3f2dd3..ece602ff4 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java
@@ -32,11 +32,13 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
*/
public class SimplifyBooleanReturnCheck extends Check
{
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.LITERAL_if};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
// paranoia - what an untrusting sole :-)
@@ -72,14 +74,15 @@ public class SimplifyBooleanReturnCheck extends Check
private boolean isBooleanLiteralReturnStatement(AST aAST)
{
- if (aAST.getType() != JavaTokenTypes.LITERAL_return)
+ if (aAST.getType() != JavaTokenTypes.LITERAL_return) {
return false;
+ }
- AST expr = aAST.getFirstChild();
- AST value = expr.getFirstChild();
+ final AST expr = aAST.getFirstChild();
+ final AST value = expr.getFirstChild();
- int valueType = value.getType();
- return ( valueType == JavaTokenTypes.LITERAL_true
- || valueType == JavaTokenTypes.LITERAL_false );
+ final int valueType = value.getType();
+ return ((valueType == JavaTokenTypes.LITERAL_true)
+ || (valueType == JavaTokenTypes.LITERAL_false));
}
}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/TypeNameCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/TypeNameCheck.java
new file mode 100644
index 000000000..a250aeacf
--- /dev/null
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/TypeNameCheck.java
@@ -0,0 +1,66 @@
+////////////////////////////////////////////////////////////////////////////////
+// checkstyle: Checks Java source code for adherence to a set of rules.
+// Copyright (C) 2001-2002 Oliver Burn
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle.checks;
+
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
+
+/**
+ * Checks that the header of the source file is correct.
+ *
+ *
+ * Rationale: In most projects each file must have a fixed header, + * usually the header contains copyright information. + *
+ * + * @author Oliver Burn + */ +public class TypeNameCheck + extends AbstractFormatCheck +{ + + /** + * Creates a newTypeNameCheck instance.
+ */
+ public TypeNameCheck()
+ {
+ super("^[A-Z][a-zA-Z0-9]*$");
+ }
+
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
+ public int[] getDefaultTokens()
+ {
+ return new int[] {JavaTokenTypes.CLASS_DEF,
+ JavaTokenTypes.INTERFACE_DEF};
+ }
+
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
+ public void visitToken(DetailAST aAST)
+ {
+ final DetailAST nameAST =
+ (DetailAST) aAST.getFirstChild().getNextSibling();
+ if (!getRegexp().match(nameAST.getText())) {
+ log(nameAST.getLineNo(),
+ nameAST.getColumnNo(),
+ "name.invalidPattern",
+ nameAST.getText(),
+ getFormat());
+ }
+ }
+}
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UnusedImportsCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UnusedImportsCheck.java
index e6e0e65f4..6dc4303a0 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UnusedImportsCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UnusedImportsCheck.java
@@ -33,10 +33,14 @@ import java.util.Iterator;
*/
public class UnusedImportsCheck extends ImportCheck
{
+ /** flag to indicate when time to start collecting references */
private boolean mCollect;
+ /** set of the imports */
private final Set mImports = new HashSet();
+ /** set of references - possibly to imports or other things */
private final Set mReferenced = new HashSet();
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void beginTree()
{
mCollect = false;
@@ -44,6 +48,7 @@ public class UnusedImportsCheck extends ImportCheck
mReferenced.clear();
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void finishTree()
{
// loop over all the imports to see if referenced.
@@ -56,6 +61,7 @@ public class UnusedImportsCheck extends ImportCheck
}
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.IMPORT,
@@ -64,6 +70,7 @@ public class UnusedImportsCheck extends ImportCheck
JavaTokenTypes.IDENT};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
if (aAST.getType() == JavaTokenTypes.IDENT) {
@@ -81,6 +88,10 @@ public class UnusedImportsCheck extends ImportCheck
}
}
+ /**
+ * Collects references made by IDENT.
+ * @param aAST the IDENT node to process
+ */
private void processIdent(DetailAST aAST)
{
// TODO: should be a lot smarter in selection. Currently use
@@ -96,6 +107,10 @@ public class UnusedImportsCheck extends ImportCheck
}
}
+ /**
+ * Collects the details of imports.
+ * @param aAST node containing the import details
+ */
private void processImport(DetailAST aAST)
{
final String name = getImportText(aAST);
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java
index 2d9760e24..d07c96c5f 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java
@@ -35,11 +35,13 @@ import com.puppycrawl.tools.checkstyle.api.Check;
public class UpperEllCheck
extends Check
{
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.NUM_LONG};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
if (aAST.getText().endsWith("l")) {
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java
index 778ccf37b..36580eaa7 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/WhitespaceAroundCheck.java
@@ -23,8 +23,11 @@ import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.Java14TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
-public class WhitespaceAroundCheck extends Check implements Java14TokenTypes
+public class WhitespaceAroundCheck
+ extends Check
+ implements Java14TokenTypes
{
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {
@@ -75,6 +78,7 @@ public class WhitespaceAroundCheck extends Check implements Java14TokenTypes
};
}
+ /** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
final String[] lines = getLines();
@@ -89,7 +93,8 @@ public class WhitespaceAroundCheck extends Check implements Java14TokenTypes
if ((after < line.length())
&& !Character.isWhitespace(line.charAt(after))
- && !(aAST.getType() == LITERAL_return && aAST.getFirstChild() == null))
+ && !((aAST.getType() == LITERAL_return)
+ && (aAST.getFirstChild() == null)))
{
log(aAST.getLineNo(), aAST.getColumnNo() + aAST.getText().length(),
"ws.notFollowed", new Object[]{aAST.getText()});
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
index 9c320e8b1..1f4976258 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java
@@ -502,7 +502,6 @@ public class CheckerTest
filepath + ":130:18: Name 'I' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
filepath + ":131:9: '{' should be on the previous line.",
filepath + ":132:20: Name 'InnerBlockVariable' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
- filepath + ":137:10: Name 'ALL_UPPERCASE_METHOD' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
filepath + ":142:30: Name 'BAD__NAME' must match pattern '^[A-Z](_?[A-Z0-9]+)*$'.",
filepath + ":145: Line is longer than 80 characters.",
filepath + ":145:35: Line contains a tab character.",
@@ -727,7 +726,6 @@ public class CheckerTest
final String[] expected = {
filepath + ":1: Missing a header - not enough lines in file.",
filepath + ":1: Missing a Javadoc comment.",
- filepath + ":1:48: Name 'inputHeader' must match pattern '^[A-Z][a-zA-Z0-9]*$'.",
};
verify(c, filepath, expected);
}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java b/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java
index 9672dda49..a1be4e16c 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java
@@ -6,7 +6,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
-import java.util.Properties;
import junit.framework.TestCase;
import org.apache.regexp.RE;
@@ -40,26 +39,6 @@ public class ConfigSerializationTest
return configCopy;
}
- /**
- * Test that the RE deserialization mechanism works for one example.
- */
- public void testRegexpDeserialization()
- throws Exception
- {
- final Properties props = new Properties();
- props.setProperty(Defn.TYPE_PATTERN_PROP, "xyz");
- Configuration configOrig = new Configuration(props, System.out);
-
- Configuration configCopy = copyBySerialization(configOrig);
- assertNotNull(configCopy);
- assertNotNull(configCopy.getClassLoader());
-
- // test that the general deserialization mechanism for RE fields works
- RE typeRegexp = configCopy.getTypeRegexp();
- assertTrue(typeRegexp.match("xyz"));
- assertTrue(!typeRegexp.match("DefaultCompatibleTypeFormat"));
- }
-
/**
* Tests that all RE fields are restored during deserialization.
* This test is designed to prevent addition of transient RE
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/MethodNameCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/MethodNameCheckTest.java
new file mode 100644
index 000000000..4418214e3
--- /dev/null
+++ b/src/tests/com/puppycrawl/tools/checkstyle/MethodNameCheckTest.java
@@ -0,0 +1,28 @@
+package com.puppycrawl.tools.checkstyle;
+
+import com.puppycrawl.tools.checkstyle.checks.AvoidStarImport;
+import com.puppycrawl.tools.checkstyle.checks.ParameterFormatCheck;
+import com.puppycrawl.tools.checkstyle.checks.TypeNameCheck;
+import com.puppycrawl.tools.checkstyle.checks.MethodNameCheck;
+
+public class MethodNameCheckTest
+ extends BaseCheckTestCase
+{
+ public MethodNameCheckTest(String aName)
+ {
+ super(aName);
+ }
+
+ public void testDefault()
+ throws Exception
+ {
+ final CheckConfiguration checkConfig = new CheckConfiguration();
+ checkConfig.setClassname(MethodNameCheck.class.getName());
+ final Checker c = createChecker(checkConfig);
+ final String fname = getPath("InputSimple.java");
+ final String[] expected = {
+ "137:10: Name 'ALL_UPPERCASE_METHOD' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
+ };
+ verify(c, fname, expected);
+ }
+}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/PackageNameCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/PackageNameCheckTest.java
new file mode 100644
index 000000000..a66f51d11
--- /dev/null
+++ b/src/tests/com/puppycrawl/tools/checkstyle/PackageNameCheckTest.java
@@ -0,0 +1,42 @@
+package com.puppycrawl.tools.checkstyle;
+
+import com.puppycrawl.tools.checkstyle.checks.AvoidStarImport;
+import com.puppycrawl.tools.checkstyle.checks.ParameterFormatCheck;
+import com.puppycrawl.tools.checkstyle.checks.TypeNameCheck;
+import com.puppycrawl.tools.checkstyle.checks.MethodNameCheck;
+import com.puppycrawl.tools.checkstyle.checks.PackageNameCheck;
+
+public class PackageNameCheckTest
+ extends BaseCheckTestCase
+{
+ public PackageNameCheckTest(String aName)
+ {
+ super(aName);
+ }
+
+ public void testSpecified()
+ throws Exception
+ {
+ final CheckConfiguration checkConfig = new CheckConfiguration();
+ checkConfig.setClassname(PackageNameCheck.class.getName());
+ checkConfig.addProperty("format", "[A-Z]+");
+ final Checker c = createChecker(checkConfig);
+ final String fname = getPath("InputSimple.java");
+ final String[] expected = {
+ "6:1: Name 'com.puppycrawl.tools.checkstyle' must match pattern '[A-Z]+'.",
+ };
+ verify(c, fname, expected);
+ }
+
+ public void testDefault()
+ throws Exception
+ {
+ final CheckConfiguration checkConfig = new CheckConfiguration();
+ checkConfig.setClassname(PackageNameCheck.class.getName());
+ final Checker c = createChecker(checkConfig);
+ final String fname = getPath("InputSimple.java");
+ final String[] expected = {
+ };
+ verify(c, fname, expected);
+ }
+}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/ParameterFormatCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/ParameterFormatCheckTest.java
index 3e1c77dff..81f9e0a39 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/ParameterFormatCheckTest.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/ParameterFormatCheckTest.java
@@ -4,7 +4,7 @@ import com.puppycrawl.tools.checkstyle.checks.AvoidStarImport;
import com.puppycrawl.tools.checkstyle.checks.ParameterFormatCheck;
public class ParameterFormatCheckTest
-extends BaseCheckTestCase
+ extends BaseCheckTestCase
{
public ParameterFormatCheckTest(String aName)
{
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/TypeNameCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/TypeNameCheckTest.java
new file mode 100644
index 000000000..eecdfe0f3
--- /dev/null
+++ b/src/tests/com/puppycrawl/tools/checkstyle/TypeNameCheckTest.java
@@ -0,0 +1,40 @@
+package com.puppycrawl.tools.checkstyle;
+
+import com.puppycrawl.tools.checkstyle.checks.AvoidStarImport;
+import com.puppycrawl.tools.checkstyle.checks.ParameterFormatCheck;
+import com.puppycrawl.tools.checkstyle.checks.TypeNameCheck;
+
+public class TypeNameCheckTest
+ extends BaseCheckTestCase
+{
+ public TypeNameCheckTest(String aName)
+ {
+ super(aName);
+ }
+
+ public void testSpecified()
+ throws Exception
+ {
+ final CheckConfiguration checkConfig = new CheckConfiguration();
+ checkConfig.setClassname(TypeNameCheck.class.getName());
+ checkConfig.addProperty("format", "^inputHe");
+ final Checker c = createChecker(checkConfig);
+ final String fname = getPath("inputHeader.java");
+ final String[] expected = {
+ };
+ verify(c, fname, expected);
+ }
+
+ public void testDefault()
+ throws Exception
+ {
+ final CheckConfiguration checkConfig = new CheckConfiguration();
+ checkConfig.setClassname(TypeNameCheck.class.getName());
+ final Checker c = createChecker(checkConfig);
+ final String fname = getPath("inputHeader.java");
+ final String[] expected = {
+ "1:48: Name 'inputHeader' must match pattern '^[A-Z][a-zA-Z0-9]*$'."
+ };
+ verify(c, fname, expected);
+ }
+}