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