|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| package net.sourceforge.pmd.rules.sunsecure; |
|
7 |
| |
|
8 |
| import net.sourceforge.pmd.AbstractRule; |
|
9 |
| import net.sourceforge.pmd.ast.ASTFieldDeclaration; |
|
10 |
| import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration; |
|
11 |
| import net.sourceforge.pmd.ast.ASTName; |
|
12 |
| import net.sourceforge.pmd.ast.ASTPrimarySuffix; |
|
13 |
| import net.sourceforge.pmd.ast.ASTReturnStatement; |
|
14 |
| import net.sourceforge.pmd.ast.ASTTypeDeclaration; |
|
15 |
| import net.sourceforge.pmd.ast.ASTVariableDeclaratorId; |
|
16 |
| import net.sourceforge.pmd.ast.SimpleNode; |
|
17 |
| |
|
18 |
| import java.util.Iterator; |
|
19 |
| import java.util.List; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| public abstract class AbstractSunSecureRule extends AbstractRule { |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
9
| protected final boolean isField(String varName, ASTTypeDeclaration typeDeclaration) {
|
|
36 |
9
| final List fds = typeDeclaration.findChildrenOfType(ASTFieldDeclaration.class);
|
|
37 |
9
| if (fds != null) {
|
|
38 |
9
| for (Iterator it = fds.iterator(); it.hasNext();) {
|
|
39 |
7
| final ASTFieldDeclaration fd = (ASTFieldDeclaration) it.next();
|
|
40 |
7
| final ASTVariableDeclaratorId vid = (ASTVariableDeclaratorId) fd.getFirstChildOfType(ASTVariableDeclaratorId.class);
|
|
41 |
7
| if (vid != null && vid.hasImageEqualTo(varName)) {
|
|
42 |
6
| return true;
|
|
43 |
| } |
|
44 |
| } |
|
45 |
| } |
|
46 |
3
| return false;
|
|
47 |
| } |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
9
| protected final String getReturnedVariableName(ASTReturnStatement ret) {
|
|
61 |
9
| final ASTName n = (ASTName) ret.getFirstChildOfType(ASTName.class);
|
|
62 |
9
| if (n != null)
|
|
63 |
6
| return n.getImage();
|
|
64 |
3
| final ASTPrimarySuffix ps = (ASTPrimarySuffix) ret.getFirstChildOfType(ASTPrimarySuffix.class);
|
|
65 |
3
| if (ps != null)
|
|
66 |
3
| return ps.getImage();
|
|
67 |
0
| return null;
|
|
68 |
| } |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
16
| protected boolean isLocalVariable(String vn, SimpleNode node) {
|
|
79 |
16
| final List lvars = node.findChildrenOfType(ASTLocalVariableDeclaration.class);
|
|
80 |
16
| if (lvars != null) {
|
|
81 |
16
| for (Iterator it = lvars.iterator(); it.hasNext();) {
|
|
82 |
3
| final ASTLocalVariableDeclaration lvd = (ASTLocalVariableDeclaration) it.next();
|
|
83 |
3
| final ASTVariableDeclaratorId vid = (ASTVariableDeclaratorId) lvd.getFirstChildOfType(ASTVariableDeclaratorId.class);
|
|
84 |
3
| if (vid != null && vid.hasImageEqualTo(vn)) {
|
|
85 |
3
| return true;
|
|
86 |
| } |
|
87 |
| } |
|
88 |
| } |
|
89 |
13
| return false;
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
14
| protected String getFirstNameImage(SimpleNode n) {
|
|
99 |
14
| ASTName name = (ASTName) n.getFirstChildOfType(ASTName.class);
|
|
100 |
14
| if (name != null)
|
|
101 |
12
| return name.getImage();
|
|
102 |
2
| return null;
|
|
103 |
| } |
|
104 |
| |
|
105 |
| } |