From 54c9b32615394622058bf9ab932f869404e00307 Mon Sep 17 00:00:00 2001 From: Wouter Zelle Date: Thu, 25 Oct 2007 11:11:44 +0000 Subject: [PATCH] cleanups git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5582 51baf565-9d33-0410-a72c-fc3788e3496d --- .../InsufficientStringBufferDeclaration.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/rules/strings/InsufficientStringBufferDeclaration.java b/pmd/src/net/sourceforge/pmd/rules/strings/InsufficientStringBufferDeclaration.java index 0f13d3d381..5045fd0e60 100644 --- a/pmd/src/net/sourceforge/pmd/rules/strings/InsufficientStringBufferDeclaration.java +++ b/pmd/src/net/sourceforge/pmd/rules/strings/InsufficientStringBufferDeclaration.java @@ -3,6 +3,12 @@ */ package net.sourceforge.pmd.rules.strings; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.ast.ASTAdditiveExpression; import net.sourceforge.pmd.ast.ASTBlockStatement; @@ -21,15 +27,8 @@ import net.sourceforge.pmd.ast.ASTVariableDeclaratorId; import net.sourceforge.pmd.ast.Node; import net.sourceforge.pmd.ast.SimpleNode; import net.sourceforge.pmd.symboltable.NameOccurrence; -import net.sourceforge.pmd.symboltable.VariableNameDeclaration; import net.sourceforge.pmd.typeresolution.TypeHelper; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - /** * This rule finds StringBuffers which may have been pre-sized incorrectly * @@ -38,17 +37,17 @@ import java.util.Set; */ public class InsufficientStringBufferDeclaration extends AbstractRule { - private final static Set blockParents; + private final static Set> blockParents; static { - blockParents = new HashSet(); + blockParents = new HashSet>(); blockParents.add(ASTIfStatement.class); blockParents.add(ASTSwitchStatement.class); } public Object visit(ASTVariableDeclaratorId node, Object data) { - if (!TypeHelper.isA((VariableNameDeclaration)node.getNameDeclaration(), StringBuffer.class)) { + if (!TypeHelper.isA(node.getNameDeclaration(), StringBuffer.class)) { return data; } Node rootNode = node; @@ -222,7 +221,7 @@ public class InsufficientStringBufferDeclaration extends AbstractRule { literal = block.findChildrenOfType(ASTLiteral.class); if (literal.isEmpty()) { - List name = block.findChildrenOfType(ASTName.class); + List name = block.findChildrenOfType(ASTName.class); if (!name.isEmpty()) { iConstructorLength = -1; } @@ -252,7 +251,6 @@ public class InsufficientStringBufferDeclaration extends AbstractRule { private int getInitialLength(SimpleNode node) { SimpleNode block = node.getFirstParentOfType(ASTBlockStatement.class); - List literal; if (block == null) { block = node.getFirstParentOfType(ASTFieldDeclaration.class); @@ -260,9 +258,9 @@ public class InsufficientStringBufferDeclaration extends AbstractRule { block = node.getFirstParentOfType(ASTFormalParameter.class); } } - literal = (block.findChildrenOfType(ASTLiteral.class)); + List literal = block.findChildrenOfType(ASTLiteral.class); if (literal.size() == 1) { - String str = ((SimpleNode) literal.get(0)).getImage(); + String str = literal.get(0).getImage(); if (str != null && isLiteral(str)) { return str.length() - 2; // take off the quotes }