KickJava   Java API By Example, From Geeks To Geeks.

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


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.QuercusException;
34 import com.caucho.quercus.env.Env;
35 import com.caucho.quercus.env.QuercusClass;
36 import com.caucho.quercus.env.Value;
37 import com.caucho.quercus.parser.QuercusParser;
38 import com.caucho.quercus.program.AbstractFunction;
39 import com.caucho.util.L10N;
40
41 import java.util.ArrayList JavaDoc;
42
43 /**
44  * Represents a PHP static method expression.
45  */

46 public class StaticMethodExpr extends Expr {
47   private static final L10N L = new L10N(StaticMethodExpr.class);
48   
49   protected final String JavaDoc _className;
50   protected final String JavaDoc _name;
51   protected final Expr []_args;
52
53   protected Expr []_fullArgs;
54
55   protected AbstractFunction _fun;
56   protected boolean _isMethod;
57
58   public StaticMethodExpr(Location location, String JavaDoc className, String JavaDoc name, ArrayList JavaDoc<Expr> args)
59   {
60     super(location);
61     _className = className.intern();
62     _name = name.intern();
63
64     _args = new Expr[args.size()];
65     args.toArray(_args);
66   }
67
68   public StaticMethodExpr(Location location, String JavaDoc className, String JavaDoc name, Expr []args)
69   {
70     super(location);
71     _className = className.intern();
72     _name = name.intern();
73
74     _args = args;
75   }
76
77
78   public StaticMethodExpr(String JavaDoc className, String JavaDoc name, ArrayList JavaDoc<Expr> args)
79   {
80     this(Location.UNKNOWN, className, name, args);
81   }
82
83   public StaticMethodExpr(String JavaDoc className, String JavaDoc name, Expr []args)
84   {
85     this(Location.UNKNOWN, className, name, args);
86   }
87
88   /**
89    * Returns the reference of the value.
90    * @param location
91    */

92   @Override JavaDoc
93   public Expr createRef(QuercusParser parser)
94   {
95     return parser.getFactory().createRef(this);
96   }
97
98   /**
99    * Returns the copy of the value.
100    * @param location
101    */

102   @Override JavaDoc
103   public Expr createCopy(ExprFactory factory)
104   {
105     return factory.createCopy(this);
106   }
107   
108   /**
109    * Evaluates the expression.
110    *
111    * @param env the calling environment.
112    *
113    * @return the expression value.
114    */

115   public Value eval(Env env)
116   {
117     QuercusClass cl = env.findClass(_className);
118
119     if (cl == null) {
120       throw new QuercusException(L.l("no matching class {0}", _className));
121     }
122
123     // qa/0954 - what appears to be a static call may be a call to a super constructor
124
Value thisValue = env.getThis();
125
126     return cl.callMethod(env, thisValue, _name, _args);
127   }
128   
129   /**
130    * Evaluates the expression.
131    *
132    * @param env the calling environment.
133    *
134    * @return the expression value.
135    */

136   public Value evalRef(Env env)
137   {
138     QuercusClass cl = env.findClass(_className);
139
140     if (cl == null) {
141       throw new QuercusException(L.l("no matching class {0}", _className));
142     }
143
144     // qa/0954 - what appears to be a static call may be a call to a super constructor
145
Value thisValue = env.getThis();
146
147     return cl.callMethodRef(env, thisValue, _name, _args);
148   }
149   
150   public String JavaDoc toString()
151   {
152     return _name + "()";
153   }
154 }
155
156
Popular Tags