*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Variable.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
4
5 import java.util.List;
6 import java.util.ArrayList;
7
8 /**
9  * A variable.
10  * It could be a simple variable, or contains another variable.
11  * @author Matthieu Casanova
12  */
13 public class Variable extends AbstractVariable {
14
15   /** The name of the variable. */
16   private String name;
17
18   /** A variable inside ($$varname). */
19   private AbstractVariable variable;
20
21   /**
22    * Create a new simple variable.
23    * @param name the name
24    * @param sourceStart the starting position
25    * @param sourceEnd the ending position
26    */
27   public Variable(final String name, final int sourceStart, final int sourceEnd) {
28     super(sourceStart, sourceEnd);
29     this.name = name;
30   }
31
32   /**
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
37    */
38   public Variable(final AbstractVariable variable, final int sourceStart, final int sourceEnd) {
39     super(sourceStart, sourceEnd);
40     this.variable = variable;
41   }
42
43   /**
44    * Return the expression as String.
45    * @return the expression
46    */
47   public String toStringExpression() {
48     return "$" + getName();
49   }
50
51   public String getName() {
52     if (variable == null) {
53       return name;
54     }
55     return variable.toStringExpression();
56   }
57
58   /**
59    * Get the variables from outside (parameters, globals ...)
60    * @return the variables from outside
61    */
62   public List getOutsideVariable() {
63     return new ArrayList(1);
64   }
65
66   /**
67    * get the modified variables.
68    * @return the variables modified
69    */
70   public List getModifiedVariable() {
71     return new ArrayList(1);
72   }
73
74   /**
75    * Get the variables used.
76    * @return the variables used
77    */
78   public List getUsedVariable() {
79     final ArrayList list = new ArrayList(1);
80     if (name == null) {
81       list.add(new VariableUsage(variable.getName(), getSourceStart()));
82     } else {
83       list.add(new VariableUsage(name, getSourceStart()));
84     }
85     return list;
86   }
87 }