*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / PHPFunctionDeclaration.java
1 package net.sourceforge.phpdt.internal.compiler.parser;
2
3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
4
5 import org.eclipse.jface.resource.ImageDescriptor;
6
7 import java.util.List;
8 import java.util.Hashtable;
9 import java.util.Map;
10 import java.util.Enumeration;
11
12 import test.PHPVar;
13
14 /**
15  * A function declaration.
16  * @author khartlage
17  */
18 public class PHPFunctionDeclaration extends PHPSegmentWithChildren {
19
20   private final Hashtable parameters;
21   private String stringRepresentation;
22
23   /**
24    * Create a function declaration.
25    * @param parent the parent object (it should be a php class)
26    * @param name the name of the function
27    * @param index where the function is in the file
28    */
29   public PHPFunctionDeclaration(Object parent, String name, int index) {
30     super(parent, name, index);
31     parameters = null;
32   }
33
34   /**
35    * Create a function declaration.
36    * @param parent the parent object (it should be a php class)
37    * @param name the name of the function
38    * @param index where the function is in the file
39    * @param parameters the list of parameters (it should contains only PHPVar)
40    */
41   public PHPFunctionDeclaration(Object parent, String name, int index, Hashtable parameters) {
42     super(parent, name, index);
43     this.parameters = parameters;
44     createStringView();
45   }
46
47   /**
48    * Get the image of a class.
49    * @return the image that represents a php class
50    */
51   public ImageDescriptor getImage() {
52     return PHPUiImages.DESC_FUN;
53   }
54
55   public String toString() {
56     if (parameters == null) {
57       return super.toString();
58     }
59     return stringRepresentation;
60   }
61
62   private void createStringView() {
63     StringBuffer buff = new StringBuffer(name).append("(");
64     Enumeration vars = parameters.elements();
65     boolean first = true;
66     while (vars.hasMoreElements()) {
67       PHPVarDeclaration o = (PHPVarDeclaration) vars.nextElement();
68       if (first) {
69         buff.append(",");
70         first = false;
71       }
72       buff.append(o.toString());
73     }
74     buff.append(")");
75     stringRepresentation = buff.toString();
76   }
77
78   public PHPVarDeclaration getParameter(String parameterName) {
79     return (PHPVarDeclaration) parameters.get(parameterName);
80   }
81
82   public Hashtable getParameters() {
83     return parameters;
84   }
85 }