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 ...)
72 * @return the variables from outside
74 public List getOutsideVariable() {
75 final ArrayList list = new ArrayList(variables.length);
76 for (int i = 0; i < variables.length; i++) {
77 list.addAll(variables[i].getUsedVariable());
83 * get the modified variables.
84 * @return the variables modified
86 public List getModifiedVariable() {
87 return new ArrayList(1);
91 * Get the variables used.
92 * @return the variables used
94 public List getUsedVariable() {
95 return new ArrayList(1);
99 * We will analyse the code.
100 * if we have in globals a special variable it will be reported as a warning.
101 * @see Variable#SPECIAL_VARS
103 public void analyzeCode() {
104 for (int i = 0; i < variables.length; i++) {
105 if (arrayContains(Variable.SPECIAL_VARS, variables[i].getName())) {
107 PHPParserSuperclass.setMarker("warning, you shouldn't request " + variables[i].getName() + " as global",
108 variables[i].sourceStart,
109 variables[i].sourceEnd,
110 PHPParserSuperclass.WARNING,
112 } catch (CoreException e) {
113 PHPeclipsePlugin.log(e);