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?
This commit is contained in:
parent
cf089fe1a1
commit
7bd1126a3b
|
|
@ -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 <code>FullIdent</code> value
|
||||
*/
|
||||
public static FullIdent createFullIdentBelow(DetailAST aAST)
|
||||
{
|
||||
return createFullIdent((DetailAST) aAST.getFirstChild());
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively extract a FullIdent.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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 <a href="mailto:checkstyle@puppycrawl.com">Oliver Burn</a>
|
||||
* @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 <code>String</code> value
|
||||
*/
|
||||
protected FullIdent getImportText(DetailAST aAST)
|
||||
{
|
||||
return FullIdent.createFullIdent((DetailAST) aAST.getFirstChild());
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue