1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
4 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
5 import org.eclipse.jface.resource.ImageDescriptor;
6 import org.eclipse.jface.text.Position;
9 * A variable declaration.
10 * @author Matthieu Casanova
12 public class VariableDeclaration extends AbstractVariableDeclaration implements Outlineable {
14 /** The value for variable initialization. */
15 public Expression initialization;
17 private Object parent;
18 private boolean reference;
19 private Position position;
22 * @param initialization the initialization
23 * @param name the name of the variable
24 * @param sourceStart the start point
26 public VariableDeclaration(Object parent,
28 Expression initialization,
30 super(name, sourceStart, initialization.sourceEnd);
31 this.initialization = initialization;
33 position = new Position(sourceStart, sourceEnd);
38 * @param name the name of the variable
39 * @param sourceStart the start point
41 public VariableDeclaration(Object parent,
45 super(name, sourceStart, sourceEnd);
49 public void setReference(boolean reference) {
50 this.reference = reference;
55 * @param initialization the initialization
56 * @param name the name of the variable
57 * @param sourceStart the start point
59 public VariableDeclaration(char[] name,
60 Expression initialization,
62 super(name, sourceStart, initialization.sourceEnd);
63 this.initialization = initialization;
68 * @param name the name of the variable
69 * @param sourceStart the start point
71 public VariableDeclaration(char[] name,
73 super(name, sourceStart, sourceStart + name.length);
77 * Return the variable into String.
80 public String toStringExpression() {
81 final StringBuffer buff;
83 buff = new StringBuffer("&$"); //$NON-NLS-1$
85 buff = new StringBuffer("$");//$NON-NLS-1$
88 if (initialization != null) {
89 buff.append(" = "); //$NON-NLS-1$
90 buff.append(initialization.toStringExpression());
92 return buff.toString();
95 public Object getParent() {
99 public String toString() {
100 return toStringExpression();
104 * Get the image of a variable.
105 * @return the image that represents a php variable
107 public ImageDescriptor getImage() {
108 return PHPUiImages.DESC_VAR;
111 public Position getPosition() {