*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / VariableDeclaration.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
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
7 /**
8  * A variable declaration.
9  * @author Matthieu Casanova
10  */
11 public class VariableDeclaration extends AbstractVariableDeclaration implements Outlineable {
12
13   /** The value for variable initialization. */
14   public Expression initialization;
15
16   private Object parent;
17   private boolean reference;
18
19   /**
20    * Create a variable.
21    * @param initialization the initialization
22    * @param name the name of the variable
23    * @param sourceStart the start point
24    */
25   public VariableDeclaration(Object parent,
26                              char[] name,
27                              Expression initialization,
28                              int sourceStart) {
29     super(name, sourceStart, initialization.sourceEnd);
30     this.initialization = initialization;
31     this.parent = parent;
32   }
33
34   /**
35    * Create a variable.
36    * @param name the name of the variable
37    * @param sourceStart the start point
38    */
39   public VariableDeclaration(Object parent,
40                              char[] name,
41                              int sourceStart,
42                              int sourceEnd) {
43     super(name, sourceStart, sourceEnd);
44     this.parent = parent;
45   }
46
47   public void setReference(boolean reference) {
48     this.reference = reference;
49   }
50
51   /**
52    * Create a variable.
53    * @param initialization the initialization
54    * @param name the name of the variable
55    * @param sourceStart the start point
56    */
57   public VariableDeclaration(char[] name,
58                              Expression initialization,
59                              int sourceStart) {
60     super(name, sourceStart, initialization.sourceEnd);
61     this.initialization = initialization;
62   }
63
64   /**
65    * Create a variable.
66    * @param name the name of the variable
67    * @param sourceStart the start point
68    */
69   public VariableDeclaration(char[] name,
70                              int sourceStart) {
71     super(name, sourceStart, sourceStart + name.length);
72   }
73
74   /**
75    * Return the variable into String.
76    * @return a String
77    */
78   public String toStringExpression() {
79     final StringBuffer buff;
80     if (reference) {
81       buff = new StringBuffer("&$"); //$NON-NLS-1$
82     } else {
83       buff = new StringBuffer("$");//$NON-NLS-1$
84     }
85     buff.append(name);
86     if (initialization != null) {
87       buff.append(" = "); //$NON-NLS-1$
88       buff.append(initialization.toStringExpression());
89     }
90     return buff.toString();
91   }
92
93   public Object getParent() {
94     return parent;
95   }
96
97     /**
98      * Get the image of a variable.
99      * @return the image that represents a php variable
100      */
101     public ImageDescriptor getImage() {
102         return PHPUiImages.DESC_VAR;
103     }
104 }