1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpdt.internal.compiler.ast.Block;
4 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
5 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
6 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
7 import org.eclipse.jface.resource.ImageDescriptor;
9 import java.util.Hashtable;
10 import java.util.Enumeration;
11 import java.util.ArrayList;
14 * A Method declaration.
15 * @author Matthieu Casanova
17 public class MethodDeclaration extends Statement implements OutlineableWithChildren {
19 /** The name of the method. */
21 public Hashtable arguments;
24 public Statement[] statements;
26 public int bodyEnd = -1;
27 /** Tell if the method is a class constructor. */
28 public boolean isConstructor;
29 private Object parent;
30 /** The outlineable children (those will be in the node array too. */
31 private ArrayList children = new ArrayList();
33 public boolean reference;
35 public MethodDeclaration(Object parent,
41 super(sourceStart, sourceEnd);
43 this.arguments = arguments;
45 this.reference = reference;
49 * Return method into String, with a number of tabs
50 * @param tab the number of tabs
51 * @return the String containing the method
53 public String toString(int tab) {
54 StringBuffer buff = new StringBuffer(tabString(tab));
55 buff.append("function ");//$NON-NLS-1$
57 buff.append('&');//$NON-NLS-1$
59 buff.append(name).append("(");//$NON-NLS-1$
61 if (arguments != null) {
62 Enumeration values = arguments.elements();
64 while (values.hasMoreElements()) {
65 VariableDeclaration o = (VariableDeclaration) values.nextElement();
66 buff.append(o.toStringExpression());
67 if (i != (arguments.size() - 1)) {
68 buff.append(", "); //$NON-NLS-1$
73 buff.append(")"); //$NON-NLS-1$
75 buff.append(toStringStatements(tab + 1));
76 return buff.toString();
80 * Return the statements of the method into Strings
81 * @param tab the number of tabs
82 * @return the String containing the statements
84 public String toStringStatements(int tab) {
85 StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
86 if (statements != null) {
87 for (int i = 0; i < statements.length; i++) {
88 buff.append("\n").append(statements[i].toString(tab)); //$NON-NLS-1$
89 if (!(statements[i] instanceof Block)) {
90 buff.append(";"); //$NON-NLS-1$
94 buff.append("\n").append(tabString(tab == 0 ? 0 : tab - 1)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
95 return buff.toString();
99 * Get the image of a class.
100 * @return the image that represents a php class
102 public ImageDescriptor getImage() {
103 return PHPUiImages.DESC_FUN;
106 public Object getParent() {
110 public boolean add(Outlineable o) {
111 return children.add(o);
114 public Outlineable get(int index) {
115 return (Outlineable) children.get(index);
119 return children.size();