01 /* Generated By:JJTree: Do not edit this line. ASTMethodDeclaration.java */
02
03 package net.sourceforge.pmd.lang.java.ast;
04
05 public class ASTMethodDeclaration extends AbstractJavaAccessNode {
06 public ASTMethodDeclaration(int id) {
07 super(id);
08 }
09
10 public ASTMethodDeclaration(JavaParser p, int id) {
11 super(p, id);
12 }
13
14 /**
15 * Accept the visitor. *
16 */
17 @Override
18 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
19 return visitor.visit(this, data);
20 }
21
22 /**
23 * Gets the name of the method.
24 *
25 * @return a String representing the name of the method
26 */
27 public String getMethodName() {
28 ASTMethodDeclarator md = getFirstChildOfType(ASTMethodDeclarator.class);
29 if (md != null) {
30 return md.getImage();
31 }
32 return null;
33 }
34
35 public boolean isSyntacticallyPublic() {
36 return super.isPublic();
37 }
38
39 public boolean isSyntacticallyAbstract() {
40 return super.isAbstract();
41 }
42
43 @Override
44 public boolean isPublic() {
45 if (isInterfaceMember()) {
46 return true;
47 }
48 return super.isPublic();
49 }
50
51 @Override
52 public boolean isAbstract() {
53 if (isInterfaceMember()) {
54 return true;
55 }
56 return super.isAbstract();
57 }
58
59 public boolean isInterfaceMember() {
60 ASTClassOrInterfaceDeclaration clz = getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
61 return clz != null && clz.isInterface();
62 }
63
64 public boolean isVoid() {
65 return getResultType().isVoid();
66 }
67
68 public ASTResultType getResultType() {
69 return getFirstChildOfType(ASTResultType.class);
70 }
71
72 public ASTBlock getBlock() {
73 // FIXME doesn't work for all methods that use generics and declare exceptions
74 if (this.jjtGetChild(2) instanceof ASTBlock) {
75 return (ASTBlock) this.jjtGetChild(2);
76 }
77 if (jjtGetNumChildren() > 3) {
78 if (this.jjtGetChild(3) instanceof ASTBlock) {
79 return (ASTBlock) this.jjtGetChild(3);
80 }
81 }
82 return null;
83 }
84 }
|