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