Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ClassAccess.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4
5 /**
6  * Any class access.
7  * @author Matthieu Casanova
8  */
9 public class ClassAccess extends AbstractVariable {
10
11   /** a static class access : "::" */
12   public static final int STATIC = 0;
13
14   /** a normal class access : "->" */
15   public static final int NORMAL = 1;
16
17   public Expression prefix;
18
19   /** the suffix. */
20   public Expression suffix;
21
22   /** the type of access. */
23   public int type;
24
25   /**
26    * Create a new class access.
27    * @param prefix
28    * @param suffix
29    * @param type the type of access {@link #STATIC} or {@link #NORMAL}
30    */
31   public ClassAccess(final Expression prefix,
32                      final Expression suffix,
33                      final int type) {
34     super(prefix.sourceStart, suffix.sourceEnd);
35     this.prefix = prefix;
36     this.suffix = suffix;
37     this.type = type;
38   }
39
40   public String toStringOperator() {
41     switch (type) {
42       case STATIC : return "::"; //$NON-NLS-1$
43       case NORMAL : return "->"; //$NON-NLS-1$
44     }
45     return "unknown operator"; //$NON-NLS-1$
46   }
47
48   /**
49    * Return the expression as String.
50    * @return the expression
51    */
52   public String toStringExpression() {
53     final StringBuffer buff = new StringBuffer();
54     buff.append(prefix.toStringExpression());
55     buff.append(toStringOperator());
56     buff.append(suffix.toStringExpression());
57     return buff.toString();
58   }
59
60   /**
61    * todo: find a better way to handle this
62    * @return
63    */
64   public String getName() {
65     if (prefix instanceof AbstractVariable) {
66       return ((AbstractVariable)prefix).getName();
67     }
68     return prefix.toStringExpression();
69   }
70
71   /**
72    * Get the variables from outside (parameters, globals ...)
73    */
74   public void getOutsideVariable(final List list) {
75   }
76
77   /**
78    * get the modified variables.
79    */
80   public void getModifiedVariable(final List list) {
81   }
82
83   /**
84    * Get the variables used.
85    */
86   public void getUsedVariable(final List list) {
87     prefix.getUsedVariable(list);
88     suffix.getUsedVariable(list);
89   }
90 }