*/
public class PHPFunctionDeclaration extends PHPSegmentWithChildren {
+ /** The parameters of the function. */
private final Hashtable parameters;
+
+ /** The parameters of the function. */
+ private final Hashtable declaredVariables;
+
+ /**
+ * A String representation of the function (it's generated once because it needs to iterate
+ * a hashtable == long.
+ */
private String stringRepresentation;
/**
public PHPFunctionDeclaration(Object parent, String name, int index) {
super(parent, name, index);
parameters = null;
+ declaredVariables = null;
}
/**
public PHPFunctionDeclaration(Object parent, String name, int index, Hashtable parameters) {
super(parent, name, index);
this.parameters = parameters;
+ declaredVariables = (Hashtable) parameters.clone();
createStringView();
}
return PHPUiImages.DESC_FUN;
}
+ /**
+ * Return the string representation of the function.
+ * @return the string representation of the function
+ */
public String toString() {
if (parameters == null) {
return super.toString();
return stringRepresentation;
}
+ /**
+ * Create the String representation of the function.
+ */
private void createStringView() {
StringBuffer buff = new StringBuffer(name).append("(");
Enumeration vars = parameters.elements();
- boolean first = true;
+ boolean first = false;
while (vars.hasMoreElements()) {
PHPVarDeclaration o = (PHPVarDeclaration) vars.nextElement();
if (first) {
buff.append(",");
- first = false;
+ } else {
+ first = true;
}
buff.append(o.toString());
}
stringRepresentation = buff.toString();
}
+ /**
+ * Return a parameter of the function
+ * @param parameterName the name of the parameter
+ * @return it will return the PHPVarDeclaration of the parameter asked, or null
+ */
public PHPVarDeclaration getParameter(String parameterName) {
return (PHPVarDeclaration) parameters.get(parameterName);
}
+ /**
+ * Return all parameters of the function.
+ * @return a hashtable containing all PHPVarDeclaration
+ */
public Hashtable getParameters() {
return parameters;
}
+
+ /**
+ * Return a variable of the function
+ * @param variableName the name of the parameter
+ * @return it will return the PHPVarDeclaration of the parameter asked, or null
+ */
+ public PHPVarDeclaration getVariable(String variableName) {
+ return (PHPVarDeclaration) declaredVariables.get(variableName);
+ }
+
+ /**
+ * Return all declared variables of the function.
+ * @return a hashtable containing all PHPVarDeclaration
+ */
+ public Hashtable getVariables() {
+ return declaredVariables;
+ }
+
+ public Object addVariable(PHPVarDeclaration var) {
+ return declaredVariables.put(var.getVariable().getName(),var);
+ }
}