Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Variable.java
index bd3c0fd..2a76db4 100644 (file)
@@ -1,10 +1,8 @@
 package net.sourceforge.phpdt.internal.compiler.ast;
 
-import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
-
 import java.util.List;
-import java.util.ArrayList;
-import java.util.Arrays;
+
+import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
 
 /**
  * A variable.
@@ -19,6 +17,9 @@ public class Variable extends AbstractVariable {
   /** A variable inside ($$varname). */
   private AbstractVariable variable;
 
+  /** the variable is defined like this ${expression} */
+  private Expression expression;
+
   public static final String _GET = "_GET";
   public static final String _POST = "_POST";
   public static final String _REQUEST = "_REQUEST";
@@ -69,6 +70,19 @@ public class Variable extends AbstractVariable {
   }
 
   /**
+   * Create a special variable ($$toto for example).
+   * @param expression the variable contained
+   * @param sourceStart the starting position
+   * @param sourceEnd the ending position
+   */
+  public Variable(final Expression expression,
+                  final int sourceStart,
+                  final int sourceEnd) {
+    super(sourceStart, sourceEnd);
+    this.expression = expression;
+  }
+
+  /**
    * Return the expression as String.
    * @return the expression
    */
@@ -77,44 +91,41 @@ public class Variable extends AbstractVariable {
   }
 
   public String getName() {
-    if (variable == null) {
+    if (name != null) {
       return name;
     }
-    return variable.toStringExpression();
+    if (variable != null) {
+      return variable.toStringExpression();
+    }
+    return "{" + expression.toStringExpression() + "}";
   }
 
   /**
    * Get the variables from outside (parameters, globals ...)
-   * @return the variables from outside
    */
-  public List getOutsideVariable() {
-    return new ArrayList(1);
+  public void getOutsideVariable(final List list) {
   }
 
   /**
    * get the modified variables.
-   * @return the variables modified
    */
-  public List getModifiedVariable() {
-    return new ArrayList(1);
+  public void getModifiedVariable(final List list) {
   }
 
   /**
    * Get the variables used.
-   * @return the variables used
    */
-  public List getUsedVariable() {
+  public void getUsedVariable(final List list) {
     final String varName;
-    if (name == null) {
+    if (name != null) {
+      varName = name;
+    } else if (variable != null) {
       varName = variable.getName();
     } else {
-      varName = name;
+      varName = expression.toStringExpression();//todo : do a better thing like evaluate this ??
     }
-    if (arrayContains(SPECIAL_VARS, name)) {
-      return new ArrayList(1);
+    if (!arrayContains(SPECIAL_VARS, name)) {
+      list.add(new VariableUsage(varName, sourceStart));
     }
-    final ArrayList list = new ArrayList(1);
-    list.add(new VariableUsage(varName, sourceStart));
-    return list;
   }
 }