1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
6 import java.util.ArrayList;
10 * It could be a simple variable, or contains another variable.
11 * @author Matthieu Casanova
13 public class Variable extends AbstractVariable {
15 /** The name of the variable. */
18 /** A variable inside ($$varname). */
19 private AbstractVariable variable;
22 * Create a new simple variable.
23 * @param name the name
24 * @param sourceStart the starting position
25 * @param sourceEnd the ending position
27 public Variable(final String name,
28 final int sourceStart,
29 final int sourceEnd) {
30 super(sourceStart, sourceEnd);
35 * Create a special variable ($$toto for example).
36 * @param variable the variable contained
37 * @param sourceStart the starting position
38 * @param sourceEnd the ending position
40 public Variable(final AbstractVariable variable,
41 final int sourceStart,
42 final int sourceEnd) {
43 super(sourceStart, sourceEnd);
44 this.variable = variable;
48 * Return the expression as String.
49 * @return the expression
51 public String toStringExpression() {
52 return "$" + getName();
55 public String getName() {
56 if (variable == null) {
59 return variable.toStringExpression();
63 * Get the variables from outside (parameters, globals ...)
64 * @return the variables from outside
66 public List getOutsideVariable() {
67 return new ArrayList(1);
71 * get the modified variables.
72 * @return the variables modified
74 public List getModifiedVariable() {
75 return new ArrayList(1);
79 * Get the variables used.
80 * @return the variables used
82 public List getUsedVariable() {
83 final ArrayList list = new ArrayList(1);
85 list.add(new VariableUsage(variable.getName(), sourceStart));
87 list.add(new VariableUsage(name, sourceStart));