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