Some minor changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / VariableDeclaration.java
index 5d3f8b9..fc4f236 100644 (file)
@@ -6,10 +6,10 @@ import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.text.Position;
 
 import java.util.List;
-import java.util.ArrayList;
 
 /**
  * A variable declaration.
+ * 
  * @author Matthieu Casanova
  */
 public class VariableDeclaration extends Expression implements Outlineable {
@@ -28,40 +28,43 @@ public class VariableDeclaration extends Expression implements Outlineable {
   public static final int LSHIFT_EQUAL = 11;
   public static final int RSIGNEDSHIFT_EQUAL = 12;
 
-  protected AbstractVariable variable;
+  protected final AbstractVariable variable;
 
   /** The value for variable initialization. */
   public Expression initialization;
 
   private Object parent;
-  private boolean reference;
+  protected boolean reference;
+
   private Position position;
 
   private int operator;
 
   /**
    * Create a variable.
-   * @param variable the name of the variable
+   * 
+   * @param variable       the name of the variable
    * @param initialization the initialization
-   * @param operator the assign operator
-   * @param sourceStart the start point
+   * @param operator       the assign operator
+   * @param sourceStart    the start point
    */
   public VariableDeclaration(final Object parent,
                              final AbstractVariable variable,
                              final Expression initialization,
                              final int operator,
                              final int sourceStart) {
-    super(sourceStart, initialization.getSourceEnd());
+    super(sourceStart, initialization.sourceEnd);
     this.initialization = initialization;
     this.variable = variable;
     this.operator = operator;
     this.parent = parent;
-    position = new Position(sourceStart, getSourceEnd());
+    position = new Position(sourceStart, sourceEnd);
   }
 
   /**
    * Create a variable.
-   * @param variable a variable (in case of $$variablename)
+   * 
+   * @param variable    a variable (in case of $$variablename)
    * @param sourceStart the start point
    */
   public VariableDeclaration(final Object parent,
@@ -71,23 +74,25 @@ public class VariableDeclaration extends Expression implements Outlineable {
     super(sourceStart, sourceEnd);
     this.variable = variable;
     this.parent = parent;
+    position = new Position(sourceStart, sourceEnd);
   }
 
-  public void setReference(final boolean reference) {
+  public final void setReference(final boolean reference) {
     this.reference = reference;
   }
 
   /**
    * Create a variable.
+   * 
    * @param initialization the initialization
-   * @param variable a variable (in case of $$variablename)
-   * @param sourceStart the start point
+   * @param variable       a variable (in case of $$variablename)
+   * @param sourceStart    the start point
    */
   public VariableDeclaration(final AbstractVariable variable,
                              final Expression initialization,
                              final int operator,
                              final int sourceStart) {
-    super(sourceStart, initialization.getSourceEnd());
+    super(sourceStart, initialization.sourceEnd);
     this.variable = variable;
     this.initialization = initialization;
     this.operator = operator;
@@ -95,20 +100,22 @@ public class VariableDeclaration extends Expression implements Outlineable {
 
   /**
    * Create a variable.
-   * @param variable a variable (in case of $$variablename)
+   * 
+   * @param variable    a variable (in case of $$variablename)
    * @param sourceStart the start point
    */
   public VariableDeclaration(final AbstractVariable variable,
                              final int sourceStart) {
-    super(sourceStart, variable.getSourceEnd());
+    super(sourceStart, variable.sourceEnd);
     this.variable = variable;
   }
 
   /**
    * Return the operator as String.
+   * 
    * @return the operator
    */
-  public final String operatorToString() {
+  private String operatorToString() {
     switch (operator) {
       case EQUAL:
         return "="; //$NON-NLS-1$
@@ -142,79 +149,79 @@ public class VariableDeclaration extends Expression implements Outlineable {
 
   /**
    * Return the variable into String.
+   * 
    * @return a String
    */
   public String toStringExpression() {
-    final StringBuffer buff;
-    if (reference) {
-      buff = new StringBuffer("&"); //$NON-NLS-1$
+    final String variableString = variable.toStringExpression();
+    if (initialization == null) {
+      if (reference) return '&' + variableString; else return variableString;
     } else {
-      buff = new StringBuffer();//$NON-NLS-1$
-    }
-    buff.append(variable.toStringExpression());
-    if (initialization != null) {
-      buff.append(operatorToString()); //$NON-NLS-1$
-      buff.append(initialization.toStringExpression());
+      final String operatorString = operatorToString();
+      final String initString = initialization.toStringExpression();
+      final StringBuffer buff = new StringBuffer(variableString.length() +
+                                                 operatorString.length() +
+                                                 initString.length() +
+                                                 1);
+      buff.append(variableString);
+      buff.append(operatorString); //$NON-NLS-1$
+      buff.append(initString);
+      return buff.toString();
     }
-    return buff.toString();
   }
 
-  public Object getParent() {
+  public final Object getParent() {
     return parent;
   }
 
-  public String toString() {
+  public final String toString() {
     return toStringExpression();
   }
 
   /**
    * Get the image of a variable.
+   * 
    * @return the image that represents a php variable
    */
-  public ImageDescriptor getImage() {
+  public final ImageDescriptor getImage() {
     return PHPUiImages.DESC_VAR;
   }
 
-  public Position getPosition() {
+  public final Position getPosition() {
     return position;
   }
 
   /**
    * Get the name of the field as String.
+   * 
    * @return the name of the String
    */
-  public String name() {
+  public final String name() {
     return variable.getName();
   }
 
   /**
    * Get the variables from outside (parameters, globals ...)
-   * @return the variables from outside
    */
-  public List getOutsideVariable() {
-    return new ArrayList(1);
+  public final void getOutsideVariable(final List list) {
   }
 
   /**
    * get the modified variables.
-   * @return the variables from we change value
    */
-  public List getModifiedVariable() {
-    final List list = variable.getUsedVariable();
+  public final void getModifiedVariable(final List list) {
+    variable.getUsedVariable(list);
     if (initialization != null) {
-      list.addAll(initialization.getModifiedVariable());
+      initialization.getModifiedVariable(list);
     }
-    return list;
   }
 
   /**
    * Get the variables used.
-   * @return the variables used
    */
-  public List getUsedVariable() {
+  public final void getUsedVariable(final List list) {
     if (initialization != null) {
-      return initialization.getModifiedVariable();//yes it's getModified variable (in a variable declaration $a = $b, $a is modified, event if you have only $a and no initialization
+      initialization.getUsedVariable(list);
     }
-    return new ArrayList(1);
   }
 }