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