X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPFunctionDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPFunctionDeclaration.java index d94df50..1c86a3f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPFunctionDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPFunctionDeclaration.java @@ -1,23 +1,28 @@ package net.sourceforge.phpdt.internal.compiler.parser; +import java.util.Enumeration; +import java.util.Hashtable; + 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 { + /** 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; /** @@ -29,6 +34,7 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { public PHPFunctionDeclaration(Object parent, String name, int index) { super(parent, name, index); parameters = null; + declaredVariables = null; } /** @@ -41,6 +47,7 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { public PHPFunctionDeclaration(Object parent, String name, int index, Hashtable parameters) { super(parent, name, index); this.parameters = parameters; + declaredVariables = (Hashtable) parameters.clone(); createStringView(); } @@ -52,6 +59,10 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { 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(); @@ -59,15 +70,19 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { 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()); } @@ -75,11 +90,41 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { 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); + } }