1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpdt.internal.compiler.ast.Block;
4 import net.sourceforge.phpdt.internal.compiler.ast.ArgumentDeclaration;
5 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
6 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
7 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
8 import org.eclipse.jface.resource.ImageDescriptor;
10 import java.util.Hashtable;
11 import java.util.Enumeration;
12 import java.util.ArrayList;
15 * A Method declaration.
16 * @author Matthieu Casanova
18 public class MethodDeclaration extends Statement implements OutlineableWithChildren {
21 public Hashtable arguments;
22 public Statement[] statements;
24 public int bodyEnd = -1;
25 public boolean isConstructor;
26 private Object parent;
27 /** The outlineable children (those will be in the node array too. */
28 private ArrayList children = new ArrayList();
30 public boolean reference;
32 public MethodDeclaration(Object parent,
38 super(sourceStart, sourceEnd);
40 this.arguments = arguments;
42 this.reference = reference;
46 * Return method into String, with a number of tabs
47 * @param tab the number of tabs
48 * @return the String containing the method
50 public String toString(int tab) {
51 StringBuffer buff = new StringBuffer(tabString(tab));
52 buff.append("function ");//$NON-NLS-1$
54 buff.append('&');//$NON-NLS-1$
56 buff.append(name).append("(");//$NON-NLS-1$
58 if (arguments != null) {
59 Enumeration values = arguments.elements();
61 while (values.hasMoreElements()) {
62 ArgumentDeclaration o = (ArgumentDeclaration) values.nextElement();
63 buff.append(o.toString(0));
64 if (i != (arguments.size() - 1)) {
65 buff.append(", "); //$NON-NLS-1$
70 buff.append(")"); //$NON-NLS-1$
72 buff.append(toStringStatements(tab + 1));
73 return buff.toString();
77 * Return the statements of the method into Strings
78 * @param tab the number of tabs
79 * @return the String containing the statements
81 public String toStringStatements(int tab) {
82 StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
83 if (statements != null) {
84 for (int i = 0; i < statements.length; i++) {
85 buff.append("\n").append(statements[i].toString(tab)); //$NON-NLS-1$
86 if (!(statements[i] instanceof Block)) {
87 buff.append(";"); //$NON-NLS-1$
91 buff.append("\n").append(tabString(tab == 0 ? 0 : tab - 1)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
92 return buff.toString();
96 * Get the image of a class.
97 * @return the image that represents a php class
99 public ImageDescriptor getImage() {
100 return PHPUiImages.DESC_FUN;
103 public Object getParent() {
107 public boolean add(Outlineable o) {
108 return children.add(o);
111 public Outlineable get(int index) {
112 return (Outlineable) children.get(index);
116 return children.size();