37d99c1824ff8d3d6ad04909f53a63465d29c44a
[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 final 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   private final int keyword;
23   private final Expression expression;
24
25   private final Object parent;
26
27   private final 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   private 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 String keyword = keywordToString();
68     final String expressionString = expression.toStringExpression();
69     final StringBuffer buffer = new StringBuffer(keyword.length() +
70                                                  expressionString.length() + 2);
71     if (silent) {
72       buffer.append('@');
73     }
74     buffer.append(keyword);
75     buffer.append(' ');
76     buffer.append(expressionString);
77     return buffer.toString();
78   }
79
80   /**
81    * Get the image of a variable.
82    * @return the image that represents a php variable
83    */
84   public ImageDescriptor getImage() {
85     return PHPUiImages.DESC_INC;
86   }
87
88   public Object getParent() {
89     return parent;
90   }
91
92   public Position getPosition() {
93     return position;
94   }
95
96   /**
97    * Get the variables from outside (parameters, globals ...)
98    *
99    * @param list the list where we will put variables
100    */
101   public void getOutsideVariable(final List list) {
102     expression.getOutsideVariable(list);
103   }
104
105   /**
106    * get the modified variables.
107    *
108    * @param list the list where we will put variables
109    */
110   public void getModifiedVariable(final List list) {
111     expression.getModifiedVariable(list);
112   }
113
114   /**
115    * Get the variables used.
116    *
117    * @param list the list where we will put variables
118    */
119   public void getUsedVariable(final List list) {
120     expression.getUsedVariable(list);
121   }
122 }