KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > expr > ThisFieldExpr


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.expr;
31
32 import com.caucho.quercus.Location;
33 import com.caucho.quercus.env.Env;
34 import com.caucho.quercus.env.Value;
35 import com.caucho.quercus.program.InterpretedClassDef;
36 import com.caucho.util.L10N;
37
38 /**
39  * Represents a PHP field reference.
40  */

41 public class ThisFieldExpr extends AbstractVarExpr {
42   private static final L10N L = new L10N(ThisFieldExpr.class);
43
44   protected final InterpretedClassDef _quercusClass;
45   
46   protected final String JavaDoc _name;
47
48   public ThisFieldExpr(Location location, InterpretedClassDef quercusClass, String JavaDoc name)
49   {
50     super(location);
51     _quercusClass = quercusClass;
52     
53     _name = name.intern();
54   }
55
56   public ThisFieldExpr(InterpretedClassDef quercusClass, String JavaDoc name)
57   {
58     _quercusClass = quercusClass;
59     
60     _name = name.intern();
61   }
62   
63   /**
64    * Evaluates the expression.
65    *
66    * @param env the calling environment.
67    *
68    * @return the expression value.
69    */

70   public Value eval(Env env)
71   {
72     Value obj = env.getThis();
73
74     return obj.getField(env, _name);
75   }
76   
77   /**
78    * Evaluates the expression.
79    *
80    * @param env the calling environment.
81    *
82    * @return the expression value.
83    */

84   public Value evalCopy(Env env)
85   {
86     Value obj = env.getThis();
87
88     return obj.getField(env, _name).copy();
89   }
90   
91   /**
92    * Evaluates the expression.
93    *
94    * @param env the calling environment.
95    *
96    * @return the expression value.
97    */

98   public Value evalRef(Env env)
99   {
100     Value obj = env.getThis();
101
102     return obj.getFieldRef(env, _name);
103   }
104   
105   /**
106    * Evaluates the expression.
107    *
108    * @param env the calling environment.
109    *
110    * @return the expression value.
111    */

112   public Value evalArg(Env env)
113   {
114     Value obj = env.getThis();
115
116     return obj.getFieldArg(env, _name);
117   }
118   
119   /**
120    * Evaluates the expression.
121    *
122    * @param env the calling environment.
123    *
124    * @return the expression value.
125    */

126   public void evalAssign(Env env, Value value)
127   {
128     Value obj = env.getThis();
129
130     obj.putField(env, _name, value);
131   }
132
133   /**
134    * Evaluates the expression, creating an array if the value is unset..
135    *
136    * @param env the calling environment.
137    *
138    * @return the expression value.
139    */

140   public Value evalArray(Env env)
141   {
142     Value obj = env.getThis();
143
144     return obj.getFieldArray(env, _name);
145   }
146
147   /**
148    * Evaluates the expression, creating an array if the value is unset..
149    *
150    * @param env the calling environment.
151    *
152    * @return the expression value.
153    */

154   public Value evalObject(Env env)
155   {
156     Value obj = env.getThis();
157
158     return obj.getFieldObject(env, _name);
159   }
160   
161   /**
162    * Evaluates the expression.
163    *
164    * @param env the calling environment.
165    *
166    * @return the expression value.
167    */

168   public void evalUnset(Env env)
169   {
170     Value obj = env.getThis();
171
172     obj.removeField(_name);
173   }
174   
175   public String JavaDoc toString()
176   {
177     return "$this->" + _name;
178   }
179 }
180
181
Popular Tags