package net.sourceforge.phpdt.internal.compiler.ast; import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage; import java.util.List; import java.util.ArrayList; /** * A variable. * It could be a simple variable, or contains another variable. * @author Matthieu Casanova */ public class Variable extends AbstractVariable { /** The name of the variable. */ private String name; /** A variable inside ($$varname). */ private AbstractVariable variable; /** * Create a new simple variable. * @param name the name * @param sourceStart the starting position * @param sourceEnd the ending position */ public Variable(final String name, final int sourceStart, final int sourceEnd) { super(sourceStart, sourceEnd); this.name = name; } /** * Create a special variable ($$toto for example). * @param variable the variable contained * @param sourceStart the starting position * @param sourceEnd the ending position */ public Variable(final AbstractVariable variable, final int sourceStart, final int sourceEnd) { super(sourceStart, sourceEnd); this.variable = variable; } /** * Return the expression as String. * @return the expression */ public String toStringExpression() { return "$" + getName(); } public String getName() { if (variable == null) { return name; } return variable.toStringExpression(); } /** * Get the variables from outside (parameters, globals ...) * @return the variables from outside */ public List getOutsideVariable() { return new ArrayList(1); } /** * get the modified variables. * @return the variables modified */ public List getModifiedVariable() { return new ArrayList(1); } /** * Get the variables used. * @return the variables used */ public List getUsedVariable() { final ArrayList list = new ArrayList(1); if (name == null) { list.add(new VariableUsage(variable.getName(), getSourceStart())); } else { list.add(new VariableUsage(name, getSourceStart())); } return list; } }