First try for AST structure. A lot of things to change
[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.ast.Expression;
4 import net.sourceforge.phpdt.internal.compiler.ast.AbstractVariableDeclaration;
5 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
6 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
7 import org.eclipse.jface.resource.ImageDescriptor;
8
9 /**
10  * A variable declaration.
11  * @author Matthieu Casanova
12  */
13 public class VariableDeclaration extends AbstractVariableDeclaration implements Outlineable {
14
15   /** The value for variable initialization. */
16   public Expression initialization;
17
18   private Object parent;
19   private boolean reference;
20
21   /**
22    * Create a variable.
23    * @param initialization the initialization
24    * @param name the name of the variable
25    * @param sourceStart the start point
26    */
27   public VariableDeclaration(Object parent,
28                              char[] name,
29                              Expression initialization,
30                              int sourceStart) {
31     super(name, sourceStart, initialization.sourceEnd);
32     this.initialization = initialization;
33     this.parent = parent;
34   }
35
36   public void setReference(boolean reference) {
37     this.reference = reference;
38   }
39
40   /**
41    * Create a variable.
42    * @param initialization the initialization
43    * @param name the name of the variable
44    * @param sourceStart the start point
45    */
46   public VariableDeclaration(char[] name,
47                              Expression initialization,
48                              int sourceStart) {
49     super(name, sourceStart, initialization.sourceEnd);
50     this.initialization = initialization;
51   }
52   /**
53    * Return the variable into String.
54    * @return a String
55    */
56   public String toStringExpression() {
57     final StringBuffer buff;
58     if (reference) {
59       buff = new StringBuffer('&');
60     } else {
61       buff = new StringBuffer();
62     }
63     buff.append(name);
64     if (initialization != null) {
65       buff.append(" = "); //$NON-NLS-1$
66       buff.append(initialization.toStringExpression());
67     }
68     return buff.toString();
69   }
70
71   public Object getParent() {
72     return parent;
73   }
74
75     /**
76      * Get the image of a variable.
77      * @return the image that represents a php variable
78      */
79     public ImageDescriptor getImage() {
80         return PHPUiImages.DESC_VAR;
81     }
82 }