1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
4 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
5 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
6 import org.eclipse.jface.resource.ImageDescriptor;
7 import org.eclipse.jface.text.Position;
8 import org.eclipse.core.runtime.CoreException;
10 import java.util.List;
11 import java.util.ArrayList;
12 import java.util.Arrays;
14 import test.PHPParserSuperclass;
17 * A GlobalStatement statement in php.
18 * @author Matthieu Casanova
20 public class GlobalStatement extends Statement implements Outlineable {
22 /** An array of the variables called by this global statement. */
23 public AbstractVariable[] variables;
25 private Object parent;
27 private Position position;
29 public GlobalStatement(final Object parent,
30 final AbstractVariable[] variables,
31 final int sourceStart,
32 final int sourceEnd) {
33 super(sourceStart, sourceEnd);
34 this.variables = variables;
36 position = new Position(sourceStart, sourceEnd);
39 public String toString() {
40 final StringBuffer buff = new StringBuffer("global ");//$NON-NLS-1$
41 for (int i = 0; i < variables.length; i++) {
43 buff.append(", ");//$NON-NLS-1$
45 buff.append(variables[i].toStringExpression());
47 return buff.toString();
50 public String toString(final int tab) {
51 return tabString(tab) + toString();
55 * This will return the image for the outline of the object.
58 public ImageDescriptor getImage() {
59 return PHPUiImages.DESC_INC;
62 public Object getParent() {
66 public Position getPosition() {
71 * Get the variables from outside (parameters, globals ...)
73 public void getOutsideVariable(final List list) {
74 for (int i = 0; i < variables.length; i++) {
75 variables[i].getUsedVariable(list);
80 * get the modified variables.
82 public void getModifiedVariable(final List list) {
86 * Get the variables used.
88 public void getUsedVariable(final List list) {
92 * We will analyse the code.
93 * if we have in globals a special variable it will be reported as a warning.
94 * @see Variable#SPECIAL_VARS
96 public void analyzeCode() {
97 for (int i = 0; i < variables.length; i++) {
98 if (arrayContains(Variable.SPECIAL_VARS, variables[i].getName())) {
100 PHPParserSuperclass.setMarker("warning, you shouldn't request " + variables[i].getName() + " as global",
101 variables[i].sourceStart,
102 variables[i].sourceEnd,
103 PHPParserSuperclass.WARNING,
105 } catch (CoreException e) {
106 PHPeclipsePlugin.log(e);