1 package net.sourceforge.phpdt.internal.compiler.ast;
5 import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
9 * It could be a simple variable, or contains another variable.
10 * @author Matthieu Casanova
12 public class Variable extends AbstractVariable {
14 /** The name of the variable. */
17 /** A variable inside ($$varname). */
18 private AbstractVariable variable;
20 /** the variable is defined like this ${expression} */
21 private Expression expression;
23 public static final String _GET = "_GET";
24 public static final String _POST = "_POST";
25 public static final String _REQUEST = "_REQUEST";
26 public static final String _SERVER = "_SERVER";
27 public static final String _SESSION = "_SESSION";
28 public static final String _this = "this";
29 public static final String GLOBALS = "GLOBALS";
30 public static final String _COOKIE = "_COOKIE";
31 public static final String _FILES = "_FILES";
32 public static final String _ENV = "_ENV";
34 /** Here is an array of all superglobals variables and the special "this". */
35 public static final String[] SPECIAL_VARS = {_GET,
47 * Create a new simple variable.
48 * @param name the name
49 * @param sourceStart the starting position
50 * @param sourceEnd the ending position
52 public Variable(final String name,
53 final int sourceStart,
54 final int sourceEnd) {
55 super(sourceStart, sourceEnd);
60 * Create a special variable ($$toto for example).
61 * @param variable the variable contained
62 * @param sourceStart the starting position
63 * @param sourceEnd the ending position
65 public Variable(final AbstractVariable variable,
66 final int sourceStart,
67 final int sourceEnd) {
68 super(sourceStart, sourceEnd);
69 this.variable = variable;
73 * Create a special variable ($$toto for example).
74 * @param expression the variable contained
75 * @param sourceStart the starting position
76 * @param sourceEnd the ending position
78 public Variable(final Expression expression,
79 final int sourceStart,
80 final int sourceEnd) {
81 super(sourceStart, sourceEnd);
82 this.expression = expression;
86 * Return the expression as String.
87 * @return the expression
89 public String toStringExpression() {
90 return "$" + getName();
93 public String getName() {
97 if (variable != null) {
98 return variable.toStringExpression();
100 return "{" + expression.toStringExpression() + "}";
104 * Get the variables from outside (parameters, globals ...)
106 public void getOutsideVariable(final List list) {
110 * get the modified variables.
112 public void getModifiedVariable(final List list) {
116 * Get the variables used.
118 public void getUsedVariable(final List list) {
119 final String varName;
122 } else if (variable != null) {
123 varName = variable.getName();
125 varName = expression.toStringExpression();//todo : do a better thing like evaluate this ??
127 if (!arrayContains(SPECIAL_VARS, name)) {
128 list.add(new VariableUsage(varName, sourceStart));