1 package net.sourceforge.phpdt.internal.compiler.ast;
6 * A Variable assignation.
7 * $varname = initializer
8 * @author Matthieu Casanova
10 public final class VarAssignation extends Expression {
12 public static final int EQUAL = 0;
13 public static final int PLUS_EQUAL = 1;
14 public static final int MINUS_EQUAL = 2;
15 public static final int STAR_EQUAL = 3;
16 public static final int SLASH_EQUAL = 4;
17 public static final int AND_EQUAL = 5;
18 public static final int OR_EQUAL = 6;
19 public static final int XOR_EQUAL = 7;
20 public static final int DOT_EQUAL = 8;
21 public static final int REM_EQUAL = 9;
22 public static final int TILDE_EQUAL = 10;
23 public static final int LSHIFT_EQUAL = 11;
24 public static final int RSIGNEDSHIFT_EQUAL = 12;
26 public final Expression variableName;
27 public final Expression initializer;
28 public final int operator;
31 * Create a new variable assignation.
32 * @param variableName the name of the variable
33 * @param initializer the expression in initializer
34 * @param operator the operator of assignation
35 * @param sourceStart the sourceStart
36 * @param sourceEnd the sourceEnd
38 public VarAssignation(final Expression variableName,
39 final Expression initializer,
41 final int sourceStart,
42 final int sourceEnd) {
43 super(sourceStart, sourceEnd);
44 this.variableName = variableName;
45 this.initializer = initializer;
46 this.operator = operator;
50 * Return the operator as String.
51 * @return the operator
53 public String operatorToString() {
56 return "="; //$NON-NLS-1$
58 return "+="; //$NON-NLS-1$
60 return "-="; //$NON-NLS-1$
62 return "*="; //$NON-NLS-1$
64 return "/="; //$NON-NLS-1$
66 return "<="; //$NON-NLS-1$
68 return "|=";//$NON-NLS-1$
70 return "^=";//$NON-NLS-1$
72 return ".="; //$NON-NLS-1$
74 return "%="; //$NON-NLS-1$
76 return "~="; //$NON-NLS-1$
78 return "<<="; //$NON-NLS-1$
79 case RSIGNEDSHIFT_EQUAL:
80 return ">>="; //$NON-NLS-1$
82 return " unknown operator ";//$NON-NLS-1$
86 * Return the expression as String.
87 * @return the expression
89 public String toStringExpression() {
90 final String varName = variableName.toStringExpression();
91 final String init = initializer.toStringExpression();
92 final String operatorString = operatorToString();
93 final StringBuffer buff = new StringBuffer(varName.length() + operatorString.length() + init.length() + 2);
95 buff.append(" ");//$NON-NLS-1$
96 buff.append(operatorString);
97 buff.append(" ");//$NON-NLS-1$
99 return buff.toString();
104 * Get the variables from outside (parameters, globals ...)
106 public void getOutsideVariable(final List list) {
110 * get the modified variables.
112 public void getModifiedVariable(final List list) {
113 variableName.getUsedVariable(list);
114 initializer.getModifiedVariable(list);
118 * Get the variables used.
120 public void getUsedVariable(final List list) {
121 initializer.getUsedVariable(list);