1
2
3
4
5
6 package net.sourceforge.pmd.lang.java.ast;
7
8 import net.sourceforge.pmd.lang.ast.Node;
9 import net.sourceforge.pmd.lang.dfa.DFAGraphMethod;
10
11 public class ASTMethodDeclaration extends AbstractJavaAccessNode implements DFAGraphMethod {
12 public ASTMethodDeclaration(int id) {
13 super(id);
14 }
15
16 public ASTMethodDeclaration(JavaParser p, int id) {
17 super(p, id);
18 }
19
20
21
22
23 @Override
24 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
25 return visitor.visit(this, data);
26 }
27
28
29
30
31
32
33 public String getMethodName() {
34 ASTMethodDeclarator md = getFirstChildOfType(ASTMethodDeclarator.class);
35 if (md != null) {
36 return md.getImage();
37 }
38 return null;
39 }
40
41 public String getName() {
42 return getMethodName();
43 }
44
45 public boolean isSyntacticallyPublic() {
46 return super.isPublic();
47 }
48
49 public boolean isSyntacticallyAbstract() {
50 return super.isAbstract();
51 }
52
53 @Override
54 public boolean isPublic() {
55 if (isInterfaceMember()) {
56 return true;
57 }
58 return super.isPublic();
59 }
60
61 @Override
62 public boolean isAbstract() {
63 if (isInterfaceMember()) {
64 return true;
65 }
66 return super.isAbstract();
67 }
68
69 public boolean isInterfaceMember() {
70 ASTClassOrInterfaceDeclaration clz = getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
71 return clz != null && clz.isInterface();
72 }
73
74 public boolean isVoid() {
75 return getResultType().isVoid();
76 }
77
78 public ASTResultType getResultType() {
79 return getFirstChildOfType(ASTResultType.class);
80 }
81
82 public ASTBlock getBlock() {
83 for (int i = 0; i < jjtGetNumChildren(); i++) {
84 Node n = jjtGetChild(i);
85 if (n instanceof ASTBlock) {
86 return (ASTBlock)n;
87 }
88 }
89 return null;
90 }
91
92 public ASTNameList getThrows() {
93 int declaratorIndex = -1;
94 for (int i = 0; i < jjtGetNumChildren(); i++) {
95 Node child = jjtGetChild(i);
96 if (child instanceof ASTMethodDeclarator) {
97 declaratorIndex = i;
98 break;
99 }
100 }
101
102 if (jjtGetNumChildren() > declaratorIndex + 1) {
103 Node n = jjtGetChild(declaratorIndex + 1);
104 if (n instanceof ASTNameList) {
105 return (ASTNameList)n;
106 }
107 }
108 return null;
109 }
110 }