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
This commit is contained in:
pmd
regress/test/net/sourceforge/pmd
rules
symboltable
testframework
rulesets
src/net/sourceforge/pmd
AbstractRule.java
rules
AccessorClassGeneration.javaAvoidConcatenatingNonLiteralsInStringBuffer.javaAvoidDeeplyNestedIfStmtsRule.javaAvoidFieldNameMatchingMethodName.javaAvoidFieldNameMatchingTypeName.javaAvoidNonConstructorMethodsWithClassName.javaAvoidReassigningParameters.javaBeanMembersShouldSerializeRule.javaClassNamingConventions.javaCloseConnection.javaConstructorCallsOverridableMethod.javaDoubleCheckedLocking.javaDuplicateImportsRule.javaIdempotentOperations.javaTestClassWithoutTestCases.javaUnusedModifier.javaUnusedPrivateFieldRule.java
design
AssignmentToNonFinalStatic.javaCompareObjectsWithEquals.javaExceptionAsFlowControl.javaImmutableField.javaNullAssignmentRule.javaPositionLiteralsFirstInComparisons.javaTooManyFields.java
optimization
@ -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;
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -25,7 +25,7 @@ These are new rules that are still in progress
|
||||
</example>
|
||||
</rule>
|
||||
<rule name="Foo"
|
||||
message=""
|
||||
message="blah ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.FooRule">
|
||||
<description>
|
||||
|
||||
|
@ -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})));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class CloseConnection extends AbstractRule {
|
||||
|
||||
// if all is not well, complain
|
||||
if (!closed) {
|
||||
addViolation((RuleContext) data, id);
|
||||
addViolation(data, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class IdempotentOperations extends AbstractRule {
|
||||
}
|
||||
}
|
||||
|
||||
addViolation((RuleContext)data, node);
|
||||
addViolation(data, node);
|
||||
return super.visit(node, data);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class TestClassWithoutTestCases extends AbstractRule {
|
||||
}
|
||||
|
||||
if (!testsFound) {
|
||||
addViolation((RuleContext)data, node);
|
||||
addViolation(data, node);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -37,7 +37,7 @@ public class PositionLiteralsFirstInComparisons extends AbstractRule {
|
||||
return data;
|
||||
}
|
||||
|
||||
addViolation((RuleContext)data, (SimpleNode)exp);
|
||||
addViolation(data, exp);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user