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 {
 
  20   /** The name of the method. */
 
  22   public Hashtable arguments;
 
  25   public Statement[] statements;
 
  27   public int bodyEnd = -1;
 
  28   /** Tell if the method is a class constructor. */
 
  29   public boolean isConstructor;
 
  30   private Object parent;
 
  31   /** The outlineable children (those will be in the node array too. */
 
  32   private ArrayList children = new ArrayList();
 
  34   public boolean reference;
 
  36   public MethodDeclaration(Object parent,
 
  42     super(sourceStart, sourceEnd);
 
  44     this.arguments = arguments;
 
  46     this.reference = reference;
 
  50    * Return method into String, with a number of tabs
 
  51    * @param tab the number of tabs
 
  52    * @return the String containing the method
 
  54   public String toString(int tab) {
 
  55     StringBuffer buff = new StringBuffer(tabString(tab));
 
  56     buff.append("function ");//$NON-NLS-1$
 
  58       buff.append('&');//$NON-NLS-1$
 
  60     buff.append(name).append("(");//$NON-NLS-1$
 
  62     if (arguments != null) {
 
  63       Enumeration values = arguments.elements();
 
  65       while (values.hasMoreElements()) {
 
  66         ArgumentDeclaration o = (ArgumentDeclaration) values.nextElement();
 
  67         buff.append(o.toString(0));
 
  68         if (i != (arguments.size() - 1)) {
 
  69           buff.append(", "); //$NON-NLS-1$
 
  74     buff.append(")"); //$NON-NLS-1$
 
  76    buff.append(toStringStatements(tab + 1));
 
  77     return buff.toString();
 
  81    * Return the statements of the method into Strings
 
  82    * @param tab the number of tabs
 
  83    * @return the String containing the statements
 
  85   public String toStringStatements(int tab) {
 
  86     StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
 
  87     if (statements != null) {
 
  88       for (int i = 0; i < statements.length; i++) {
 
  89         buff.append("\n").append(statements[i].toString(tab)); //$NON-NLS-1$
 
  90         if (!(statements[i] instanceof Block)) {
 
  91           buff.append(";"); //$NON-NLS-1$
 
  95     buff.append("\n").append(tabString(tab == 0 ? 0 : tab - 1)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
 
  96     return buff.toString();
 
 100    * Get the image of a class.
 
 101    * @return the image that represents a php class
 
 103   public ImageDescriptor getImage() {
 
 104     return PHPUiImages.DESC_FUN;
 
 107   public Object getParent() {
 
 111   public boolean add(Outlineable o) {
 
 112     return children.add(o);
 
 115   public Outlineable get(int index) {
 
 116     return (Outlineable) children.get(index);
 
 120     return children.size();