Changes:
[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 class GlobalStatement extends Statement implements Outlineable {
20
21   /** An array of the variables called by this global statement. */
22   public AbstractVariable[] variables;
23
24   private Object parent;
25
26   private 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   public void getOutsideVariable(final List list) {
73     for (int i = 0; i < variables.length; i++) {
74       variables[i].getUsedVariable(list);
75     }
76   }
77
78   /**
79    * get the modified variables.
80    */
81   public void getModifiedVariable(final List list) {
82   }
83
84   /**
85    * Get the variables used.
86    */
87   public void getUsedVariable(final List list) {
88   }
89
90   /**
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
94    */
95   public void analyzeCode() {
96     for (int i = 0; i < variables.length; i++) {
97       if (arrayContains(Variable.SPECIAL_VARS, variables[i].getName())) {
98         try {
99           PHPParserSuperclass.setMarker("warning, you shouldn't request " + variables[i].getName() + " as global",
100                                         variables[i].sourceStart,
101                                         variables[i].sourceEnd,
102                                         PHPParserSuperclass.WARNING,
103                                         "");
104         } catch (CoreException e) {
105           PHPeclipsePlugin.log(e);
106         }
107       }
108     }
109   }
110 }