be8e479a9f869d4c39a36bd51438248a18a1eb4c
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / phpparser / PHPVarDeclaration.java
1 package net.sourceforge.phpeclipse.phpeditor.phpparser;
2
3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
4 import org.eclipse.jface.resource.ImageDescriptor;
5
6 /**
7  * A php variable declaration strongly inspired by the PHPFunctionDeclaration of Khartlage (:.
8  * @author khartlage, Matthieu Casanova
9  */
10 public class PHPVarDeclaration extends PHPSegment {
11
12   /** The value of the variable. */
13   private String value;
14     /**
15      * Create a php variable declaration.
16      * @param parent the parent object (it should be a php class)
17      * @param name the name of the variable
18      * @param index where the variable is in the file
19      * @param value the value
20      */
21     public PHPVarDeclaration(Object parent, String name, int index, String value) {
22       super(parent, name, index);
23       this.value = value;
24     }
25
26   /**
27    * Create a php variable declaration.
28    * @param parent the parent object (it should be a php class)
29    * @param name the name of the variable
30    * @param index where the variable is in the file
31    */
32   public PHPVarDeclaration(Object parent, String name, int index) {
33       this(parent, name, index,null);
34   }
35
36     /**
37      * Get the image of a variable.
38      * @return the image that represents a php variable
39      */
40     public ImageDescriptor getImage() {
41         return PHPUiImages.DESC_VAR;
42     }
43
44   public String toString() {
45     if (value == null || value.equals("")) {
46       return super.toString();
47     } else {
48       return name + " = " + value;
49     }
50   }
51 }