X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java index a6d027a..cd38e79 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java @@ -6,29 +6,64 @@ import java.util.List; import java.util.ArrayList; /** + * A variable. + * It could be a simple variable, or contains another variable. * @author Matthieu Casanova */ -public class Variable extends Expression { +public class Variable extends AbstractVariable { /** The name of the variable. */ - public char[] name; + private String name; + /** A variable inside ($$varname). */ + private AbstractVariable variable; - public Variable(final char[] name, final int sourceStart, final int sourceEnd) { + private static final String _GET = "_GET"; + private static final String _POST = "_POST"; + private static final String _REQUEST = "_REQUEST"; + private static final String _SERVER = "_SERVER"; + private static final String _SESSION = "_SESSION"; + private static final String _this = "this"; + + /** + * Create a new simple variable. + * @param name the name + * @param sourceStart the starting position + * @param sourceEnd the ending position + */ + public Variable(final String name, + final int sourceStart, + final int sourceEnd) { super(sourceStart, sourceEnd); this.name = name; } - /** + /** + * Create a special variable ($$toto for example). + * @param variable the variable contained + * @param sourceStart the starting position + * @param sourceEnd the ending position + */ + public Variable(final AbstractVariable variable, + final int sourceStart, + final int sourceEnd) { + super(sourceStart, sourceEnd); + this.variable = variable; + } + + /** * Return the expression as String. * @return the expression */ public String toStringExpression() { - return "$"+new String(name); + return "$" + getName(); } public String getName() { - return new String(name); + if (variable == null) { + return name; + } + return variable.toStringExpression(); } /** @@ -44,9 +79,7 @@ public class Variable extends Expression { * @return the variables modified */ public List getModifiedVariable() { - final ArrayList list = new ArrayList(1); - list.add(new VariableUsage(getName(),sourceStart)); - return list; + return new ArrayList(1); } /** @@ -54,6 +87,22 @@ public class Variable extends Expression { * @return the variables used */ public List getUsedVariable() { - return new ArrayList(1); + final String varName; + if (name == null) { + varName = variable.getName(); + } else { + varName = name; + } + if (name.equals(_GET) || + name.equals(_POST) || + name.equals(_REQUEST) || + name.equals(_SERVER) || + name.equals(_SESSION) || + name.equals(_this)) { + return new ArrayList(1); + } + final ArrayList list = new ArrayList(1); + list.add(new VariableUsage(varName, sourceStart)); + return list; } }