X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java index 6bb61fe..3e97fb4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java @@ -1,24 +1,34 @@ package net.sourceforge.phpdt.internal.compiler.ast; +import java.util.List; + import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; + +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.Position; +import test.PHPParserSuperclass; + /** * A GlobalStatement statement in php. * @author Matthieu Casanova */ -public class GlobalStatement extends Statement implements Outlineable { +public final class GlobalStatement extends Statement implements Outlineable { /** An array of the variables called by this global statement. */ - public String[] variables; + private final AbstractVariable[] variables; - private Object parent; + private final Object parent; - private Position position; + private final Position position; - public GlobalStatement(Object parent, String[] variables, int sourceStart, int sourceEnd) { + public GlobalStatement(final Object parent, + final AbstractVariable[] variables, + final int sourceStart, + final int sourceEnd) { super(sourceStart, sourceEnd); this.variables = variables; this.parent = parent; @@ -26,17 +36,17 @@ public class GlobalStatement extends Statement implements Outlineable { } public String toString() { - StringBuffer buff = new StringBuffer("global "); + final StringBuffer buff = new StringBuffer("global ");//$NON-NLS-1$ for (int i = 0; i < variables.length; i++) { if (i != 0) { - buff.append(", "); + buff.append(", ");//$NON-NLS-1$ } - buff.append(variables[i]); + buff.append(variables[i].toStringExpression()); } return buff.toString(); } - public String toString(int tab) { + public String toString(final int tab) { return tabString(tab) + toString(); } @@ -55,4 +65,50 @@ public class GlobalStatement extends Statement implements Outlineable { public Position getPosition() { return position; } + + /** + * Get the variables from outside (parameters, globals ...) + * + * @param list the list where we will put variables + */ + public void getOutsideVariable(final List list) { + for (int i = 0; i < variables.length; i++) { + variables[i].getUsedVariable(list); + } + } + + /** + * get the modified variables. + * + * @param list the list where we will put variables + */ + public void getModifiedVariable(final List list) {} + + /** + * Get the variables used. + * + * @param list the list where we will put variables + */ + public void getUsedVariable(final List list) {} + + /** + * We will analyse the code. + * if we have in globals a special variable it will be reported as a warning. + * @see Variable#SPECIAL_VARS + */ + public void analyzeCode() { + for (int i = 0; i < variables.length; i++) { + if (arrayContains(Variable.SPECIAL_VARS, variables[i].getName())) { + try { + PHPParserSuperclass.setMarker("warning, you shouldn't request " + variables[i].getName() + " as global", + variables[i].sourceStart, + variables[i].sourceEnd, + PHPParserSuperclass.WARNING, + ""); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + } + } + } + } }