From 7f35e143a2472ecb49625cc841bd0482fe3dfeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Thu, 17 Oct 2002 22:52:25 +0000 Subject: [PATCH] cleanup of checkstyle errors --- .../tools/checkstyle/api/DetailAST.java | 3 +- .../tools/checkstyle/checks/HeaderCheck.java | 8 ++++- .../checkstyle/checks/ModifierCheck.java | 12 +++++++ .../checkstyle/checks/RegexpHeaderCheck.java | 7 +++- .../checks/SimplifyBooleanReturnCheck.java | 34 +++++++++++++++++++ .../checks/VisibilityModifierCheck.java | 12 ++++--- .../tools/checkstyle/gui/JTreeTable.java | 21 ++++++++---- .../tools/checkstyle/CheckerTest.java | 1 - .../checkstyle/MethodLengthCheckTest.java | 19 +++++++++++ 9 files changed, 102 insertions(+), 15 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/DetailAST.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/DetailAST.java index bc64787ba..2b39b1ae4 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/DetailAST.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/DetailAST.java @@ -94,7 +94,8 @@ public class DetailAST * Set the parent token. * @param aParent the parent token */ - // TODO: Check visibility, could be private if set in setFirstChild() and friends + // TODO: Check visibility, could be private + // if set in setFirstChild() and friends public void setParent(DetailAST aParent) { mParent = aParent; diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java index 4a2dc0bb2..462bab06c 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/HeaderCheck.java @@ -40,7 +40,8 @@ import org.apache.commons.beanutils.ConversionException; */ public class HeaderCheck extends Check { - private static int[] EMPTY_INT_ARRAY = new int[0]; + /** empty array to avoid instantiations */ + private static final int[] EMPTY_INT_ARRAY = new int[0]; /** the lines of the header file */ private String[] mHeaderLines = null; @@ -102,6 +103,7 @@ public class HeaderCheck extends Check /** * Set the header file to check against. + * @param aFileName the file that contains the header to check against. * @throws org.apache.commons.beanutils.ConversionException if * the file cannot be loaded */ @@ -149,6 +151,10 @@ public class HeaderCheck extends Check Arrays.sort(mIgnoreLines); } + /** + * Return the header lines to check against. + * @return the header lines to check against. + */ protected String[] getHeaderLines() { return mHeaderLines; diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java index 7ebed25dd..8df922b2c 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/ModifierCheck.java @@ -29,6 +29,17 @@ import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.JavaTokenTypes; import com.puppycrawl.tools.checkstyle.api.DetailAST; +/** + * Checks that modifiers are written in the order suggested by + * the Java Language Specification (JLS). The relevant sections + * are 8.1.1, 8.3.1 and 8.4.3. + *

+ * Rationale: Code is easier to read if everybody follows + * a standard. + *

+ * + * @author Lars Kühne + */ public class ModifierCheck extends Check { @@ -72,6 +83,7 @@ public class ModifierCheck * Checks if the modifiers were added in the order suggested * in the Java language specification. * + * @param aModifiers list of modifier AST tokens * @return null if the order is correct, otherwise returns the offending * * modifier AST. */ diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RegexpHeaderCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RegexpHeaderCheck.java index 531400d0e..29e17777e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RegexpHeaderCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/RegexpHeaderCheck.java @@ -27,7 +27,12 @@ public class RegexpHeaderCheck extends HeaderCheck /** the compiled regular expressions */ private RE[] mHeaderRegexps = null; - /** */ + /** + * Sets the file that contains the header to check against. + * @param aFileName the file that contains the header to check against. + * @throws org.apache.commons.beanutils.ConversionException if + * the file cannot be loaded or one line is not a regexp. + */ public void setHeaderFile(String aFileName) { super.setHeaderFile(aFileName); diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java index ece602ff4..8bf256b45 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java @@ -29,6 +29,8 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST; * Checks for overly complicated boolean return statements. * * Idea shamelessly stolen from the equivalent PMD rule (pmd.sourceforge.net). + * + * @author Lars Kühne */ public class SimplifyBooleanReturnCheck extends Check { @@ -62,6 +64,26 @@ public class SimplifyBooleanReturnCheck extends Check } } + /** + * Returns if an AST is a return statment with a boolean literal + * or a compound statement that contains only such a return statement. + * + * Returns true iff aAST represents + *
+ *
+     * return true/false;
+     * 
+     * or
+     * 
+ *
+     * {
+     *   return true/false;
+     * }
+     * 
+     *
+     * @param aAST the sytax tree to check
+     * @return if aAST is a return statment with a boolean literal.
+     */
     private boolean returnsOnlyBooleanLiteral(AST aAST)
     {
         if (isBooleanLiteralReturnStatement(aAST)) {
@@ -72,6 +94,18 @@ public class SimplifyBooleanReturnCheck extends Check
         return isBooleanLiteralReturnStatement(firstStmnt);
     }
 
+    /**
+     * Returns if an AST is a return statment with a boolean literal.
+     *
+     * Returns true iff aAST represents
+     * 
+ *
+     * return true/false;
+     * 
+     *
+     * @param aAST the sytax tree to check
+     * @return if aAST is a return statment with a boolean literal.
+     */
     private boolean isBooleanLiteralReturnStatement(AST aAST)
     {
         if (aAST.getType() != JavaTokenTypes.LITERAL_return) {
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/VisibilityModifierCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/VisibilityModifierCheck.java
index f861aae7b..528593cfa 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/VisibilityModifierCheck.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/VisibilityModifierCheck.java
@@ -40,6 +40,8 @@ import antlr.collections.AST;
  * the public member regular expression.
  * 

* Rationale: Enforce encapsulation. + * + * @author Lars Kühne */ public class VisibilityModifierCheck extends Check @@ -50,7 +52,8 @@ public class VisibilityModifierCheck /** whether package visible members are allowed */ private boolean mPackageAllowed = false; - // TODO: Now that EJB 1.1 is becoming obsolete (is it?) we should change the default to "^$" + // TODO: we should change the default to "^$" + // as EJB 1.1 is becoming obsolete (is it?) /** pattern for public members that should be ignored */ private String mPublicMemberPattern = "^f[A-Z][a-zA-Z0-9]*$"; @@ -144,7 +147,8 @@ public class VisibilityModifierCheck || mods.contains("static") && mods.contains("final") || "package".equals(variableScope) && isPackageAllowed() || "protected".equals(variableScope) && isProtectedAllowed() - || "public".equals(variableScope) && getPublicMemberRegexp().match(varName))) + || "public".equals(variableScope) + && getPublicMemberRegexp().match(varName))) { log(varNameAST.getLineNo(), varNameAST.getColumnNo(), "variable.notPrivate", varName); @@ -191,8 +195,8 @@ public class VisibilityModifierCheck } /** - * Returns the set of modifier Strings for a VARIABLE_DEF AST - * @param variableDefAST + * Returns the set of modifier Strings for a VARIABLE_DEF AST. + * @param variableDefAST AST for a vraiable definition * @return the set of modifier Strings for variableDefAST */ private Set getModifiers(DetailAST variableDefAST) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java index 3b136a479..8379f6475 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/JTreeTable.java @@ -128,8 +128,8 @@ public class JTreeTable extends JTable */ public int getEditingRow() { - return (getColumnClass(editingColumn) == TreeTableModel.class) ? -1 : - editingRow; + final Class editingClass = getColumnClass(editingColumn); + return (editingClass == TreeTableModel.class) ? -1 : editingRow; } /** @@ -144,7 +144,7 @@ public class JTreeTable extends JTable } /** - * Returns the tree that is being shared between the model. + * @return the tree that is being shared between the model. */ public JTree getTree() { @@ -154,12 +154,13 @@ public class JTreeTable extends JTable /** * A TreeCellRenderer that displays a JTree. */ - public class TreeTableCellRenderer extends JTree implements + class TreeTableCellRenderer extends JTree implements TableCellRenderer { /** Last table/tree row asked to renderer. */ protected int visibleRow; + /** creates a new instance */ public TreeTableCellRenderer(TreeModel model) { super(model); @@ -223,6 +224,7 @@ public class JTreeTable extends JTable /** * TreeCellRenderer method. Overridden to update the visible row. + * @see TableCellRenderer */ public Component getTableCellRendererComponent(JTable table, Object value, @@ -230,10 +232,11 @@ public class JTreeTable extends JTable boolean hasFocus, int row, int column) { - if (isSelected) + if (isSelected) { setBackground(table.getSelectionBackground()); - else + } else { setBackground(table.getBackground()); + } visibleRow = row; return this; @@ -273,6 +276,8 @@ public class JTreeTable extends JTable * that wouldn't be the case. *

By returning false we are also enforcing the policy that * the tree will never be editable (at least by a key sequence). + * + * @see TableCellEditor */ public boolean isCellEditable(EventObject e) { @@ -318,6 +323,8 @@ public class JTreeTable extends JTable * Returns the list selection model. ListToTreeSelectionModelWrapper * listens for changes to this model and updates the selected paths * accordingly. + * + * @return the list selection model */ ListSelectionModel getListSelectionModel() { @@ -349,7 +356,7 @@ public class JTreeTable extends JTable /** * Creates and returns an instance of ListSelectionHandler. */ - protected ListSelectionListener createListSelectionListener() + private ListSelectionListener createListSelectionListener() { return new ListSelectionHandler(); } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index a4b3aee12..2723325ac 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -310,7 +310,6 @@ public class CheckerTest public void testIgnoreAccess() throws Exception { - mProps.setProperty(Defn.PUBLIC_MEMBER_PATTERN_PROP, "^r[A-Z]"); mProps.setProperty(Defn.ALLOW_PROTECTED_PROP, "true"); mProps.setProperty(Defn.ALLOW_PACKAGE_PROP, "true"); final Checker c = createChecker(); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java index 40c541412..a0d57429c 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/MethodLengthCheckTest.java @@ -1,3 +1,22 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; import com.puppycrawl.tools.checkstyle.checks.MethodLengthCheck;