1 package net.sourceforge.phpdt.internal.compiler.ast;
5 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
6 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
7 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.jface.resource.ImageDescriptor;
11 import org.eclipse.jface.text.Position;
13 import test.PHPParserSuperclass;
16 * A GlobalStatement statement in php.
17 * @author Matthieu Casanova
19 public class GlobalStatement extends Statement implements Outlineable {
21 /** An array of the variables called by this global statement. */
22 public AbstractVariable[] variables;
24 private Object parent;
26 private Position position;
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;
35 position = new Position(sourceStart, sourceEnd);
38 public String toString() {
39 final StringBuffer buff = new StringBuffer("global ");//$NON-NLS-1$
40 for (int i = 0; i < variables.length; i++) {
42 buff.append(", ");//$NON-NLS-1$
44 buff.append(variables[i].toStringExpression());
46 return buff.toString();
49 public String toString(final int tab) {
50 return tabString(tab) + toString();
54 * This will return the image for the outline of the object.
57 public ImageDescriptor getImage() {
58 return PHPUiImages.DESC_INC;
61 public Object getParent() {
65 public Position getPosition() {
70 * Get the variables from outside (parameters, globals ...)
72 public void getOutsideVariable(final List list) {
73 for (int i = 0; i < variables.length; i++) {
74 variables[i].getUsedVariable(list);
79 * get the modified variables.
81 public void getModifiedVariable(final List list) {
85 * Get the variables used.
87 public void getUsedVariable(final List list) {
91 * We will analyse the code.
92 * if we have in globals a special variable it will be reported as a warning.
93 * @see Variable#SPECIAL_VARS
95 public void analyzeCode() {
96 for (int i = 0; i < variables.length; i++) {
97 if (arrayContains(Variable.SPECIAL_VARS, variables[i].getName())) {
99 PHPParserSuperclass.setMarker("warning, you shouldn't request " + variables[i].getName() + " as global",
100 variables[i].sourceStart,
101 variables[i].sourceEnd,
102 PHPParserSuperclass.WARNING,
104 } catch (CoreException e) {
105 PHPeclipsePlugin.log(e);