*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / InclusionStatement.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 import java.util.List;
9 import java.util.ArrayList;
10
11 /**
12  * @author Matthieu Casanova
13  */
14 public class InclusionStatement extends Statement implements Outlineable {
15
16   public static final int INCLUDE = 0;
17   public static final int INCLUDE_ONCE = 1;
18   public static final int REQUIRE = 2;
19   public static final int REQUIRE_ONCE = 3;
20   public boolean silent;
21   /** The kind of include. */
22   public int keyword;
23   public Expression expression;
24
25   private Object parent;
26
27   private Position position;
28
29   public InclusionStatement(final Object parent,
30                             final int keyword,
31                             final Expression expression,
32                             final int sourceStart) {
33     super(sourceStart, expression.getSourceEnd());
34     this.keyword = keyword;
35     this.expression = expression;
36     this.parent = parent;
37     position = new Position(sourceStart, getSourceEnd());
38   }
39
40   public String keywordToString() {
41     switch (keyword) {
42       case INCLUDE:
43         return "include";       //$NON-NLS-1$
44       case INCLUDE_ONCE:
45         return "include_once";  //$NON-NLS-1$
46       case REQUIRE:
47         return "require";       //$NON-NLS-1$
48       case REQUIRE_ONCE:
49         return "require_once";  //$NON-NLS-1$
50     }
51     return "unknown keyword";//$NON-NLS-1$
52   }
53
54   /**
55    * Return the object into String.
56    * @param tab how many tabs (not used here
57    * @return a String
58    */
59   public String toString(final int tab) {
60     final StringBuffer buffer = new StringBuffer(tabString(tab));
61     buffer.append(toString());
62     return buffer.toString();
63   }
64
65   public String toString() {
66     final StringBuffer buffer = new StringBuffer();
67     if (silent) {
68       buffer.append('@');
69     }
70     buffer.append(keywordToString());
71     buffer.append(" ");
72     buffer.append(expression.toStringExpression());
73     return buffer.toString();
74   }
75
76   /**
77    * Get the image of a variable.
78    * @return the image that represents a php variable
79    */
80   public ImageDescriptor getImage() {
81     return PHPUiImages.DESC_INC;
82   }
83
84   public Object getParent() {
85     return parent;
86   }
87
88   public Position getPosition() {
89     return position;
90   }
91
92   /**
93    * Get the variables from outside (parameters, globals ...)
94    * @return the variables from outside
95    */
96   public List getOutsideVariable() {
97     return expression.getOutsideVariable();
98   }
99
100   /**
101    * get the modified variables.
102    * @return the variables from we change value
103    */
104   public List getModifiedVariable() {
105     return expression.getModifiedVariable();
106   }
107
108   /**
109    * Get the variables used.
110    * @return the variables used
111    */
112   public List getUsedVariable() {
113     return expression.getUsedVariable();
114   }
115 }