1 package net.sourceforge.pmd.rules.strings; 2 3 import net.sourceforge.pmd.ast.Node; 4 import net.sourceforge.pmd.ast.SimpleNode; 5 import net.sourceforge.pmd.rules.AbstractInefficientZeroCheck; 6 import net.sourceforge.pmd.symboltable.NameOccurrence; 7 8 25 public class InefficientEmptyStringCheck extends AbstractInefficientZeroCheck { 26 27 34 public boolean isTargetMethod(NameOccurrence occ) { 35 if (occ.getNameForWhichThisIsAQualifier() != null 36 && occ.getNameForWhichThisIsAQualifier().getImage().indexOf("trim") != -1) { 37 Node pExpression = occ.getLocation().jjtGetParent().jjtGetParent(); 38 if (pExpression.jjtGetNumChildren() >= 3 39 && "length".equals(((SimpleNode) pExpression.jjtGetChild(2)).getImage())) { 40 return true; 41 } 42 } 43 return false; 44 } 45 46 public boolean appliesToClassName(String name) { 47 return "String".equals(name); 48 } 49 50 } | Popular Tags |