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 final class GlobalStatement extends Statement implements Outlineable {
21 /** An array of the variables called by this global statement. */
22 private final AbstractVariable[] variables;
24 private final Object parent;
26 private final 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 * @param list the list where we will put variables
74 public void getOutsideVariable(final List list) {
75 for (int i = 0; i < variables.length; i++) {
76 variables[i].getUsedVariable(list);
81 * get the modified variables.
83 * @param list the list where we will put variables
85 public void getModifiedVariable(final List list) {}
88 * Get the variables used.
90 * @param list the list where we will put variables
92 public void getUsedVariable(final List list) {}
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
99 public void analyzeCode() {
100 for (int i = 0; i < variables.length; i++) {
101 if (arrayContains(Variable.SPECIAL_VARS, variables[i].getName())) {
103 PHPParserSuperclass.setMarker("warning, you shouldn't request " + variables[i].getName() + " as global",
104 variables[i].sourceStart,
105 variables[i].sourceEnd,
106 PHPParserSuperclass.WARNING,
108 } catch (CoreException e) {
109 PHPeclipsePlugin.log(e);