* @param initialization the initialization
* @param sourceStart the start point
*/
- public ArgumentDeclaration(final char[] name,
+ public ArgumentDeclaration(final Variable name,
final boolean reference,
final Expression initialization,
final int sourceStart) {
* @param reference the variable is a reference ?
* @param sourceStart the start point
*/
- public ArgumentDeclaration(final char[] name,
+ public ArgumentDeclaration(final Variable name,
final boolean reference,
final int sourceStart) {
super(name, sourceStart);
public String toStringExpression() {
final StringBuffer buff;
if (reference) {
- buff = new StringBuffer("&$");
+ buff = new StringBuffer("&");
} else {
- buff = new StringBuffer("$");
+ buff = new StringBuffer();
}
- buff.append(name);
+ buff.append(variable.toStringExpression());
if (initialization != null) {
buff.append(" = ");
buff.append(initialization.toStringExpression());
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Matthieu Casanova
+ */
+public class Variable extends Expression {
+
+ /** The name of the variable. */
+ public char[] name;
+
+
+ public Variable(final char[] name, final int sourceStart, final int sourceEnd) {
+ super(sourceStart, sourceEnd);
+ this.name = name;
+ }
+
+ /**
+ * Return the expression as String.
+ * @return the expression
+ */
+ public String toStringExpression() {
+ return "$"+new String(name);
+ }
+
+ public String getName() {
+ return new String(name);
+ }
+
+ /**
+ * Get the variables from outside (parameters, globals ...)
+ * @return the variables from outside
+ */
+ public List getOutsideVariable() {
+ return new ArrayList(1);
+ }
+
+ /**
+ * get the modified variables.
+ * @return the variables modified
+ */
+ public List getModifiedVariable() {
+ final ArrayList list = new ArrayList(1);
+ list.add(new VariableUsage(getName(),sourceStart));
+ return list;
+ }
+
+ /**
+ * Get the variables used.
+ * @return the variables used
+ */
+ public List getUsedVariable() {
+ return new ArrayList(1);
+ }
+}
* A variable declaration.
* @author Matthieu Casanova
*/
-public class VariableDeclaration extends AbstractVariableDeclaration implements Outlineable {
+public class VariableDeclaration extends Expression implements Outlineable {
public static final int EQUAL = 0;
public static final int PLUS_EQUAL = 1;
public static final int LSHIFT_EQUAL = 11;
public static final int RSIGNEDSHIFT_EQUAL = 12;
+ protected Variable variable;
/** The value for variable initialization. */
public Expression initialization;
private Position position;
private int operator;
+
/**
* Create a variable.
* @param initialization the initialization
- * @param name the name of the variable
+ * @param variable the name of the variable
* @param sourceStart the start point
*/
public VariableDeclaration(final Object parent,
- final char[] name,
+ final Variable variable,
final Expression initialization,
final int operator,
final int sourceStart) {
- super(name, sourceStart, initialization.sourceEnd);
+ super(sourceStart, initialization.sourceEnd);
this.initialization = initialization;
+ this.variable = variable;
this.operator = operator;
this.parent = parent;
position = new Position(sourceStart, sourceEnd);
* @param sourceStart the start point
*/
public VariableDeclaration(final Object parent,
- final char[] name,
+ final Variable variable,
final int sourceStart,
final int sourceEnd) {
- super(name, sourceStart, sourceEnd);
+ super(sourceStart, sourceEnd);
+ this.variable = variable;
this.parent = parent;
}
* @param name the name of the variable
* @param sourceStart the start point
*/
- public VariableDeclaration(final char[] name,
+ public VariableDeclaration(final Variable variable,
final Expression initialization,
final int operator,
final int sourceStart) {
- super(name, sourceStart, initialization.sourceEnd);
+ super(sourceStart, initialization.sourceEnd);
+ this.variable = variable;
this.initialization = initialization;
this.operator = operator;
}
* @param name the name of the variable
* @param sourceStart the start point
*/
- public VariableDeclaration(final char[] name,
+ public VariableDeclaration(final Variable variable,
final int sourceStart) {
- super(name, sourceStart, sourceStart + name.length);
+ super(sourceStart, variable.sourceEnd);
+ this.variable = variable;
}
- /**
+ /**
* Return the operator as String.
* @return the operator
*/
public String toStringExpression() {
final StringBuffer buff;
if (reference) {
- buff = new StringBuffer("&$"); //$NON-NLS-1$
+ buff = new StringBuffer("&"); //$NON-NLS-1$
} else {
- buff = new StringBuffer("$");//$NON-NLS-1$
+ buff = new StringBuffer();//$NON-NLS-1$
}
- buff.append(name);
+ buff.append(variable.toStringExpression());
if (initialization != null) {
buff.append(operatorToString()); //$NON-NLS-1$
buff.append(initialization.toStringExpression());
* @return the name of the String
*/
public String name() {
- return new String(name);
+ return variable.getName();
}
/**
*/
public List getModifiedVariable() {
final ArrayList list = new ArrayList();
- list.add(new VariableUsage(new String(name), sourceStart));
+ list.addAll(variable.getModifiedVariable());
if (initialization != null) {
list.addAll(initialization.getModifiedVariable());
}