Clean up of import checks - removed old code

This commit is contained in:
Oliver Burn 2002-09-29 05:19:13 +00:00
parent aa5dbacdcb
commit 84c1f8375f
4 changed files with 28 additions and 34 deletions

View File

@ -856,17 +856,6 @@ class Verifier
**/
void reportImport(int aLineNo, String aType)
{
if (!mConfig.isIgnoreImports()) {
// Check for a duplicate import
final Iterator it = mImports.iterator();
while (it.hasNext()) {
final LineText lt = (LineText) it.next();
if (aType.equals(lt.getText())) {
mMessages.add(aLineNo, "import.duplicate",
new Integer(lt.getLineNo()));
}
}
}
// Add to list to check for duplicates, usage and instantiation checks
mImports.add(new LineText(aLineNo, aType));
}
@ -879,9 +868,6 @@ class Verifier
**/
void reportStarImport(int aLineNo, String aPkg)
{
if (!mConfig.isIgnoreImports()) {
mMessages.add(aLineNo, "import.avoidStar");
}
mImports.add(new LineText(aLineNo, aPkg));
}
@ -1420,16 +1406,7 @@ class Verifier
while (it.hasNext()) {
final LineText imp = (LineText) it.next();
if (fromPackage(imp.getText(), "java.lang")) {
mMessages.add(imp.getLineNo(), "import.lang");
}
else if (fromPackage(imp.getText(), mPkgName)) {
mMessages.add(imp.getLineNo(), "import.same");
}
else if (!isReferencedImport(imp)) {
mMessages.add(imp.getLineNo(), "import.unused", imp.getText());
}
else if (isIllegalImport(imp.getText())) {
if (isIllegalImport(imp.getText())) {
mMessages.add(imp.getLineNo(), "import.illegal", imp.getText());
}
}

View File

@ -23,10 +23,23 @@ import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
public class RedundantImportCheck
extends ImportCheck
{
private String mPkgName;
/** set of the imports */
private final Set mImports = new HashSet();
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void beginTree()
{
mPkgName = null;
mImports.clear();
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
@ -49,6 +62,19 @@ public class RedundantImportCheck
else if (fromPackage(imp.getText(), mPkgName)) {
log(aAST.getLineNo(), aAST.getColumnNo(), "import.same");
}
// Check for a duplicate import
final Iterator it = mImports.iterator();
while (it.hasNext()) {
final FullIdent full = (FullIdent) it.next();
if (imp.getText().equals(full.getText())) {
log(aAST.getLineNo(),
aAST.getColumnNo(),
"import.duplicate",
new Integer(full.getLineNo()));
}
}
mImports.add(imp);
}
}

View File

@ -720,16 +720,6 @@ public class CheckerTest
final String filepath = getPath("InputImport.java");
assertNotNull(c);
final String[] expected = {
filepath + ":7: Avoid using the '.*' form of import.",
filepath + ":7: Redundant import from the same package.",
filepath + ":8: Redundant import from the same package.",
filepath + ":9: Avoid using the '.*' form of import.",
filepath + ":10: Avoid using the '.*' form of import.",
filepath + ":10: Redundant import from the java.lang package.",
filepath + ":11: Redundant import from the java.lang package.",
filepath + ":13: Unused import - java.util.List.",
filepath + ":14: Duplicate import to line 13.",
filepath + ":14: Unused import - java.util.List.",
filepath + ":15: Import from illegal package - sun.net.ftpclient.FtpClient.",
};
verify(c, filepath, expected);

View File

@ -22,6 +22,7 @@ public class RedundantImportCheckTest
"8:38: Redundant import from the same package.",
"10:1: Redundant import from the java.lang package.",
"11:1: Redundant import from the java.lang package.",
"14:1: Duplicate import to line 13.",
};
verify(c, fname, expected);
}