Changes:
[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 java.util.List;
4
5 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
6 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
7
8 import org.eclipse.jface.resource.ImageDescriptor;
9 import org.eclipse.jface.text.Position;
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                             final int sourceEnd) {
34     super(sourceStart, sourceEnd);
35     this.keyword = keyword;
36     this.expression = expression;
37     this.parent = parent;
38     position = new Position(sourceStart, sourceEnd);
39   }
40
41   public String keywordToString() {
42     switch (keyword) {
43       case INCLUDE:
44         return "include";       //$NON-NLS-1$
45       case INCLUDE_ONCE:
46         return "include_once";  //$NON-NLS-1$
47       case REQUIRE:
48         return "require";       //$NON-NLS-1$
49       case REQUIRE_ONCE:
50         return "require_once";  //$NON-NLS-1$
51     }
52     return "unknown keyword";//$NON-NLS-1$
53   }
54
55   /**
56    * Return the object into String.
57    * @param tab how many tabs (not used here
58    * @return a String
59    */
60   public String toString(final int tab) {
61     final StringBuffer buffer = new StringBuffer(tabString(tab));
62     buffer.append(toString());
63     return buffer.toString();
64   }
65
66   public String toString() {
67     final StringBuffer buffer = new StringBuffer();
68     if (silent) {
69       buffer.append('@');
70     }
71     buffer.append(keywordToString());
72     buffer.append(" ");
73     buffer.append(expression.toStringExpression());
74     return buffer.toString();
75   }
76
77   /**
78    * Get the image of a variable.
79    * @return the image that represents a php variable
80    */
81   public ImageDescriptor getImage() {
82     return PHPUiImages.DESC_INC;
83   }
84
85   public Object getParent() {
86     return parent;
87   }
88
89   public Position getPosition() {
90     return position;
91   }
92
93   /**
94    * Get the variables from outside (parameters, globals ...)
95    */
96   public void getOutsideVariable(final List list) {
97     expression.getOutsideVariable(list);
98   }
99
100   /**
101    * get the modified variables.
102    */
103   public void getModifiedVariable(final List list) {
104     expression.getModifiedVariable(list);
105   }
106
107   /**
108    * Get the variables used.
109    */
110   public void getUsedVariable(final List list) {
111     expression.getUsedVariable(list);
112   }
113 }