*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ConditionalExpression.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4 import java.util.ArrayList;
5
6 /**
7  * A ConditionalExpression is like that : booleanExpression ? trueValue : falseValue;
8  * @author Matthieu Casanova
9  */
10 public class ConditionalExpression extends OperatorExpression {
11
12   public Expression condition, valueIfTrue, valueIfFalse;
13
14   public ConditionalExpression(final Expression condition,
15                                final Expression valueIfTrue,
16                                final Expression valueIfFalse) {
17     super(-1, condition.sourceStart, valueIfFalse.sourceEnd);
18     this.condition = condition;
19     this.valueIfTrue = valueIfTrue;
20     this.valueIfFalse = valueIfFalse;
21   }
22
23   public String toStringExpression() {
24     final StringBuffer buff = new StringBuffer("(");
25     buff.append(condition.toStringExpression());
26     buff.append(") ? ");
27     buff.append(valueIfTrue.toStringExpression());
28     buff.append(" : ");
29     buff.append(valueIfFalse.toStringExpression());
30     return buff.toString();
31   }
32
33   /**
34    * Get the variables from outside (parameters, globals ...)
35    * @return the variables from outside
36    */
37   public List getOutsideVariable() {
38     return new ArrayList();
39   }
40
41   /**
42    * get the modified variables.
43    * @return the variables from we change value
44    */
45   public List getModifiedVariable() {
46     final ArrayList list = new ArrayList();
47     list.addAll(condition.getModifiedVariable());
48     list.addAll(valueIfTrue.getModifiedVariable());
49     list.addAll(valueIfFalse.getModifiedVariable());
50     return list;
51   }
52
53   /**
54    * Get the variables used.
55    * @return the variables used
56    */
57   public List getUsedVariable() {
58     final ArrayList list = new ArrayList();
59     list.addAll(condition.getUsedVariable());
60     list.addAll(valueIfTrue.getUsedVariable());
61     list.addAll(valueIfFalse.getUsedVariable());
62     return list;
63   }
64 }