Refactored out ugly copy/paste code.
This commit is contained in:
parent
4cddf4771c
commit
8dd44cbead
|
|
@ -173,4 +173,13 @@ public final class Utils
|
|||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the base class name from a fully qualified name
|
||||
* @param aType the fully qualified name. Cannot be null
|
||||
*/
|
||||
public static String baseClassname(String aType)
|
||||
{
|
||||
final int i = aType.lastIndexOf(".");
|
||||
return (i == -1) ? aType : aType.substring(i + 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ 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 antlr.collections.AST;
|
||||
|
||||
// TODO: Clean up potential duplicate code here and in UnusedImportsCheck
|
||||
|
|
@ -61,7 +62,7 @@ import antlr.collections.AST;
|
|||
* @author lkuehne
|
||||
*/
|
||||
public class IllegalInstantiationCheck
|
||||
extends AbstractImportCheck
|
||||
extends AbstractImportCheck
|
||||
{
|
||||
/** Set of fully qualified classnames. E.g. "java.lang.Boolean" */
|
||||
private final Set mIllegalClasses = new HashSet();
|
||||
|
|
@ -238,7 +239,7 @@ public class IllegalInstantiationCheck
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (basename(importArg).equals(aClassName)
|
||||
if (Utils.baseClassname(importArg).equals(aClassName)
|
||||
&& mIllegalClasses.contains(importArg))
|
||||
{
|
||||
return importArg;
|
||||
|
|
@ -249,16 +250,6 @@ public class IllegalInstantiationCheck
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name from a fully qualified name
|
||||
* @param aType the fully qualified name
|
||||
*/
|
||||
private static String basename(String aType)
|
||||
{
|
||||
final int i = aType.lastIndexOf(".");
|
||||
return (i == -1) ? aType : aType.substring(i + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the classes that are illegal to instantiate.
|
||||
* @param aClassNames a comma seperate list of class names
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ public class JavadocMethodCheck
|
|||
return false;
|
||||
}
|
||||
|
||||
final String base = basename(aFullName);
|
||||
final String base = Utils.baseClassname(aFullName);
|
||||
if (aShortName.length() >= aFullName.length()
|
||||
|| !base.equals(aShortName))
|
||||
{
|
||||
|
|
@ -705,16 +705,4 @@ public class JavadocMethodCheck
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: clean up duplicate code in UnusedImports and IllegalInstantiation
|
||||
/**
|
||||
* @return the class name from a fully qualified name
|
||||
* @param aType the fully qualified name
|
||||
*/
|
||||
private String basename(String aType)
|
||||
{
|
||||
final int i = aType.lastIndexOf(".");
|
||||
return (i == -1) ? aType : aType.substring(i + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package com.puppycrawl.tools.checkstyle.checks;
|
|||
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 java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
|
@ -65,7 +66,7 @@ public class UnusedImportsCheck
|
|||
while (it.hasNext()) {
|
||||
final FullIdent imp = (FullIdent) it.next();
|
||||
|
||||
if (!mReferenced.contains(basename(imp.getText()))) {
|
||||
if (!mReferenced.contains(Utils.baseClassname(imp.getText()))) {
|
||||
log(imp.getLineNo(),
|
||||
imp.getColumnNo(),
|
||||
"import.unused", imp.getText());
|
||||
|
|
@ -130,15 +131,4 @@ public class UnusedImportsCheck
|
|||
mImports.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name from a fully qualified name
|
||||
* @param aType the fully qualified name
|
||||
*/
|
||||
private String basename(String aType)
|
||||
{
|
||||
final int i = aType.lastIndexOf(".");
|
||||
return (i == -1) ? aType : aType.substring(i + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue