package net.sourceforge.phpdt.internal.compiler.ast; import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; import net.sourceforge.phpdt.internal.ui.PHPUiImages; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.Position; /** * A variable declaration. * @author Matthieu Casanova */ public class VariableDeclaration extends AbstractVariableDeclaration implements Outlineable { /** The value for variable initialization. */ public Expression initialization; private Object parent; private boolean reference; private Position position; /** * Create a variable. * @param initialization the initialization * @param name the name of the variable * @param sourceStart the start point */ public VariableDeclaration(Object parent, char[] name, Expression initialization, int sourceStart) { super(name, sourceStart, initialization.sourceEnd); this.initialization = initialization; this.parent = parent; position = new Position(sourceStart, sourceEnd); } /** * Create a variable. * @param name the name of the variable * @param sourceStart the start point */ public VariableDeclaration(Object parent, char[] name, int sourceStart, int sourceEnd) { super(name, sourceStart, sourceEnd); this.parent = parent; } public void setReference(boolean reference) { this.reference = reference; } /** * Create a variable. * @param initialization the initialization * @param name the name of the variable * @param sourceStart the start point */ public VariableDeclaration(char[] name, Expression initialization, int sourceStart) { super(name, sourceStart, initialization.sourceEnd); this.initialization = initialization; } /** * Create a variable. * @param name the name of the variable * @param sourceStart the start point */ public VariableDeclaration(char[] name, int sourceStart) { super(name, sourceStart, sourceStart + name.length); } /** * Return the variable into String. * @return a String */ public String toStringExpression() { final StringBuffer buff; if (reference) { buff = new StringBuffer("&$"); //$NON-NLS-1$ } else { buff = new StringBuffer("$");//$NON-NLS-1$ } buff.append(name); if (initialization != null) { buff.append(" = "); //$NON-NLS-1$ buff.append(initialization.toStringExpression()); } return buff.toString(); } public Object getParent() { return parent; } public String toString() { return toStringExpression(); } /** * Get the image of a variable. * @return the image that represents a php variable */ public ImageDescriptor getImage() { return PHPUiImages.DESC_VAR; } public Position getPosition() { return position; } }