From 0d6e351e27720a3d1fe527fa9d74d6803580e217 Mon Sep 17 00:00:00 2001 From: kpouer Date: Tue, 8 Apr 2003 07:45:42 +0000 Subject: [PATCH] Some changes --- .../compiler/parser/PHPFunctionDeclaration.java | 53 +++++++++++++++++++- .../compiler/parser/PHPVarDeclaration.java | 2 +- 2 files changed, 52 insertions(+), 3 deletions(-) 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..7bb9832 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 @@ -17,7 +17,16 @@ import test.PHPVar; */ 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 +38,7 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { public PHPFunctionDeclaration(Object parent, String name, int index) { super(parent, name, index); parameters = null; + declaredVariables = null; } /** @@ -41,6 +51,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 +63,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 +74,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 +94,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); + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPVarDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPVarDeclaration.java index 03a9955..994404f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPVarDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/PHPVarDeclaration.java @@ -44,7 +44,7 @@ public class PHPVarDeclaration extends PHPSegment { } /** - * Get the PHPVar + * Get the PHPVar. * @return a phpvar object */ public PHPVar getVariable() { -- 1.7.1