1
2
3
4 package net.sourceforge.pmd.lang.java.rule.strings;
5
6 import net.sourceforge.pmd.lang.java.ast.ASTBlockStatement;
7 import net.sourceforge.pmd.lang.java.ast.ASTLiteral;
8 import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
9
10
11
12
13
14
15
16
17
18
19
20
21 public class AppendCharacterWithCharRule extends AbstractJavaRule {
22
23 @Override
24 public Object visit(ASTLiteral node, Object data) {
25 ASTBlockStatement bs = node.getFirstParentOfType(ASTBlockStatement.class);
26 if (bs == null) {
27 return data;
28 }
29
30 if (node.isSingleCharacterStringLiteral()) {
31 if (!InefficientStringBufferingRule.isInStringBufferOperation(node, 8, "append")) {
32 return data;
33 }
34 addViolation(data, node);
35 }
36 return data;
37 }
38 }