added a first php $f command to the PHP console
[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   /**
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('&');
84     } else {
85       buff = new StringBuffer();
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 }