From c6784aca766e205d6b5a78b860c5558eb2bd8f3a Mon Sep 17 00:00:00 2001 From: kpouer Date: Mon, 7 Apr 2003 09:00:15 +0000 Subject: [PATCH] *** empty log message *** --- .../compiler/parser/PHPFunctionDeclaration.java | 57 +++++++++++++++++++- .../compiler/parser/PHPVarDeclaration.java | 21 +++++--- 2 files changed, 69 insertions(+), 9 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 31e473c..d94df50 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 @@ -4,12 +4,22 @@ 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 { + private final Hashtable parameters; + private String stringRepresentation; + /** * Create a function declaration. * @param parent the parent object (it should be a php class) @@ -18,8 +28,22 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { */ 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 @@ -27,4 +51,35 @@ public class PHPFunctionDeclaration extends PHPSegmentWithChildren { 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; + } } 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 ac22f1b..03a9955 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 @@ -3,6 +3,7 @@ package net.sourceforge.phpdt.internal.compiler.parser; 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 (:. @@ -10,8 +11,8 @@ import org.eclipse.jface.resource.ImageDescriptor; */ 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) @@ -21,7 +22,7 @@ public class PHPVarDeclaration extends PHPSegment { */ public PHPVarDeclaration(Object parent, String name, int index, String value) { super(parent, name, index); - this.value = value; + variable = new PHPVar(name,value); } /** @@ -42,11 +43,15 @@ public class PHPVarDeclaration extends PHPSegment { 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(); } } -- 1.7.1