Some minor changes
[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
5 /**
6  * a variable declaration in an array().
7  * it could take Expression as key.
8  * 
9  * @author Matthieu Casanova
10  */
11 public final class ArrayVariableDeclaration extends Expression {
12
13   /** the array key. */
14   private final Expression key;
15
16   /** the array value. */
17   private Expression value;
18
19   /**
20    * Create a new array variable declaration.
21    * 
22    * @param key   the key
23    * @param value the value
24    */
25   public ArrayVariableDeclaration(final Expression key, final Expression value) {
26     super(key.sourceStart, value.sourceEnd);
27     this.key = key;
28     this.value = value;
29   }
30
31   /**
32    * Create a new array variable declaration.
33    * 
34    * @param key       the key
35    * @param sourceEnd the end position
36    */
37   public ArrayVariableDeclaration(final Expression key, final int sourceEnd) {
38     super(key.sourceStart, sourceEnd);
39     this.key = key;
40   }
41
42   /**
43    * Return the expression as String.
44    * 
45    * @return the expression
46    */
47   public String toStringExpression() {
48     if (value == null) {
49       return key.toStringExpression();
50     } else {
51       final String keyString = key.toStringExpression();
52       final String valueString = value.toStringExpression();
53       final StringBuffer buff = new StringBuffer(keyString.length() + valueString.length() + 3);
54       buff.append(keyString);
55       buff.append(" => ");
56       buff.append(valueString);
57       return buff.toString();
58     }
59   }
60
61
62   /**
63    * Get the variables from outside (parameters, globals ...)
64    * 
65    * @param list the list where we will put variables
66    */
67   public void getOutsideVariable(final List list) {
68   }
69
70   /**
71    * get the modified variables.
72    * 
73    * @param list the list where we will put variables
74    */
75   public void getModifiedVariable(final List list) {
76     key.getModifiedVariable(list);
77     if (value != null) {
78       value.getModifiedVariable(list);
79     }
80   }
81
82   /**
83    * Get the variables used.
84    * 
85    * @param list the list where we will put variables
86    */
87   public void getUsedVariable(final List list) {
88     key.getUsedVariable(list);
89     if (value != null) {
90       value.getUsedVariable(list);
91     }
92   }
93 }