4a306e6b568107f0074e4a0852f2befab77bc32e
[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    */
58   public void getOutsideVariable(final List list) {
59   }
60
61   /**
62    * get the modified variables.
63    */
64   public void getModifiedVariable(final List list) {
65     key.getModifiedVariable(list);
66     if (value != null) {
67       value.getModifiedVariable(list);
68     }
69   }
70
71   /**
72    * Get the variables used.
73    */
74   public void getUsedVariable(final List list) {
75     key.getUsedVariable(list);
76     if (value != null) {
77       value.getUsedVariable(list);
78     }
79   }
80 }