fixed most checkstyle errors
This commit is contained in:
parent
79d2d3d3e2
commit
3d734ac416
|
|
@ -1,20 +1,20 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
//Copyright (C) 2001-2003 Oliver Burn
|
||||
// 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 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.
|
||||
// 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
|
||||
// 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.usage;
|
||||
|
||||
|
|
@ -43,11 +43,11 @@ import com.puppycrawl.tools.checkstyle.checks.usage.transmogrify.TableMaker;
|
|||
public final class ASTManager
|
||||
{
|
||||
/** singleton */
|
||||
private static final ASTManager sInstance = new ASTManager();
|
||||
private static final ASTManager INSTANCE = new ASTManager();
|
||||
|
||||
/** maps DetailASTs to SymTabASTs. */
|
||||
private Map mMap = new IdentityHashMap();
|
||||
|
||||
|
||||
/** root with subtrees for a set of files */
|
||||
private SymTabAST mCompleteTree = null;
|
||||
|
||||
|
|
@ -61,14 +61,14 @@ public final class ASTManager
|
|||
private ASTManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the singleon ASTManager.
|
||||
* @return the singleon ASTManager.
|
||||
*/
|
||||
public static ASTManager getInstance()
|
||||
{
|
||||
return sInstance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,6 +83,7 @@ public final class ASTManager
|
|||
|
||||
/**
|
||||
* Builds the complete tree for all added parse trees.
|
||||
* @throws SymbolTableException if there is an error.
|
||||
*/
|
||||
private void buildTree()
|
||||
throws SymbolTableException
|
||||
|
|
@ -108,14 +109,15 @@ public final class ASTManager
|
|||
* @param aFile the file to add.
|
||||
* @param aAST the DetailAST to add.
|
||||
*/
|
||||
private void addToCompleteTree(File aFile, AST aAST) {
|
||||
private void addToCompleteTree(File aFile, AST aAST)
|
||||
{
|
||||
// add aFile to the root
|
||||
final SymTabAST fileNode =
|
||||
SymTabASTFactory.create(0, aFile.getAbsolutePath());
|
||||
fileNode.setFile(aFile);
|
||||
mCompleteTree.addChild(fileNode);
|
||||
fileNode.setParent(mCompleteTree);
|
||||
|
||||
|
||||
// add aAST to aFile
|
||||
final SymTabAST child = SymTabASTFactory.create(aAST);
|
||||
child.setFile(aFile);
|
||||
|
|
@ -153,7 +155,7 @@ public final class ASTManager
|
|||
{
|
||||
// lazy initialization
|
||||
if (mCompleteTree == null) {
|
||||
buildTree();
|
||||
buildTree();
|
||||
}
|
||||
Set result = (Set) mCheckNodes.get(aCheck);
|
||||
if (result == null) {
|
||||
|
|
@ -181,7 +183,7 @@ public final class ASTManager
|
|||
{
|
||||
return (SymTabAST) mMap.get(aAST);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears all associations from DetailsASTs to SymTabASTs.
|
||||
*/
|
||||
|
|
@ -206,7 +208,7 @@ public final class ASTManager
|
|||
{
|
||||
mCheckNodes.clear();
|
||||
mCompleteTree = null;
|
||||
mMap .clear();
|
||||
mMap.clear();
|
||||
mTrees.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public abstract class AbstractUsageCheck
|
|||
{
|
||||
/** determines whether all checks are single, intra-file checks */
|
||||
private static boolean sIsSingleFileCheckSet = true;
|
||||
|
||||
|
||||
/** the regexp to match against */
|
||||
private RE mRegexp = null;
|
||||
/** the format string of the regexp */
|
||||
|
|
@ -85,7 +85,7 @@ public abstract class AbstractUsageCheck
|
|||
{
|
||||
// use my class loader
|
||||
ClassManager.setClassLoader(getClassLoader());
|
||||
|
||||
|
||||
final String fileName = getFileContents().getFilename();
|
||||
ASTManager.getInstance().addTree(fileName, aRootAST);
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ public abstract class AbstractUsageCheck
|
|||
*/
|
||||
public void logError(Exception aException)
|
||||
{
|
||||
log(0, "general.exception", new String[] { aException.getMessage()});
|
||||
log(0, "general.exception", new String[] {aException.getMessage()});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,14 +134,15 @@ public abstract class AbstractUsageCheck
|
|||
* @param aFile the file to add.
|
||||
* @param aAST the DetailAST to add.
|
||||
*/
|
||||
private void addToTree(SymTabAST aRoot, File aFile, DetailAST aAST) {
|
||||
private void addToTree(SymTabAST aRoot, File aFile, DetailAST aAST)
|
||||
{
|
||||
// add aFile to aRoot
|
||||
final SymTabAST fileNode =
|
||||
SymTabASTFactory.create(0, aFile.getAbsolutePath());
|
||||
fileNode.setFile(aFile);
|
||||
aRoot.addChild(fileNode);
|
||||
fileNode.setParent(aRoot);
|
||||
|
||||
|
||||
// add aAST to aFile
|
||||
final SymTabAST child = SymTabASTFactory.create(aAST);
|
||||
child.setFile(aFile);
|
||||
|
|
@ -153,13 +154,13 @@ public abstract class AbstractUsageCheck
|
|||
/**
|
||||
* Determines the reference count for a DetailAST.
|
||||
* @param aAST the DetailAST to count.
|
||||
* @return the number of references to aAST.
|
||||
* @return the number of references to aAST.
|
||||
*/
|
||||
private int getReferenceCount(DetailAST aAST)
|
||||
{
|
||||
final SymTabAST ident = ASTManager.getInstance().get(aAST);
|
||||
final Definition definition =
|
||||
(Definition)ident.getDefinition();
|
||||
(Definition) ident.getDefinition();
|
||||
if (definition != null) {
|
||||
return definition.getNumReferences();
|
||||
}
|
||||
|
|
@ -183,9 +184,10 @@ public abstract class AbstractUsageCheck
|
|||
|
||||
/**
|
||||
* Applies this check to a set of nodes.
|
||||
* @param nodes the nodes to check.
|
||||
* @param aNodes the nodes to check.
|
||||
*/
|
||||
public void applyTo(Set aNodes) {
|
||||
public void applyTo(Set aNodes)
|
||||
{
|
||||
final Iterator it = aNodes.iterator();
|
||||
while (it.hasNext()) {
|
||||
final DetailAST nameAST = (DetailAST) it.next();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public class UnusedLocalVariableCheck extends AbstractUsageCheck
|
|||
TokenTypes.VARIABLE_DEF,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
|
||||
public String getErrorKey()
|
||||
|
|
@ -55,6 +54,6 @@ public class UnusedLocalVariableCheck extends AbstractUsageCheck
|
|||
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
|
||||
public boolean mustCheckReferenceCount(DetailAST aAST)
|
||||
{
|
||||
return ScopeUtils.isLocalVariableDef(aAST);
|
||||
return ScopeUtils.isLocalVariableDef(aAST);
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ public class UnusedParameterCheck extends AbstractUsageCheck
|
|||
{
|
||||
/** controls checking of catch clause parameter */
|
||||
private boolean mIgnoreCatch = true;
|
||||
|
||||
|
||||
/** @see com.puppycrawl.tools.checkstyle.api.Check */
|
||||
public int[] getDefaultTokens()
|
||||
{
|
||||
|
|
@ -47,7 +47,7 @@ public class UnusedParameterCheck extends AbstractUsageCheck
|
|||
TokenTypes.PARAMETER_DEF,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
|
||||
public String getErrorKey()
|
||||
{
|
||||
|
|
@ -63,29 +63,28 @@ public class UnusedParameterCheck extends AbstractUsageCheck
|
|||
if (parent.getType() == TokenTypes.PARAMETERS) {
|
||||
final DetailAST grandparent = parent.getParent();
|
||||
if (grandparent != null) {
|
||||
if (grandparent.getType() == TokenTypes.METHOD_DEF)
|
||||
{
|
||||
if (grandparent.getType() == TokenTypes.METHOD_DEF) {
|
||||
final DetailAST modifiersAST =
|
||||
grandparent.findFirstToken(TokenTypes.MODIFIERS);
|
||||
grandparent.findFirstToken(TokenTypes.MODIFIERS);
|
||||
if ((modifiersAST != null)
|
||||
&& !modifiersAST.branchContains(TokenTypes.ABSTRACT)
|
||||
&& !ScopeUtils.inInterfaceBlock(aAST))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (grandparent.getType() == TokenTypes.CTOR_DEF) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (parent.getType() == TokenTypes.LITERAL_CATCH) {
|
||||
result = !mIgnoreCatch;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Control whether unused catch clause parameters are flagged.
|
||||
* @param aIgnoreCatch whether unused catch clause parameters
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ public class UnusedPrivateFieldCheck
|
|||
TokenTypes.VARIABLE_DEF,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
|
||||
public String getErrorKey()
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
*/
|
||||
public class UnusedPrivateMethodCheck
|
||||
extends AbstractUsageCheck
|
||||
|
||||
|
||||
{
|
||||
/** @see com.puppycrawl.tools.checkstyle.api.Check */
|
||||
public int[] getDefaultTokens()
|
||||
|
|
|
|||
Loading…
Reference in New Issue