1 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 ; 42 43 46 public class StaticMethodExpr extends Expr { 47 private static final L10N L = new L10N(StaticMethodExpr.class); 48 49 protected final String _className; 50 protected final String _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 className, String name, ArrayList <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 className, String 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 className, String name, ArrayList <Expr> args) 79 { 80 this(Location.UNKNOWN, className, name, args); 81 } 82 83 public StaticMethodExpr(String className, String name, Expr []args) 84 { 85 this(Location.UNKNOWN, className, name, args); 86 } 87 88 92 @Override 93 public Expr createRef(QuercusParser parser) 94 { 95 return parser.getFactory().createRef(this); 96 } 97 98 102 @Override 103 public Expr createCopy(ExprFactory factory) 104 { 105 return factory.createCopy(this); 106 } 107 108 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 Value thisValue = env.getThis(); 125 126 return cl.callMethod(env, thisValue, _name, _args); 127 } 128 129 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 Value thisValue = env.getThis(); 146 147 return cl.callMethodRef(env, thisValue, _name, _args); 148 } 149 150 public String toString() 151 { 152 return _name + "()"; 153 } 154 } 155 156 | Popular Tags |