3.x RC1 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / GlobalStatement.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 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
8
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.jface.resource.ImageDescriptor;
11 import org.eclipse.jface.text.Position;
12
13 import test.PHPParserSuperclass;
14
15 /**
16  * A GlobalStatement statement in php.
17  * @author Matthieu Casanova
18  */
19 public final class GlobalStatement extends Statement implements Outlineable {
20
21   /** An array of the variables called by this global statement. */
22   private final AbstractVariable[] variables;
23
24   private final Object parent;
25
26   private final Position position;
27
28   public GlobalStatement(final Object parent,
29                          final AbstractVariable[] variables,
30                          final int sourceStart,
31                          final int sourceEnd) {
32     super(sourceStart, sourceEnd);
33     this.variables = variables;
34     this.parent = parent;
35     position = new Position(sourceStart, sourceEnd);
36   }
37
38   public String toString() {
39     final StringBuffer buff = new StringBuffer("global ");//$NON-NLS-1$
40     for (int i = 0; i < variables.length; i++) {
41       if (i != 0) {
42         buff.append(", ");//$NON-NLS-1$
43       }
44       buff.append(variables[i].toStringExpression());
45     }
46     return buff.toString();
47   }
48
49   public String toString(final int tab) {
50     return tabString(tab) + toString();
51   }
52
53   /**
54    * This will return the image for the outline of the object.
55    * @return an image
56    */
57   public ImageDescriptor getImage() {
58     return PHPUiImages.DESC_INC;
59   }
60
61   public Object getParent() {
62     return parent;
63   }
64
65   public Position getPosition() {
66     return position;
67   }
68
69   /**
70    * Get the variables from outside (parameters, globals ...)
71    *
72    * @param list the list where we will put variables
73    */
74   public void getOutsideVariable(final List list) {
75     for (int i = 0; i < variables.length; i++) {
76       variables[i].getUsedVariable(list);
77     }
78   }
79
80   /**
81    * get the modified variables.
82    *
83    * @param list the list where we will put variables
84    */
85   public void getModifiedVariable(final List list) {}
86
87   /**
88    * Get the variables used.
89    *
90    * @param list the list where we will put variables
91    */
92   public void getUsedVariable(final List list) {}
93
94   /**
95    * We will analyse the code.
96    * if we have in globals a special variable it will be reported as a warning.
97    * @see Variable#SPECIAL_VARS
98    */
99   public void analyzeCode() {
100     for (int i = 0; i < variables.length; i++) {
101       if (arrayContains(Variable.SPECIAL_VARS, variables[i].getName())) {
102         try {
103           PHPParserSuperclass.setMarker("warning, you shouldn't request " + variables[i].getName() + " as global",
104                                         variables[i].sourceStart,
105                                         variables[i].sourceEnd,
106                                         PHPParserSuperclass.WARNING,
107                                         "");
108         } catch (CoreException e) {
109           PHPeclipsePlugin.log(e);
110         }
111       }
112     }
113   }
114 }