*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / PHPFunctionDeclaration.java
index 31e473c..d94df50 100644 (file)
@@ -4,12 +4,22 @@ import net.sourceforge.phpdt.internal.ui.PHPUiImages;
 
 import org.eclipse.jface.resource.ImageDescriptor;
 
+import java.util.List;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Enumeration;
+
+import test.PHPVar;
+
 /**
  * A function declaration.
  * @author khartlage
  */
 public class PHPFunctionDeclaration extends PHPSegmentWithChildren {
 
+  private final Hashtable parameters;
+  private String stringRepresentation;
+
   /**
    * Create a function declaration.
    * @param parent the parent object (it should be a php class)
@@ -18,8 +28,22 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren {
    */
   public PHPFunctionDeclaration(Object parent, String name, int index) {
     super(parent, name, index);
+    parameters = null;
   }
-  
+
+  /**
+   * Create a function declaration.
+   * @param parent the parent object (it should be a php class)
+   * @param name the name of the function
+   * @param index where the function is in the file
+   * @param parameters the list of parameters (it should contains only PHPVar)
+   */
+  public PHPFunctionDeclaration(Object parent, String name, int index, Hashtable parameters) {
+    super(parent, name, index);
+    this.parameters = parameters;
+    createStringView();
+  }
+
   /**
    * Get the image of a class.
    * @return the image that represents a php class
@@ -27,4 +51,35 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren {
   public ImageDescriptor getImage() {
     return PHPUiImages.DESC_FUN;
   }
+
+  public String toString() {
+    if (parameters == null) {
+      return super.toString();
+    }
+    return stringRepresentation;
+  }
+
+  private void createStringView() {
+    StringBuffer buff = new StringBuffer(name).append("(");
+    Enumeration vars = parameters.elements();
+    boolean first = true;
+    while (vars.hasMoreElements()) {
+      PHPVarDeclaration o = (PHPVarDeclaration) vars.nextElement();
+      if (first) {
+        buff.append(",");
+        first = false;
+      }
+      buff.append(o.toString());
+    }
+    buff.append(")");
+    stringRepresentation = buff.toString();
+  }
+
+  public PHPVarDeclaration getParameter(String parameterName) {
+    return (PHPVarDeclaration) parameters.get(parameterName);
+  }
+
+  public Hashtable getParameters() {
+    return parameters;
+  }
 }