1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
6 import java.util.ArrayList;
7 import java.util.Arrays;
11 * It could be a simple variable, or contains another variable.
12 * @author Matthieu Casanova
14 public class Variable extends AbstractVariable {
16 /** The name of the variable. */
19 /** A variable inside ($$varname). */
20 private AbstractVariable variable;
22 public static final String _GET = "_GET";
23 public static final String _POST = "_POST";
24 public static final String _REQUEST = "_REQUEST";
25 public static final String _SERVER = "_SERVER";
26 public static final String _SESSION = "_SESSION";
27 public static final String _this = "this";
28 public static final String GLOBALS = "GLOBALS";
29 public static final String _COOKIE = "_COOKIE";
30 public static final String _FILES = "_FILES";
31 public static final String _ENV = "_ENV";
33 /** Here is an array of all superglobals variables and the special "this". */
34 public static final String[] SPECIAL_VARS = {_GET,
46 * Create a new simple variable.
47 * @param name the name
48 * @param sourceStart the starting position
49 * @param sourceEnd the ending position
51 public Variable(final String name,
52 final int sourceStart,
53 final int sourceEnd) {
54 super(sourceStart, sourceEnd);
59 * Create a special variable ($$toto for example).
60 * @param variable the variable contained
61 * @param sourceStart the starting position
62 * @param sourceEnd the ending position
64 public Variable(final AbstractVariable variable,
65 final int sourceStart,
66 final int sourceEnd) {
67 super(sourceStart, sourceEnd);
68 this.variable = variable;
72 * Return the expression as String.
73 * @return the expression
75 public String toStringExpression() {
76 return "$" + getName();
79 public String getName() {
80 if (variable == null) {
83 return variable.toStringExpression();
87 * Get the variables from outside (parameters, globals ...)
88 * @return the variables from outside
90 public List getOutsideVariable() {
91 return new ArrayList(1);
95 * get the modified variables.
96 * @return the variables modified
98 public List getModifiedVariable() {
99 return new ArrayList(1);
103 * Get the variables used.
104 * @return the variables used
106 public List getUsedVariable() {
107 final String varName;
109 varName = variable.getName();
113 if (arrayContains(SPECIAL_VARS, name)) {
114 return new ArrayList(1);
116 final ArrayList list = new ArrayList(1);
117 list.add(new VariableUsage(varName, sourceStart));