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, final int sourceStart, final int sourceEnd) {
28 super(sourceStart, sourceEnd);
33 * Create a special variable ($$toto for example).
34 * @param variable the variable contained
35 * @param sourceStart the starting position
36 * @param sourceEnd the ending position
38 public Variable(final AbstractVariable variable, final int sourceStart, final int sourceEnd) {
39 super(sourceStart, sourceEnd);
40 this.variable = variable;
44 * Return the expression as String.
45 * @return the expression
47 public String toStringExpression() {
48 return "$" + getName();
51 public String getName() {
52 if (variable == null) {
55 return variable.toStringExpression();
59 * Get the variables from outside (parameters, globals ...)
60 * @return the variables from outside
62 public List getOutsideVariable() {
63 return new ArrayList(1);
67 * get the modified variables.
68 * @return the variables modified
70 public List getModifiedVariable() {
71 return new ArrayList(1);
75 * Get the variables used.
76 * @return the variables used
78 public List getUsedVariable() {
79 final ArrayList list = new ArrayList(1);
81 list.add(new VariableUsage(variable.getName(), getSourceStart()));
83 list.add(new VariableUsage(name, getSourceStart()));