1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
6 import java.util.ArrayList;
9 * A Variable assignation.
10 * $varname = initializer
11 * @author Matthieu Casanova
13 public class VarAssignation extends Expression {
15 public static final int EQUAL = 0;
16 public static final int PLUS_EQUAL = 1;
17 public static final int MINUS_EQUAL = 2;
18 public static final int STAR_EQUAL = 3;
19 public static final int SLASH_EQUAL = 4;
20 public static final int AND_EQUAL = 5;
21 public static final int OR_EQUAL = 6;
22 public static final int XOR_EQUAL = 7;
23 public static final int DOT_EQUAL = 8;
24 public static final int REM_EQUAL = 9;
25 public static final int TILDE_EQUAL = 10;
26 public static final int LSHIFT_EQUAL = 11;
27 public static final int RSIGNEDSHIFT_EQUAL = 12;
29 public Expression variableName;
30 public Expression initializer;
34 * Create a new variable assignation.
35 * @param variableName the name of the variable
36 * @param initializer the expression in initializer
37 * @param operator the operator of assignation
38 * @param sourceStart the sourceStart
39 * @param sourceEnd the sourceEnd
41 public VarAssignation(final Expression variableName,
42 final Expression initializer,
44 final int sourceStart,
45 final int sourceEnd) {
46 super(sourceStart, sourceEnd);
47 this.variableName = variableName;
48 this.initializer = initializer;
49 this.operator = operator;
53 * Return the operator as String.
54 * @return the operator
56 public final String operatorToString() {
59 return "="; //$NON-NLS-1$
61 return "+="; //$NON-NLS-1$
63 return "-="; //$NON-NLS-1$
65 return "*="; //$NON-NLS-1$
67 return "/="; //$NON-NLS-1$
69 return "<="; //$NON-NLS-1$
71 return "|=";//$NON-NLS-1$
73 return "^=";//$NON-NLS-1$
75 return ".="; //$NON-NLS-1$
77 return "%="; //$NON-NLS-1$
79 return "~="; //$NON-NLS-1$
81 return "<<="; //$NON-NLS-1$
82 case RSIGNEDSHIFT_EQUAL:
83 return ">>="; //$NON-NLS-1$
85 return " unknown operator ";//$NON-NLS-1$
89 * Return the expression as String.
90 * @return the expression
92 public String toStringExpression() {
93 final String varName = variableName.toStringExpression();
94 final String init = initializer.toStringExpression();
95 final String operatorString = operatorToString();
96 final StringBuffer buff = new StringBuffer(varName.length() + operatorString.length() + init.length() + 2);
98 buff.append(" ");//$NON-NLS-1$
99 buff.append(operatorString);
100 buff.append(" ");//$NON-NLS-1$
102 return buff.toString();
107 * Get the variables from outside (parameters, globals ...)
109 public void getOutsideVariable(final List list) {
113 * get the modified variables.
115 public void getModifiedVariable(final List list) {
116 variableName.getUsedVariable(list);
117 initializer.getModifiedVariable(list);
121 * Get the variables used.
123 public void getUsedVariable(final List list) {
124 initializer.getUsedVariable(list);