First try, not finished
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / MethodDeclaration.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 /**
4  * A Method declaration.
5  * @author Matthieu Casanova
6  */
7 public class MethodDeclaration extends Statement {
8
9   public char[] name;
10   public ArgumentDeclaration[] arguments;
11   public Statement[] statements;
12   public int bodyStart;
13   public int bodyEnd = -1;
14   public boolean isConstructor;
15
16   /**
17    * Return method into String, with a number of tabs
18    * @param tab the number of tabs
19    * @return the String containing the method
20    */
21   public String toString(int tab) {
22     String s = tabString(tab);
23     StringBuffer buff = new StringBuffer(s);
24     buff.append(name).append("(");//$NON-NLS-1$
25
26     if (arguments != null) {
27       for (int i = 0; i < arguments.length; i++) {
28         buff.append(arguments[i].toString(0));
29         if (i != (arguments.length - 1)) {
30           buff.append(", "); //$NON-NLS-1$
31         }
32       }
33     }
34     buff.append(")"); //$NON-NLS-1$
35
36     s += toStringStatements(tab + 1);
37     return s;
38   }
39
40   /**
41    * Return the statements of the method into Strings
42    * @param tab the number of tabs
43    * @return the String containing the statements
44    */
45   public String toStringStatements(int tab) {
46     StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
47     if (statements != null) {
48       for (int i = 0; i < statements.length; i++) {
49         buff.append("\n").append(statements[i].toString(tab)); //$NON-NLS-1$
50         if (!(statements[i] instanceof Block)) {
51           buff.append(";"); //$NON-NLS-1$
52         }
53       }
54     }
55     buff.append("\n").append(tabString(tab == 0 ? 0 : tab - 1)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
56     return buff.toString();
57   }
58 }