Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 32 |  | Methods: | 1
| NCLOC: | 22 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
AvoidUsingOctalValues.java | 100% | 100% | 100% | 100% |

1 |  | package net.sourceforge.pmd.rules.basic;
2 |  |
3 |  | import java.util.regex.Pattern;
4 |  |
5 |  | import net.sourceforge.pmd.AbstractRule;
6 |  | import net.sourceforge.pmd.PropertyDescriptor;
7 |  | import net.sourceforge.pmd.ast.ASTLiteral;
8 |  | import net.sourceforge.pmd.properties.BooleanProperty;
9 |  |
10 |  | public class AvoidUsingOctalValues extends AbstractRule {
11 |  |
12 |  | public static final Pattern OCTAL_PATTERN = Pattern.compile("0[0-7]{2,}[lL]?");
13 |  |
14 |  | public static final Pattern STRICT_OCTAL_PATTERN = Pattern.compile("0[0-7]+[lL]?");
15 |  |
16 |  | private static final PropertyDescriptor strictMethodsDescriptor = new BooleanProperty(
17 |  | "strict", "Detect violations for 00 to 07.", false, 1.0f
18 |  | );
19 |  |
20 | 8 | public Object visit(ASTLiteral node, Object data) {
21 | 8 | boolean strict = getBooleanProperty(strictMethodsDescriptor);
22 | 8 | Pattern p = strict?STRICT_OCTAL_PATTERN:OCTAL_PATTERN;
23 |  |
24 | 8 | String img = node.getImage();
25 | 8 | if (img != null && p.matcher(img).matches()) {
26 | 3 | addViolation(data, node);
27 |  | }
28 |  |
29 | 8 | return data;
30 |  | }
31 |  |
32 |  | }