the unknown variables should be reported only once
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ClassAccess.java
index 8e332c8..5a0553b 100644 (file)
@@ -1,21 +1,33 @@
 package net.sourceforge.phpdt.internal.compiler.ast;
 
 import java.util.List;
-import java.util.ArrayList;
 
 /**
  * Any class access.
  * @author Matthieu Casanova
  */
-public class ClassAccess extends AbstractSuffixExpression {
+public final class ClassAccess extends AbstractVariable {
 
+  /** a static class access : "::". */
   public static final int STATIC = 0;
+
+  /** a normal class access : "->". */
   public static final int NORMAL = 1;
 
-  public Expression prefix;
-  public Expression suffix;
-  public int type;
+  private final Expression prefix;
+
+  /** the suffix. */
+  private final Expression suffix;
 
+  /** the type of access. */
+  private final int type;
+
+  /**
+   * Create a new class access.
+   * @param prefix
+   * @param suffix
+   * @param type the type of access {@link #STATIC} or {@link #NORMAL}
+   */
   public ClassAccess(final Expression prefix,
                      final Expression suffix,
                      final int type) {
@@ -25,7 +37,7 @@ public class ClassAccess extends AbstractSuffixExpression {
     this.type = type;
   }
 
-  public String toStringOperator() {
+  private String toStringOperator() {
     switch (type) {
       case STATIC : return "::"; //$NON-NLS-1$
       case NORMAL : return "->"; //$NON-NLS-1$
@@ -38,34 +50,50 @@ public class ClassAccess extends AbstractSuffixExpression {
    * @return the expression
    */
   public String toStringExpression() {
-    final StringBuffer buff = new StringBuffer();
-    buff.append(prefix.toStringExpression());
-    buff.append(toStringOperator());
-    buff.append(suffix.toStringExpression());
+    final String prefixString = prefix.toStringExpression();
+    final String operatorString = toStringOperator();
+    final String suffixString = suffix.toStringExpression();
+    final StringBuffer buff = new StringBuffer(prefixString.length() +
+                                               operatorString.length() +
+                                               suffixString.length());
+    buff.append(prefixString);
+    buff.append(operatorString);
+    buff.append(suffixString);
     return buff.toString();
   }
 
-          /**
-   * Get the variables from outside (parameters, globals ...)
-   * @return the variables from outside
+  /**
+   * todo: find a better way to handle this
+   * @return the name of the variable
    */
-  public List getOutsideVariable() {
-    return new ArrayList();
+  public String getName() {
+    if (prefix instanceof AbstractVariable) {
+      return ((AbstractVariable)prefix).getName();
+    }
+    return prefix.toStringExpression();
   }
 
   /**
+   * Get the variables from outside (parameters, globals ...)
+   *
+   * @param list the list where we will put variables
+   */
+  public void getOutsideVariable(final List list) {}
+
+  /**
    * get the modified variables.
-   * @return the variables from we change value
+   *
+   * @param list the list where we will put variables
    */
-  public List getModifiedVariable() {
-    return new ArrayList();
-  }
+  public void getModifiedVariable(final List list) {}
 
   /**
    * Get the variables used.
-   * @return the variables used
+   *
+   * @param list the list where we will put variables
    */
-  public List getUsedVariable() {
-    return prefix.getUsedVariable();
+  public void getUsedVariable(final List list) {
+    prefix.getUsedVariable(list);
+    suffix.getUsedVariable(list);
   }
 }