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 cd38e79..add462f 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 @@ -18,12 +18,31 @@ public class Variable extends AbstractVariable { /** A variable inside ($$varname). */ private AbstractVariable variable; - 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"; + /** the variable is defined like this ${expression} */ + private Expression expression; + + public static final String _GET = "_GET"; + public static final String _POST = "_POST"; + public static final String _REQUEST = "_REQUEST"; + public static final String _SERVER = "_SERVER"; + public static final String _SESSION = "_SESSION"; + public static final String _this = "this"; + public static final String GLOBALS = "GLOBALS"; + public static final String _COOKIE = "_COOKIE"; + public static final String _FILES = "_FILES"; + public static final String _ENV = "_ENV"; + + /** Here is an array of all superglobals variables and the special "this". */ + public static final String[] SPECIAL_VARS = {_GET, + _POST, + _REQUEST, + _SERVER, + _SESSION, + _this, + GLOBALS, + _COOKIE, + _FILES, + _ENV}; /** * Create a new simple variable. @@ -52,6 +71,19 @@ public class Variable extends AbstractVariable { } /** + * Create a special variable ($$toto for example). + * @param expression the variable contained + * @param sourceStart the starting position + * @param sourceEnd the ending position + */ + public Variable(final Expression expression, + final int sourceStart, + final int sourceEnd) { + super(sourceStart, sourceEnd); + this.expression = expression; + } + + /** * Return the expression as String. * @return the expression */ @@ -60,10 +92,13 @@ public class Variable extends AbstractVariable { } public String getName() { - if (variable == null) { + if (name != null) { return name; } - return variable.toStringExpression(); + if (variable != null) { + return variable.toStringExpression(); + } + return "{" + expression.toStringExpression() + "}"; } /** @@ -88,17 +123,14 @@ public class Variable extends AbstractVariable { */ public List getUsedVariable() { final String varName; - if (name == null) { + if (name != null) { + varName = name; + } else if (variable != null) { varName = variable.getName(); } else { - varName = name; + varName = expression.toStringExpression();//todo : do a better thing like evaluate this ?? } - if (name.equals(_GET) || - name.equals(_POST) || - name.equals(_REQUEST) || - name.equals(_SERVER) || - name.equals(_SESSION) || - name.equals(_this)) { + if (arrayContains(SPECIAL_VARS, name)) { return new ArrayList(1); } final ArrayList list = new ArrayList(1);