1 4 package net.sourceforge.pmd.rules.strings; 5 6 import net.sourceforge.pmd.AbstractRule; 7 import net.sourceforge.pmd.ast.ASTVariableDeclaratorId; 8 import net.sourceforge.pmd.symboltable.NameOccurrence; 9 10 import java.util.Iterator ; 11 12 public class StringToStringRule extends AbstractRule { 13 14 public Object visit(ASTVariableDeclaratorId node, Object data) { 15 if (!node.getNameDeclaration().getTypeImage().equals("String")) { 16 return data; 17 } 18 for (Iterator i = node.getUsages().iterator(); i.hasNext();) { 19 NameOccurrence occ = (NameOccurrence) i.next(); 20 if (occ.getNameForWhichThisIsAQualifier() != null && occ.getNameForWhichThisIsAQualifier().getImage().indexOf("toString") != -1) { 21 addViolation(data, occ.getLocation()); 22 } 23 } 24 return data; 25 } 26 } 27 | Popular Tags |