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