From: kpouer Date: Mon, 4 Aug 2003 22:55:08 +0000 (+0000) Subject: changes about variables X-Git-Url: http://git.phpeclipse.com?hp=2f007e2e08adc82a96b5fa1eeaa57c6956b8996f changes about variables --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java deleted file mode 100644 index cde0daf..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.sourceforge.phpdt.internal.compiler.ast; - -import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage; - -import java.util.List; -import java.util.ArrayList; - - -/** - * An abstract variable declaration. - * @author Matthieu Casanova - */ -public abstract class AbstractVariableDeclaration extends Expression { - /** The name of the variable. */ - public char[] name; - - /** - * Create a node giving starting and ending offset - * @param sourceStart starting offset - * @param sourceEnd ending offset - * @param name the name of the variable - */ - public AbstractVariableDeclaration(final char[] name, final int sourceStart, final int sourceEnd) { - super(sourceStart, sourceEnd); - this.name = name; - } - - -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java index be35c1d..e2fa5f4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java @@ -17,7 +17,7 @@ public class ArgumentDeclaration extends VariableDeclaration { * @param initialization the initialization * @param sourceStart the start point */ - public ArgumentDeclaration(final char[] name, + public ArgumentDeclaration(final Variable name, final boolean reference, final Expression initialization, final int sourceStart) { @@ -31,7 +31,7 @@ public class ArgumentDeclaration extends VariableDeclaration { * @param reference the variable is a reference ? * @param sourceStart the start point */ - public ArgumentDeclaration(final char[] name, + public ArgumentDeclaration(final Variable name, final boolean reference, final int sourceStart) { super(name, sourceStart); @@ -44,11 +44,11 @@ public class ArgumentDeclaration extends VariableDeclaration { public String toStringExpression() { final StringBuffer buff; if (reference) { - buff = new StringBuffer("&$"); + buff = new StringBuffer("&"); } else { - buff = new StringBuffer("$"); + buff = new StringBuffer(); } - buff.append(name); + buff.append(variable.toStringExpression()); if (initialization != null) { buff.append(" = "); buff.append(initialization.toStringExpression()); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java new file mode 100644 index 0000000..a6d027a --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Variable.java @@ -0,0 +1,59 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage; + +import java.util.List; +import java.util.ArrayList; + +/** + * @author Matthieu Casanova + */ +public class Variable extends Expression { + + /** The name of the variable. */ + public char[] name; + + + public Variable(final char[] name, final int sourceStart, final int sourceEnd) { + super(sourceStart, sourceEnd); + this.name = name; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + return "$"+new String(name); + } + + public String getName() { + return new String(name); + } + + /** + * Get the variables from outside (parameters, globals ...) + * @return the variables from outside + */ + public List getOutsideVariable() { + return new ArrayList(1); + } + + /** + * get the modified variables. + * @return the variables modified + */ + public List getModifiedVariable() { + final ArrayList list = new ArrayList(1); + list.add(new VariableUsage(getName(),sourceStart)); + return list; + } + + /** + * Get the variables used. + * @return the variables used + */ + public List getUsedVariable() { + return new ArrayList(1); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java index 9fafb2f..20a3c26 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java @@ -13,7 +13,7 @@ import java.util.ArrayList; * A variable declaration. * @author Matthieu Casanova */ -public class VariableDeclaration extends AbstractVariableDeclaration implements Outlineable { +public class VariableDeclaration extends Expression implements Outlineable { public static final int EQUAL = 0; public static final int PLUS_EQUAL = 1; @@ -29,6 +29,7 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements public static final int LSHIFT_EQUAL = 11; public static final int RSIGNEDSHIFT_EQUAL = 12; + protected Variable variable; /** The value for variable initialization. */ public Expression initialization; @@ -38,19 +39,21 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements private Position position; private int operator; + /** * Create a variable. * @param initialization the initialization - * @param name the name of the variable + * @param variable the name of the variable * @param sourceStart the start point */ public VariableDeclaration(final Object parent, - final char[] name, + final Variable variable, final Expression initialization, final int operator, final int sourceStart) { - super(name, sourceStart, initialization.sourceEnd); + super(sourceStart, initialization.sourceEnd); this.initialization = initialization; + this.variable = variable; this.operator = operator; this.parent = parent; position = new Position(sourceStart, sourceEnd); @@ -62,10 +65,11 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements * @param sourceStart the start point */ public VariableDeclaration(final Object parent, - final char[] name, + final Variable variable, final int sourceStart, final int sourceEnd) { - super(name, sourceStart, sourceEnd); + super(sourceStart, sourceEnd); + this.variable = variable; this.parent = parent; } @@ -79,11 +83,12 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements * @param name the name of the variable * @param sourceStart the start point */ - public VariableDeclaration(final char[] name, + public VariableDeclaration(final Variable variable, final Expression initialization, final int operator, final int sourceStart) { - super(name, sourceStart, initialization.sourceEnd); + super(sourceStart, initialization.sourceEnd); + this.variable = variable; this.initialization = initialization; this.operator = operator; } @@ -93,12 +98,13 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements * @param name the name of the variable * @param sourceStart the start point */ - public VariableDeclaration(final char[] name, + public VariableDeclaration(final Variable variable, final int sourceStart) { - super(name, sourceStart, sourceStart + name.length); + super(sourceStart, variable.sourceEnd); + this.variable = variable; } - /** + /** * Return the operator as String. * @return the operator */ @@ -141,11 +147,11 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements public String toStringExpression() { final StringBuffer buff; if (reference) { - buff = new StringBuffer("&$"); //$NON-NLS-1$ + buff = new StringBuffer("&"); //$NON-NLS-1$ } else { - buff = new StringBuffer("$");//$NON-NLS-1$ + buff = new StringBuffer();//$NON-NLS-1$ } - buff.append(name); + buff.append(variable.toStringExpression()); if (initialization != null) { buff.append(operatorToString()); //$NON-NLS-1$ buff.append(initialization.toStringExpression()); @@ -178,7 +184,7 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements * @return the name of the String */ public String name() { - return new String(name); + return variable.getName(); } /** @@ -195,7 +201,7 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements */ public List getModifiedVariable() { final ArrayList list = new ArrayList(); - list.add(new VariableUsage(new String(name), sourceStart)); + list.addAll(variable.getModifiedVariable()); if (initialization != null) { list.addAll(initialization.getModifiedVariable()); }