4322f61b374f97fd236ad1f33beeb75371218def
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ArrayVariableDeclaration.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4 import java.util.ArrayList;
5
6 /**
7  * a variable declaration in an array().
8  * it could take Expression as key.
9  * @author Matthieu Casanova
10  */
11 public class ArrayVariableDeclaration extends Expression {
12
13   /** the array key. */
14   public Expression key;
15
16   /** the array value. */
17   public Expression value;
18
19   /**
20    * Create a new array variable declaration.
21    * @param key the key
22    * @param value the value
23    */
24   public ArrayVariableDeclaration(final Expression key, final Expression value) {
25     super(key.sourceStart, value.sourceEnd);
26     this.key = key;
27     this.value = value;
28   }
29
30   /**
31    * Create a new array variable declaration.
32    * @param key the key
33    * @param sourceEnd the end position
34    */
35   public ArrayVariableDeclaration(final Expression key, final int sourceEnd) {
36     super(key.sourceStart, sourceEnd);
37     this.key = key;
38   }
39
40   /**
41    * Return the expression as String.
42    * @return the expression
43    */
44   public String toStringExpression() {
45     final StringBuffer buff = new StringBuffer();
46     buff.append(key.toStringExpression());
47     if (value != null) {
48       buff.append(" => ");
49       buff.append(value.toStringExpression());
50     }
51     return buff.toString();
52   }
53
54
55   /**
56    * Get the variables from outside (parameters, globals ...)
57    * @return the variables from outside
58    */
59   public List getOutsideVariable() {
60     return new ArrayList();
61   }
62
63   /**
64    * get the modified variables.
65    * @return the variables from we change value
66    */
67   public List getModifiedVariable() {
68     final ArrayList list = new ArrayList();
69     list.addAll(key.getModifiedVariable());
70     if (value != null) {
71       list.addAll(value.getModifiedVariable());
72     }
73     return list;
74   }
75
76   /**
77    * Get the variables used.
78    * @return the variables used
79    */
80   public List getUsedVariable() {
81     final ArrayList list = new ArrayList();
82     if (value != null) {
83       list.addAll(value.getUsedVariable());
84     }
85     return list;
86   }
87 }