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