From 7817e055190835ad9adebd07380e4bc6c5fa1441 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Sat, 16 Jul 2005 01:29:44 +0000 Subject: [PATCH] Refactoring away a bunch of casts... good times git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3707 51baf565-9d33-0410-a72c-fc3788e3496d --- .../rules/ConstructorCallsOverridableMethodTest.java | 2 +- .../sourceforge/pmd/symboltable/AcceptanceTest.java | 12 +++++------- .../net/sourceforge/pmd/testframework/RuleTst.java | 2 +- pmd/rulesets/scratchpad.xml | 2 +- pmd/src/net/sourceforge/pmd/AbstractRule.java | 9 ++++++--- .../pmd/rules/AccessorClassGeneration.java | 2 +- .../AvoidConcatenatingNonLiteralsInStringBuffer.java | 4 ++-- .../pmd/rules/AvoidDeeplyNestedIfStmtsRule.java | 2 +- .../pmd/rules/AvoidFieldNameMatchingMethodName.java | 2 +- .../pmd/rules/AvoidFieldNameMatchingTypeName.java | 2 +- .../AvoidNonConstructorMethodsWithClassName.java | 2 +- .../pmd/rules/AvoidReassigningParameters.java | 3 +-- .../pmd/rules/BeanMembersShouldSerializeRule.java | 3 +-- .../pmd/rules/ClassNamingConventions.java | 2 +- .../net/sourceforge/pmd/rules/CloseConnection.java | 2 +- .../pmd/rules/ConstructorCallsOverridableMethod.java | 7 +++---- .../sourceforge/pmd/rules/DoubleCheckedLocking.java | 2 +- .../sourceforge/pmd/rules/DuplicateImportsRule.java | 8 +++----- .../sourceforge/pmd/rules/IdempotentOperations.java | 2 +- .../pmd/rules/TestClassWithoutTestCases.java | 2 +- .../net/sourceforge/pmd/rules/UnusedModifier.java | 6 +++--- .../pmd/rules/UnusedPrivateFieldRule.java | 3 +-- .../pmd/rules/design/AssignmentToNonFinalStatic.java | 3 +-- .../pmd/rules/design/CompareObjectsWithEquals.java | 2 +- .../pmd/rules/design/ExceptionAsFlowControl.java | 2 +- .../sourceforge/pmd/rules/design/ImmutableField.java | 3 +-- .../pmd/rules/design/NullAssignmentRule.java | 10 +++++----- .../design/PositionLiteralsFirstInComparisons.java | 2 +- .../sourceforge/pmd/rules/design/TooManyFields.java | 7 +------ .../AvoidInstantiatingObjectsInLoops.java | 2 +- .../optimization/LocalVariableCouldBeFinal.java | 2 +- .../strictexception/AvoidCatchingThrowable.java | 2 +- .../rules/sunsecure/MethodReturnsInternalArray.java | 4 ++-- .../net/sourceforge/pmd/symboltable/MethodScope.java | 1 - pmd/src/net/sourceforge/pmd/symboltable/Scope.java | 1 - 35 files changed, 54 insertions(+), 68 deletions(-) diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethodTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethodTest.java index fd6f22b18d..2055cd7920 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethodTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethodTest.java @@ -4,8 +4,8 @@ package test.net.sourceforge.pmd.rules; import net.sourceforge.pmd.PMD; -import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.Report; +import net.sourceforge.pmd.Rule; import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; import test.net.sourceforge.pmd.testframework.TestDescriptor; diff --git a/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java b/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java index 74569a778c..2ba85eab34 100644 --- a/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java @@ -4,21 +4,19 @@ package test.net.sourceforge.pmd.symboltable; import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.ast.ASTBlock; +import net.sourceforge.pmd.ast.ASTCatchStatement; import net.sourceforge.pmd.ast.ASTEqualityExpression; +import net.sourceforge.pmd.ast.ASTInitializer; +import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration; import net.sourceforge.pmd.ast.ASTMethodDeclaration; import net.sourceforge.pmd.ast.SimpleNode; -import net.sourceforge.pmd.ast.ASTInitializer; -import net.sourceforge.pmd.ast.ASTCatchStatement; -import net.sourceforge.pmd.ast.ASTBlock; -import net.sourceforge.pmd.ast.ASTIfStatement; -import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration; import net.sourceforge.pmd.symboltable.Scope; import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import net.sourceforge.pmd.symboltable.MethodScope; import java.util.Iterator; -import java.util.Map; import java.util.List; +import java.util.Map; public class AcceptanceTest extends STBBaseTst { diff --git a/pmd/regress/test/net/sourceforge/pmd/testframework/RuleTst.java b/pmd/regress/test/net/sourceforge/pmd/testframework/RuleTst.java index 653acd356f..693d61f3fc 100644 --- a/pmd/regress/test/net/sourceforge/pmd/testframework/RuleTst.java +++ b/pmd/regress/test/net/sourceforge/pmd/testframework/RuleTst.java @@ -11,10 +11,10 @@ import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.RuleSetFactory; import net.sourceforge.pmd.RuleSetNotFoundException; +import net.sourceforge.pmd.SimpleRuleSetNameMapper; import net.sourceforge.pmd.TargetJDK1_4; import net.sourceforge.pmd.TargetJDK1_5; import net.sourceforge.pmd.TargetJDKVersion; -import net.sourceforge.pmd.SimpleRuleSetNameMapper; import java.io.StringReader; diff --git a/pmd/rulesets/scratchpad.xml b/pmd/rulesets/scratchpad.xml index 4c6aebe77c..6b1e3b419b 100644 --- a/pmd/rulesets/scratchpad.xml +++ b/pmd/rulesets/scratchpad.xml @@ -25,7 +25,7 @@ These are new rules that are still in progress diff --git a/pmd/src/net/sourceforge/pmd/AbstractRule.java b/pmd/src/net/sourceforge/pmd/AbstractRule.java index bc688a3949..2611e2dcfa 100644 --- a/pmd/src/net/sourceforge/pmd/AbstractRule.java +++ b/pmd/src/net/sourceforge/pmd/AbstractRule.java @@ -10,10 +10,10 @@ import net.sourceforge.pmd.ast.JavaParserVisitorAdapter; import net.sourceforge.pmd.ast.SimpleNode; import net.sourceforge.pmd.symboltable.MethodScope; +import java.text.MessageFormat; import java.util.Iterator; import java.util.List; import java.util.Properties; -import java.text.MessageFormat; public abstract class AbstractRule extends JavaParserVisitorAdapter implements Rule { @@ -102,6 +102,7 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R public void setExternalInfoUrl(String url) { this.externalInfoUrl = url; } + /** * Test if rules are equals. Rules are equals if * 1. they have the same implementation class @@ -223,7 +224,8 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R * @param ctx the RuleContext * @param node the node that produces the violation, may be null, in which case all line and column info will be set to zero */ - protected final void addViolation(RuleContext ctx, SimpleNode node) { + protected final void addViolation(Object data, SimpleNode node) { + RuleContext ctx = (RuleContext)data; ctx.getReport().addRuleViolation(createRuleViolation(ctx, node)); } @@ -234,7 +236,8 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R * @param node the node that produces the violation, may be null, in which case all line and column info will be set to zero * @param embed a message to embed in the rule violation message */ - protected final void addViolation(RuleContext ctx, SimpleNode node, String embed) { + protected final void addViolation(Object data, SimpleNode node, String embed) { + RuleContext ctx = (RuleContext)data; ctx.getReport().addRuleViolation(createRuleViolation(ctx, node, MessageFormat.format(getMessage(), new Object[]{embed}))); } diff --git a/pmd/src/net/sourceforge/pmd/rules/AccessorClassGeneration.java b/pmd/src/net/sourceforge/pmd/rules/AccessorClassGeneration.java index 6ca6ba298b..7f173b18a5 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AccessorClassGeneration.java +++ b/pmd/src/net/sourceforge/pmd/rules/AccessorClassGeneration.java @@ -12,9 +12,9 @@ import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.ast.ASTClassOrInterfaceType; import net.sourceforge.pmd.ast.ASTCompilationUnit; import net.sourceforge.pmd.ast.ASTConstructorDeclaration; +import net.sourceforge.pmd.ast.ASTEnumDeclaration; import net.sourceforge.pmd.ast.ASTName; import net.sourceforge.pmd.ast.ASTPackageDeclaration; -import net.sourceforge.pmd.ast.ASTEnumDeclaration; import java.util.ArrayList; import java.util.Iterator; diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidConcatenatingNonLiteralsInStringBuffer.java b/pmd/src/net/sourceforge/pmd/rules/AvoidConcatenatingNonLiteralsInStringBuffer.java index 592ef5e3c8..de861e5894 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidConcatenatingNonLiteralsInStringBuffer.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidConcatenatingNonLiteralsInStringBuffer.java @@ -36,10 +36,10 @@ public final class AvoidConcatenatingNonLiteralsInStringBuffer extends AbstractR if (bs.isAllocation()) { if (isAllocatedStringBuffer(node)) { - addViolation((RuleContext) data, node); + addViolation(data, node); } } else if (isInStringBufferAppend(node)) { - addViolation((RuleContext) data, node); + addViolation(data, node); } return data; } diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java b/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java index 8c666c5a97..a8f569e792 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java @@ -23,7 +23,7 @@ public class AvoidDeeplyNestedIfStmtsRule extends AbstractRule { } super.visit(node, data); if (depth == getIntProperty("problemDepth")) { - addViolation((RuleContext) data, node); + addViolation(data, node); } depth--; return data; diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java b/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java index 26b0e003cc..1644d28649 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java @@ -38,7 +38,7 @@ public class AvoidFieldNameMatchingMethodName extends AbstractRule { if (fieldDeclaringType.equals(getDeclaringType(m))) { String n = m.getMethodName(); if (n!=null && varName.equals(n.toLowerCase())) { - addViolation((RuleContext) data, node); + addViolation(data, node); } } } diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingTypeName.java b/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingTypeName.java index b35306de50..9bac24255f 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingTypeName.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingTypeName.java @@ -24,7 +24,7 @@ public class AvoidFieldNameMatchingTypeName extends AbstractRule { ASTClassOrInterfaceDeclaration cl = (ASTClassOrInterfaceDeclaration) node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); if (cl!=null && cl.getImage() != null) { if (varName.equals(cl.getImage().toLowerCase())) { - addViolation((RuleContext) data, node); + addViolation(data, node); } } } diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidNonConstructorMethodsWithClassName.java b/pmd/src/net/sourceforge/pmd/rules/AvoidNonConstructorMethodsWithClassName.java index 3a99e31a32..d1c0259a4d 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidNonConstructorMethodsWithClassName.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidNonConstructorMethodsWithClassName.java @@ -22,7 +22,7 @@ public class AvoidNonConstructorMethodsWithClassName extends AbstractRule { String declaringType = getDeclaringType (node); if (methodName!=null && declaringType!=null) { if (methodName.equals(declaringType)) { - addViolation((RuleContext) data, node, methodName); + addViolation(data, node, methodName); } } return data; diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidReassigningParameters.java b/pmd/src/net/sourceforge/pmd/rules/AvoidReassigningParameters.java index 4daf717b77..9c22766922 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidReassigningParameters.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidReassigningParameters.java @@ -10,7 +10,6 @@ import net.sourceforge.pmd.symboltable.NameOccurrence; import net.sourceforge.pmd.symboltable.Scope; import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import java.text.MessageFormat; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -26,7 +25,7 @@ public class AvoidReassigningParameters extends AbstractRule { for (Iterator j = usages.iterator(); j.hasNext();) { NameOccurrence occ = (NameOccurrence) j.next(); if ((occ.isOnLeftHandSide() || occ.isSelfAssignment()) && occ.getNameForWhichThisIsAQualifier() == null && !decl.isArray()) { - addViolation((RuleContext)data, decl.getNode(), decl.getImage()); + addViolation(data, decl.getNode(), decl.getImage()); } } } diff --git a/pmd/src/net/sourceforge/pmd/rules/BeanMembersShouldSerializeRule.java b/pmd/src/net/sourceforge/pmd/rules/BeanMembersShouldSerializeRule.java index 6700272793..26e9e98454 100644 --- a/pmd/src/net/sourceforge/pmd/rules/BeanMembersShouldSerializeRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/BeanMembersShouldSerializeRule.java @@ -11,7 +11,6 @@ import net.sourceforge.pmd.ast.ASTPrimitiveType; import net.sourceforge.pmd.ast.ASTResultType; import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -55,7 +54,7 @@ public class BeanMembersShouldSerializeRule extends AbstractRule { boolean hasGetMethod = Arrays.binarySearch(methNameArray, "get" + varName) >= 0 || Arrays.binarySearch(methNameArray, "is" + varName) >= 0; boolean hasSetMethod = Arrays.binarySearch(methNameArray, "set" + varName) >= 0; if (!hasGetMethod || !hasSetMethod) { - addViolation((RuleContext) data, decl.getNode(), decl.getImage()); + addViolation(data, decl.getNode(), decl.getImage()); } } return super.visit(node, data); diff --git a/pmd/src/net/sourceforge/pmd/rules/ClassNamingConventions.java b/pmd/src/net/sourceforge/pmd/rules/ClassNamingConventions.java index e472a343cf..744b996ab4 100644 --- a/pmd/src/net/sourceforge/pmd/rules/ClassNamingConventions.java +++ b/pmd/src/net/sourceforge/pmd/rules/ClassNamingConventions.java @@ -11,7 +11,7 @@ public class ClassNamingConventions extends AbstractRule { public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { if (Character.isLowerCase(node.getImage().charAt(0))) { - addViolation((RuleContext) data, node); + addViolation(data, node); } return data; } diff --git a/pmd/src/net/sourceforge/pmd/rules/CloseConnection.java b/pmd/src/net/sourceforge/pmd/rules/CloseConnection.java index 5622416a71..0a9ac31de4 100644 --- a/pmd/src/net/sourceforge/pmd/rules/CloseConnection.java +++ b/pmd/src/net/sourceforge/pmd/rules/CloseConnection.java @@ -111,7 +111,7 @@ public class CloseConnection extends AbstractRule { // if all is not well, complain if (!closed) { - addViolation((RuleContext) data, id); + addViolation(data, id); } } diff --git a/pmd/src/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethod.java b/pmd/src/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethod.java index 84c2d5cd0a..7a15e83a0b 100644 --- a/pmd/src/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethod.java +++ b/pmd/src/net/sourceforge/pmd/rules/ConstructorCallsOverridableMethod.java @@ -9,6 +9,7 @@ import net.sourceforge.pmd.ast.ASTArguments; import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.ast.ASTCompilationUnit; import net.sourceforge.pmd.ast.ASTConstructorDeclaration; +import net.sourceforge.pmd.ast.ASTEnumDeclaration; import net.sourceforge.pmd.ast.ASTExplicitConstructorInvocation; import net.sourceforge.pmd.ast.ASTLiteral; import net.sourceforge.pmd.ast.ASTMethodDeclarator; @@ -19,9 +20,7 @@ import net.sourceforge.pmd.ast.ASTPrimarySuffix; import net.sourceforge.pmd.ast.AccessNode; import net.sourceforge.pmd.ast.Node; import net.sourceforge.pmd.ast.SimpleNode; -import net.sourceforge.pmd.ast.ASTEnumDeclaration; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -573,7 +572,7 @@ public final class ConstructorCallsOverridableMethod extends AbstractRule { String methName = h.getASTMethodDeclarator().getImage(); int count = h.getASTMethodDeclarator().getParameterCount(); if (meth.getName().equals(methName) && meth.getArgumentCount() == count) { - addViolation((RuleContext) data, meth.getASTPrimaryExpression(), h.getCalled()); + addViolation( data, meth.getASTPrimaryExpression(), h.getCalled()); } } } @@ -588,7 +587,7 @@ public final class ConstructorCallsOverridableMethod extends AbstractRule { ConstructorInvocation ci = (ConstructorInvocation) calledConstIter.next(); if (ci.getArgumentCount() == paramCount) { //match name super / this !? - addViolation((RuleContext) data, ci.getASTExplicitConstructorInvocation()); + addViolation(data, ci.getASTExplicitConstructorInvocation()); } } } diff --git a/pmd/src/net/sourceforge/pmd/rules/DoubleCheckedLocking.java b/pmd/src/net/sourceforge/pmd/rules/DoubleCheckedLocking.java index 911f651684..650b87192f 100644 --- a/pmd/src/net/sourceforge/pmd/rules/DoubleCheckedLocking.java +++ b/pmd/src/net/sourceforge/pmd/rules/DoubleCheckedLocking.java @@ -107,7 +107,7 @@ public class DoubleCheckedLocking extends net.sourceforge.pmd.AbstractRule { ASTPrimaryExpression pe = (ASTPrimaryExpression) se.jjtGetChild(0); if (matchName(pe, returnVariableName)) { if (se.jjtGetChild(1) instanceof ASTAssignmentOperator) { - addViolation((RuleContext) data, node); + addViolation(data, node); } } } diff --git a/pmd/src/net/sourceforge/pmd/rules/DuplicateImportsRule.java b/pmd/src/net/sourceforge/pmd/rules/DuplicateImportsRule.java index 3da5d2618a..bc0e9dde87 100644 --- a/pmd/src/net/sourceforge/pmd/rules/DuplicateImportsRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/DuplicateImportsRule.java @@ -7,9 +7,7 @@ import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.ast.ASTCompilationUnit; import net.sourceforge.pmd.ast.ASTImportDeclaration; -import net.sourceforge.pmd.ast.SimpleNode; -import java.text.MessageFormat; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -33,7 +31,7 @@ public class DuplicateImportsRule extends AbstractRule { ImportWrapper thisSingleTypeImport = (ImportWrapper) j.next(); String singleTypePkg = thisSingleTypeImport.getName().substring(0, thisSingleTypeImport.getName().lastIndexOf(".")); if (thisImportOnDemand.getName().equals(singleTypePkg)) { - addViolation((RuleContext) data, thisSingleTypeImport.getNode(), thisSingleTypeImport.getName()); + addViolation(data, thisSingleTypeImport.getNode(), thisSingleTypeImport.getName()); } } } @@ -48,13 +46,13 @@ public class DuplicateImportsRule extends AbstractRule { // blahhhh... this really wants to be ASTImportDeclaration to be polymorphic... if (node.isImportOnDemand()) { if (importOnDemandImports.contains(wrapper)) { - addViolation((RuleContext) data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); + addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); } else { importOnDemandImports.add(wrapper); } } else { if (singleTypeImports.contains(wrapper)) { - addViolation((RuleContext) data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); + addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); } else { singleTypeImports.add(wrapper); } diff --git a/pmd/src/net/sourceforge/pmd/rules/IdempotentOperations.java b/pmd/src/net/sourceforge/pmd/rules/IdempotentOperations.java index 34cdbfb85f..fc20d43934 100644 --- a/pmd/src/net/sourceforge/pmd/rules/IdempotentOperations.java +++ b/pmd/src/net/sourceforge/pmd/rules/IdempotentOperations.java @@ -56,7 +56,7 @@ public class IdempotentOperations extends AbstractRule { } } - addViolation((RuleContext)data, node); + addViolation(data, node); return super.visit(node, data); } } diff --git a/pmd/src/net/sourceforge/pmd/rules/TestClassWithoutTestCases.java b/pmd/src/net/sourceforge/pmd/rules/TestClassWithoutTestCases.java index 05d9fb9f5c..eb3574d893 100644 --- a/pmd/src/net/sourceforge/pmd/rules/TestClassWithoutTestCases.java +++ b/pmd/src/net/sourceforge/pmd/rules/TestClassWithoutTestCases.java @@ -33,7 +33,7 @@ public class TestClassWithoutTestCases extends AbstractRule { } if (!testsFound) { - addViolation((RuleContext)data, node); + addViolation(data, node); } } diff --git a/pmd/src/net/sourceforge/pmd/rules/UnusedModifier.java b/pmd/src/net/sourceforge/pmd/rules/UnusedModifier.java index fa8d82e286..8db8a18171 100644 --- a/pmd/src/net/sourceforge/pmd/rules/UnusedModifier.java +++ b/pmd/src/net/sourceforge/pmd/rules/UnusedModifier.java @@ -14,12 +14,12 @@ public class UnusedModifier extends AbstractRule { if (!node.isInterface() && node.isNested() && (node.isPublic() || node.isStatic())) { ASTClassOrInterfaceDeclaration parent = (ASTClassOrInterfaceDeclaration)node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); if (parent.isInterface()) { - addViolation((RuleContext)data, node, getMessage()); + addViolation(data, node, getMessage()); } } else if (node.isInterface() && node.isNested() && (node.isPublic() || node.isStatic())) { ASTClassOrInterfaceDeclaration parent = (ASTClassOrInterfaceDeclaration)node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); if (parent.isInterface() || (!parent.isInterface() && node.isStatic())) { - addViolation((RuleContext)data, node, getMessage()); + addViolation(data, node, getMessage()); } } return super.visit(node, data); @@ -44,7 +44,7 @@ public class UnusedModifier extends AbstractRule { // if this is a method in an anonymous inner class Node parent = fieldOrMethod.jjtGetParent().jjtGetParent().jjtGetParent(); if (parent instanceof ASTClassOrInterfaceDeclaration && ((ASTClassOrInterfaceDeclaration)parent).isInterface()) { - addViolation((RuleContext)data, fieldOrMethod); + addViolation(data, fieldOrMethod); } } diff --git a/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateFieldRule.java b/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateFieldRule.java index 3b5409d157..4c7ad6bd62 100644 --- a/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateFieldRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateFieldRule.java @@ -9,7 +9,6 @@ import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.symboltable.NameOccurrence; import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import java.text.MessageFormat; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -24,7 +23,7 @@ public class UnusedPrivateFieldRule extends AbstractRule { continue; } if (!actuallyUsed((List) vars.get(decl))) { - addViolation((RuleContext)data, decl.getNode(), decl.getImage()); + addViolation(data, decl.getNode(), decl.getImage()); } } return super.visit(node, data); diff --git a/pmd/src/net/sourceforge/pmd/rules/design/AssignmentToNonFinalStatic.java b/pmd/src/net/sourceforge/pmd/rules/design/AssignmentToNonFinalStatic.java index da51d22e44..6e3d5a02b3 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/AssignmentToNonFinalStatic.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/AssignmentToNonFinalStatic.java @@ -14,7 +14,6 @@ import net.sourceforge.pmd.ast.SimpleNode; import net.sourceforge.pmd.symboltable.NameOccurrence; import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import java.text.MessageFormat; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -35,7 +34,7 @@ public class AssignmentToNonFinalStatic extends AbstractRule { } if (initializedInConstructor((List)vars.get(decl))) { - addViolation((RuleContext)data, decl.getNode(), decl.getImage()); + addViolation(data, decl.getNode(), decl.getImage()); } } return super.visit(node, data); diff --git a/pmd/src/net/sourceforge/pmd/rules/design/CompareObjectsWithEquals.java b/pmd/src/net/sourceforge/pmd/rules/design/CompareObjectsWithEquals.java index d1ff14b3ba..a7757487be 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/CompareObjectsWithEquals.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/CompareObjectsWithEquals.java @@ -50,7 +50,7 @@ public class CompareObjectsWithEquals extends AbstractRule { } for (Iterator j = usages.iterator(); j.hasNext();) { if (((NameOccurrence)j.next()).getLocation().jjtGetParent().jjtGetParent().jjtGetParent() == node) { - addViolation((RuleContext) data, node); + addViolation(data, node); return data; } } diff --git a/pmd/src/net/sourceforge/pmd/rules/design/ExceptionAsFlowControl.java b/pmd/src/net/sourceforge/pmd/rules/design/ExceptionAsFlowControl.java index 4ecf32d5c2..5660a6823f 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/ExceptionAsFlowControl.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/ExceptionAsFlowControl.java @@ -39,7 +39,7 @@ public class ExceptionAsFlowControl extends AbstractRule { ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) type.findChildrenOfType(ASTClassOrInterfaceType.class).get(0); if (throwName != null && throwName.equals(name.getImage())) { - addViolation((RuleContext) data, name); + addViolation(data, name); } } } diff --git a/pmd/src/net/sourceforge/pmd/rules/design/ImmutableField.java b/pmd/src/net/sourceforge/pmd/rules/design/ImmutableField.java index 454b6955ce..57116ff592 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/ImmutableField.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/ImmutableField.java @@ -14,7 +14,6 @@ import net.sourceforge.pmd.ast.SimpleNode; import net.sourceforge.pmd.symboltable.NameOccurrence; import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import java.text.MessageFormat; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -44,7 +43,7 @@ public class ImmutableField extends AbstractRule { continue; } if (result == IMMUTABLE || ((result == CHECKDECL) && initializedInDeclaration(decl.getAccessNodeParent()))) { - addViolation((RuleContext)data, decl.getNode(), decl.getImage()); + addViolation(data, decl.getNode(), decl.getImage()); } } return super.visit(node, data); diff --git a/pmd/src/net/sourceforge/pmd/rules/design/NullAssignmentRule.java b/pmd/src/net/sourceforge/pmd/rules/design/NullAssignmentRule.java index 1df45cfd63..1dad1fe3d2 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/NullAssignmentRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/NullAssignmentRule.java @@ -5,19 +5,19 @@ package net.sourceforge.pmd.rules.design; import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.symboltable.ClassScope; -import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import net.sourceforge.pmd.symboltable.Scope; import net.sourceforge.pmd.ast.ASTAssignmentOperator; import net.sourceforge.pmd.ast.ASTConditionalExpression; import net.sourceforge.pmd.ast.ASTEqualityExpression; +import net.sourceforge.pmd.ast.ASTName; import net.sourceforge.pmd.ast.ASTNullLiteral; import net.sourceforge.pmd.ast.ASTStatementExpression; import net.sourceforge.pmd.ast.Node; -import net.sourceforge.pmd.ast.ASTName; +import net.sourceforge.pmd.symboltable.ClassScope; +import net.sourceforge.pmd.symboltable.Scope; +import net.sourceforge.pmd.symboltable.VariableNameDeclaration; -import java.util.Map; import java.util.Iterator; +import java.util.Map; // Would this be simplified by using DFA somehow? public class NullAssignmentRule extends AbstractRule { diff --git a/pmd/src/net/sourceforge/pmd/rules/design/PositionLiteralsFirstInComparisons.java b/pmd/src/net/sourceforge/pmd/rules/design/PositionLiteralsFirstInComparisons.java index e1b3b09b29..ce8a001fb6 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/PositionLiteralsFirstInComparisons.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/PositionLiteralsFirstInComparisons.java @@ -37,7 +37,7 @@ public class PositionLiteralsFirstInComparisons extends AbstractRule { return data; } - addViolation((RuleContext)data, (SimpleNode)exp); + addViolation(data, exp); return data; } diff --git a/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java b/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java index 01161b4f6d..90bbda6bc4 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java @@ -46,12 +46,7 @@ public class TooManyFields extends AbstractRule { int val = ((Integer)stats.get(k)).intValue(); SimpleNode n = (SimpleNode) nodes.get(k); if (val>maxFields) { - // TODO add violation with -// RuleContext ctx = (RuleContext) data; -// RuleViolation ruleViolation = createRuleViolation(ctx, node.getBeginLine(), MessageFormat.format(getMessage(), new Object[]{methodName})); -// ctx.getReport().addRuleViolation(ruleViolation); - addViolation((RuleContext) data, n); - + addViolation( data, n); } } return data; diff --git a/pmd/src/net/sourceforge/pmd/rules/optimization/AvoidInstantiatingObjectsInLoops.java b/pmd/src/net/sourceforge/pmd/rules/optimization/AvoidInstantiatingObjectsInLoops.java index a9ea05c690..14dc81902d 100644 --- a/pmd/src/net/sourceforge/pmd/rules/optimization/AvoidInstantiatingObjectsInLoops.java +++ b/pmd/src/net/sourceforge/pmd/rules/optimization/AvoidInstantiatingObjectsInLoops.java @@ -24,7 +24,7 @@ public class AvoidInstantiatingObjectsInLoops extends AbstractOptimizationRule { public Object visit(ASTAllocationExpression node, Object data) { if (insideLoop(node) && fourthParentNotThrow(node) && fourthParentNotReturn(node)) { - addViolation((RuleContext) data, node); + addViolation(data, node); } return data; } diff --git a/pmd/src/net/sourceforge/pmd/rules/optimization/LocalVariableCouldBeFinal.java b/pmd/src/net/sourceforge/pmd/rules/optimization/LocalVariableCouldBeFinal.java index 21174f9133..c52231efe9 100644 --- a/pmd/src/net/sourceforge/pmd/rules/optimization/LocalVariableCouldBeFinal.java +++ b/pmd/src/net/sourceforge/pmd/rules/optimization/LocalVariableCouldBeFinal.java @@ -32,7 +32,7 @@ public class LocalVariableCouldBeFinal extends AbstractOptimizationRule { ASTMethodDeclaration md = (ASTMethodDeclaration) node.getFirstParentOfType(ASTMethodDeclaration.class); if (md!=null) { if (!isVarWritterInMethod(varName, md) ) { - addViolation((RuleContext)data, node); + addViolation(data, node); } } return data; diff --git a/pmd/src/net/sourceforge/pmd/rules/strictexception/AvoidCatchingThrowable.java b/pmd/src/net/sourceforge/pmd/rules/strictexception/AvoidCatchingThrowable.java index d36ee3e692..830c7d9656 100644 --- a/pmd/src/net/sourceforge/pmd/rules/strictexception/AvoidCatchingThrowable.java +++ b/pmd/src/net/sourceforge/pmd/rules/strictexception/AvoidCatchingThrowable.java @@ -19,7 +19,7 @@ public class AvoidCatchingThrowable extends AbstractRule { ASTType type = (ASTType) node.findChildrenOfType(ASTType.class).get(0); ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) type.findChildrenOfType(ASTClassOrInterfaceType.class).get(0); if (name.getImage().equals("Throwable")) { - addViolation((RuleContext)data, name); + addViolation(data, name); } return super.visit(node, data); } diff --git a/pmd/src/net/sourceforge/pmd/rules/sunsecure/MethodReturnsInternalArray.java b/pmd/src/net/sourceforge/pmd/rules/sunsecure/MethodReturnsInternalArray.java index 73eafb5fb1..bba55b61c6 100644 --- a/pmd/src/net/sourceforge/pmd/rules/sunsecure/MethodReturnsInternalArray.java +++ b/pmd/src/net/sourceforge/pmd/rules/sunsecure/MethodReturnsInternalArray.java @@ -46,14 +46,14 @@ public class MethodReturnsInternalArray extends AbstractSunSecureRule { final String vn = getReturnedVariableName(ret); if (isField(vn, td)) { if (!isLocalVariable(vn, node)) { - addViolation((RuleContext)data, ret); + addViolation(data, ret); } else { // This is to handle field hiding final ASTPrimaryPrefix pp = (ASTPrimaryPrefix) ret.getFirstChildOfType(ASTPrimaryPrefix.class); if (pp!=null && pp.usesThisModifier()) { final ASTPrimarySuffix ps = (ASTPrimarySuffix) ret.getFirstChildOfType(ASTPrimarySuffix.class); if (ps.getImage().equals(vn)) { - addViolation((RuleContext)data, ret); + addViolation(data, ret); } } } diff --git a/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java b/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java index 6764ece217..49c762912a 100644 --- a/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java +++ b/pmd/src/net/sourceforge/pmd/symboltable/MethodScope.java @@ -6,7 +6,6 @@ package net.sourceforge.pmd.symboltable; import net.sourceforge.pmd.ast.ASTConstructorDeclaration; import net.sourceforge.pmd.ast.SimpleNode; import net.sourceforge.pmd.util.Applier; -import net.sourceforge.pmd.PMD; import java.util.ArrayList; import java.util.HashMap; diff --git a/pmd/src/net/sourceforge/pmd/symboltable/Scope.java b/pmd/src/net/sourceforge/pmd/symboltable/Scope.java index 7474d642dc..4c70f82195 100644 --- a/pmd/src/net/sourceforge/pmd/symboltable/Scope.java +++ b/pmd/src/net/sourceforge/pmd/symboltable/Scope.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.symboltable; import java.util.Map; -import java.util.List; /** * Provides methods which all scopes must implement