From 7bd1126a3b5ea39d73cab69622d50bc834ee29c5 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Mon, 23 Jun 2003 12:09:08 +0000 Subject: [PATCH] Code cleanup - removed the stupid AbstractImportCheck. It served no purpose but to add to our huge inheritance hierarchy. I was suprised how deep our hierarchy actually is. Is this the sign of to much abstraction. I wonder? --- .../tools/checkstyle/api/FullIdent.java | 10 ++++ .../checks/AbstractImportCheck.java | 46 ------------------- .../coding/IllegalInstantiationCheck.java | 17 ++++--- .../checks/coding/RedundantThrowsCheck.java | 11 ++--- .../checks/imports/AvoidStarImportCheck.java | 8 ++-- .../checks/imports/IllegalImportCheck.java | 6 +-- .../checks/imports/RedundantImportCheck.java | 11 ++--- .../checks/imports/UnusedImportsCheck.java | 11 ++--- .../checks/javadoc/JavadocMethodCheck.java | 8 ++-- 9 files changed, 43 insertions(+), 85 deletions(-) delete mode 100644 src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FullIdent.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FullIdent.java index 5a382565b..5f306df82 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FullIdent.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FullIdent.java @@ -109,6 +109,16 @@ public final class FullIdent return fi; } + /** + * Creates a new FullIdent starting from the child of the specified node. + * @param aAST the parent node from where to start from + * @return a FullIdent value + */ + public static FullIdent createFullIdentBelow(DetailAST aAST) + { + return createFullIdent((DetailAST) aAST.getFirstChild()); + } + /** * Recursively extract a FullIdent. * diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java deleted file mode 100644 index 37d891501..000000000 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java +++ /dev/null @@ -1,46 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code for adherence to a set of rules. -// Copyright (C) 2001-2003 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.FullIdent; - -/** - * Abstract class that provides helper functionality for determining an import - * name. It caches the import name in the token context to improve - * performance. - * - * @author Oliver Burn - * @version 1.0 - */ -public abstract class AbstractImportCheck - extends Check -{ - /** - * Return the name of the import associated with a specifed DetailAST. - * - * @param aAST the node containing the import - * @return a String value - */ - protected FullIdent getImportText(DetailAST aAST) - { - return FullIdent.createFullIdent((DetailAST) aAST.getFirstChild()); - } -} diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalInstantiationCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalInstantiationCheck.java index 48411de95..c0a161bd8 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalInstantiationCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalInstantiationCheck.java @@ -19,18 +19,17 @@ package com.puppycrawl.tools.checkstyle.checks.coding; +import antlr.collections.AST; +import com.puppycrawl.tools.checkstyle.api.Check; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.api.Utils; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.StringTokenizer; -import com.puppycrawl.tools.checkstyle.api.TokenTypes; -import com.puppycrawl.tools.checkstyle.api.DetailAST; -import com.puppycrawl.tools.checkstyle.api.FullIdent; -import com.puppycrawl.tools.checkstyle.api.Utils; -import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; -import antlr.collections.AST; - // TODO: Clean up potential duplicate code here and in UnusedImportsCheck /** *

@@ -63,7 +62,7 @@ import antlr.collections.AST; * @author lkuehne */ public class IllegalInstantiationCheck - extends AbstractImportCheck + extends Check { /** Set of fully qualified classnames. E.g. "java.lang.Boolean" */ private final Set mIllegalClasses = new HashSet(); @@ -135,7 +134,7 @@ public class IllegalInstantiationCheck */ private void processImport(DetailAST aAST) { - final FullIdent name = getImportText(aAST); + final FullIdent name = FullIdent.createFullIdentBelow(aAST); if (name != null) { // Note: different from UnusedImportsCheck.processImport(), // '.*' imports are also added here diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/RedundantThrowsCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/RedundantThrowsCheck.java index 386a1d9d3..6544b2d1a 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/RedundantThrowsCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/RedundantThrowsCheck.java @@ -18,18 +18,17 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.checks.coding; +import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.FullIdent; import com.puppycrawl.tools.checkstyle.api.TokenTypes; import com.puppycrawl.tools.checkstyle.api.Utils; -import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; import com.puppycrawl.tools.checkstyle.checks.ClassResolver; - +import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Iterator; import java.util.Set; -import java.util.HashSet; /** * Checks for redundant exceptions declared in throws clause @@ -48,7 +47,7 @@ import java.util.HashSet; * @author o_sukhodolsky */ public class RedundantThrowsCheck - extends AbstractImportCheck + extends Check { /** * whether unchecked exceptions in throws @@ -138,7 +137,7 @@ public class RedundantThrowsCheck */ private void processImport(DetailAST aAST) { - final FullIdent name = getImportText(aAST); + final FullIdent name = FullIdent.createFullIdentBelow(aAST); if (name != null) { mImports.add(name.getText()); } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java index 04cd3237a..9dd3bf33e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java @@ -19,10 +19,10 @@ package com.puppycrawl.tools.checkstyle.checks.imports; -import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.FullIdent; -import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; /** *

@@ -42,7 +42,7 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; * @version 1.0 */ public class AvoidStarImportCheck - extends AbstractImportCheck + extends Check { /** @see com.puppycrawl.tools.checkstyle.api.Check */ public int[] getDefaultTokens() @@ -53,7 +53,7 @@ public class AvoidStarImportCheck /** @see com.puppycrawl.tools.checkstyle.api.Check */ public void visitToken(DetailAST aAST) { - final FullIdent name = getImportText(aAST); + final FullIdent name = FullIdent.createFullIdentBelow(aAST); if ((name != null) && name.getText().endsWith(".*")) { log(aAST.getLineNo(), "import.avoidStar", name.getText()); } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java index c828dee14..da3fc2ddd 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java @@ -19,10 +19,10 @@ package com.puppycrawl.tools.checkstyle.checks.imports; +import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.FullIdent; import com.puppycrawl.tools.checkstyle.api.TokenTypes; -import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; /** *

@@ -55,7 +55,7 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; * @version 1.0 */ public class IllegalImportCheck - extends AbstractImportCheck + extends Check { /** list of illegal packages */ private String[] mIllegalPkgs; @@ -86,7 +86,7 @@ public class IllegalImportCheck /** @see com.puppycrawl.tools.checkstyle.api.Check */ public void visitToken(DetailAST aAST) { - final FullIdent imp = getImportText(aAST); + final FullIdent imp = FullIdent.createFullIdentBelow(aAST); if (isIllegalImport(imp.getText())) { log(aAST.getLineNo(), aAST.getColumnNo(), diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java index 8fa3c41b0..551d65b74 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java @@ -19,14 +19,13 @@ package com.puppycrawl.tools.checkstyle.checks.imports; -import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.FullIdent; -import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; - +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import java.util.HashSet; /** *

@@ -50,7 +49,7 @@ import java.util.HashSet; * @version 1.0 */ public class RedundantImportCheck - extends AbstractImportCheck + extends Check { /** name of package in file */ private String mPkgName; @@ -78,7 +77,7 @@ public class RedundantImportCheck mPkgName = FullIdent.createFullIdent(nameAST).getText(); } else { - final FullIdent imp = getImportText(aAST); + final FullIdent imp = FullIdent.createFullIdentBelow(aAST); if (fromPackage(imp.getText(), "java.lang")) { log(aAST.getLineNo(), aAST.getColumnNo(), "import.lang", imp.getText()); diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java index b506672dc..5031937b2 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java @@ -18,15 +18,14 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.checks.imports; -import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; import com.puppycrawl.tools.checkstyle.api.Utils; -import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; - import java.util.HashSet; -import java.util.Set; import java.util.Iterator; +import java.util.Set; /** *

@@ -42,7 +41,7 @@ import java.util.Iterator; * @version 1.0 */ public class UnusedImportsCheck - extends AbstractImportCheck + extends Check { /** flag to indicate when time to start collecting references */ private boolean mCollect; @@ -129,7 +128,7 @@ public class UnusedImportsCheck */ private void processImport(DetailAST aAST) { - final FullIdent name = getImportText(aAST); + final FullIdent name = FullIdent.createFullIdentBelow(aAST); if ((name != null) && !name.getText().endsWith(".*")) { mImports.add(name); } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java index 8ca3d1974..b7dc4570d 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocMethodCheck.java @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.checks.javadoc; +import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.FileContents; import com.puppycrawl.tools.checkstyle.api.FullIdent; @@ -25,16 +26,13 @@ import com.puppycrawl.tools.checkstyle.api.Scope; import com.puppycrawl.tools.checkstyle.api.ScopeUtils; import com.puppycrawl.tools.checkstyle.api.TokenTypes; import com.puppycrawl.tools.checkstyle.api.Utils; -import com.puppycrawl.tools.checkstyle.checks.AbstractImportCheck; import com.puppycrawl.tools.checkstyle.checks.ClassResolver; - import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Set; - import org.apache.regexp.RE; /** @@ -83,7 +81,7 @@ import org.apache.regexp.RE; * @version 1.1 */ public class JavadocMethodCheck - extends AbstractImportCheck + extends Check { // {{{ Data declarations @@ -317,7 +315,7 @@ public class JavadocMethodCheck */ private void processImport(DetailAST aAST) { - final FullIdent name = getImportText(aAST); + final FullIdent name = FullIdent.createFullIdentBelow(aAST); if (name != null) { mImports.add(name.getText()); }