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)
*/
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
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;
+ }
}
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
import org.eclipse.jface.resource.ImageDescriptor;
+import test.PHPVar;
/**
* A php variable declaration strongly inspired by the PHPFunctionDeclaration of Khartlage (:.
*/
public class PHPVarDeclaration extends PHPSegment {
- /** The value of the variable. */
- private String value;
+ /** A PHPVar. */
+ private final PHPVar variable;
/**
* Create a php variable declaration.
* @param parent the parent object (it should be a php class)
*/
public PHPVarDeclaration(Object parent, String name, int index, String value) {
super(parent, name, index);
- this.value = value;
+ variable = new PHPVar(name,value);
}
/**
return PHPUiImages.DESC_VAR;
}
+ /**
+ * Get the PHPVar
+ * @return a phpvar object
+ */
+ public PHPVar getVariable() {
+ return variable;
+ }
+
public String toString() {
- if (value == null || value.equals("")) {
- return super.toString();
- } else {
- return name + " = " + value;
- }
+ return variable.toString();
}
}