1 package net.sourceforge.pmd.lang.java.rule.strings;
2
3 import net.sourceforge.pmd.lang.ast.Node;
4 import net.sourceforge.pmd.lang.java.rule.AbstractInefficientZeroCheck;
5 import net.sourceforge.pmd.lang.java.symboltable.NameOccurrence;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public class InefficientEmptyStringCheckRule extends AbstractInefficientZeroCheck {
25
26
27
28
29
30
31
32
33 public boolean isTargetMethod(NameOccurrence occ) {
34 if (occ.getNameForWhichThisIsAQualifier() != null
35 && occ.getNameForWhichThisIsAQualifier().getImage().indexOf("trim") != -1) {
36 Node pExpression = occ.getLocation().jjtGetParent().jjtGetParent();
37 if (pExpression.jjtGetNumChildren() >= 3
38 && "length".equals(pExpression.jjtGetChild(2).getImage())) {
39 return true;
40 }
41 }
42 return false;
43 }
44
45 public boolean appliesToClassName(String name) {
46 return "String".equals(name);
47 }
48
49 }