0fe5fece60e710e4362a06f8d9c763cab879b447
[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.getSourceStart(), suffix.getSourceEnd());
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    * @return the variables from outside
75    */
76   public List getOutsideVariable() {
77     return new ArrayList(1);
78   }
79
80   /**
81    * get the modified variables.
82    * @return the variables from we change value
83    */
84   public List getModifiedVariable() {
85     return new ArrayList(1);
86   }
87
88   /**
89    * Get the variables used.
90    * @return the variables used
91    */
92   public List getUsedVariable() {
93     final List list = prefix.getUsedVariable();
94     list.addAll(suffix.getUsedVariable());
95     return list;
96   }
97 }