1
2
3 package net.sourceforge.pmd.ast;
4
5 public class ASTMethodDeclaration extends AccessNode {
6 public ASTMethodDeclaration(int id) {
7 super(id);
8 }
9
10 public ASTMethodDeclaration(JavaParser p, int id) {
11 super(p, id);
12 }
13
14 /***
15 * Accept the visitor. *
16 */
17 public Object jjtAccept(JavaParserVisitor visitor, Object data) {
18 return visitor.visit(this, data);
19 }
20
21 public void dump(String prefix) {
22 System.out.println(collectDumpedModifiers(prefix));
23 dumpChildren(prefix);
24 }
25
26 /***
27 * Gets the name of the method.
28 * @return a String representing the name of the method
29 */
30 public String getMethodName() {
31 ASTMethodDeclarator md = (ASTMethodDeclarator) getFirstChildOfType(ASTMethodDeclarator.class);
32 if (md!=null)
33 return md.getImage();
34 return null;
35 }
36
37 public boolean isVoid() {
38 return ((ASTResultType)getFirstChildOfType(ASTResultType.class)).isVoid();
39 }
40
41 public ASTResultType getResultType() {
42 return (ASTResultType)getFirstChildOfType(ASTResultType.class);
43 }
44
45 public ASTBlock getBlock() {
46 if (this.jjtGetChild(2) instanceof ASTBlock) {
47 return (ASTBlock)this.jjtGetChild(2);
48 }
49 if (jjtGetNumChildren() > 3) {
50 if (this.jjtGetChild(3) instanceof ASTBlock) {
51 return (ASTBlock)this.jjtGetChild(3);
52 }
53 }
54 return null;
55 }
56 }