001: /***** BEGIN LICENSE BLOCK *****
002: * Version: CPL 1.0/GPL 2.0/LGPL 2.1
003: *
004: * The contents of this file are subject to the Common Public
005: * License Version 1.0 (the "License"); you may not use this file
006: * except in compliance with the License. You may obtain a copy of
007: * the License at http://www.eclipse.org/legal/cpl-v10.html
008: *
009: * Software distributed under the License is distributed on an "AS
010: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
011: * implied. See the License for the specific language governing
012: * rights and limitations under the License.
013: *
014: * Copyright (C) 2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
015: * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either of the GNU General Public License Version 2 or later (the "GPL"),
019: * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the CPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the CPL, the GPL or the LGPL.
028: ***** END LICENSE BLOCK *****/package org.jruby.runtime.callback;
029:
030: import org.jruby.runtime.Arity;
031: import org.jruby.runtime.CallbackFactory;
032: import org.jruby.runtime.CompiledBlockCallback;
033: import org.jruby.runtime.builtin.IRubyObject;
034:
035: public class ReflectionCallbackFactory extends CallbackFactory {
036:
037: private final Class type;
038:
039: public ReflectionCallbackFactory(Class type) {
040: this .type = type;
041: }
042:
043: public Callback getMethod(String method) {
044: return new ReflectionCallback(type, method, NULL_CLASS_ARRAY,
045: false, false, Arity.noArguments(), false);
046: }
047:
048: public Callback getFastMethod(String method) {
049: return new ReflectionCallback(type, method, NULL_CLASS_ARRAY,
050: false, false, Arity.noArguments(), true);
051: }
052:
053: public Callback getMethod(String method, Class arg1) {
054: return new ReflectionCallback(type, method,
055: new Class[] { arg1 }, false, false, Arity
056: .singleArgument(), false);
057: }
058:
059: public Callback getFastMethod(String method, Class arg1) {
060: return new ReflectionCallback(type, method,
061: new Class[] { arg1 }, false, false, Arity
062: .singleArgument(), true);
063: }
064:
065: public Callback getMethod(String method, Class arg1, Class arg2) {
066: return new ReflectionCallback(type, method, new Class[] { arg1,
067: arg2 }, false, false, Arity.fixed(2), false);
068: }
069:
070: public Callback getFastMethod(String method, Class arg1, Class arg2) {
071: return new ReflectionCallback(type, method, new Class[] { arg1,
072: arg2 }, false, false, Arity.fixed(2), true);
073: }
074:
075: public Callback getMethod(String method, Class arg1, Class arg2,
076: Class arg3) {
077: return new ReflectionCallback(type, method, new Class[] { arg1,
078: arg2, arg3 }, false, false, Arity.fixed(3), false);
079: }
080:
081: public Callback getFastMethod(String method, Class arg1,
082: Class arg2, Class arg3) {
083: return new ReflectionCallback(type, method, new Class[] { arg1,
084: arg2, arg3 }, false, false, Arity.fixed(3), true);
085: }
086:
087: public Callback getSingletonMethod(String method) {
088: return new ReflectionCallback(type, method, NULL_CLASS_ARRAY,
089: false, true, Arity.noArguments(), false);
090: }
091:
092: public Callback getFastSingletonMethod(String method) {
093: return new ReflectionCallback(type, method, NULL_CLASS_ARRAY,
094: false, true, Arity.noArguments(), true);
095: }
096:
097: public Callback getSingletonMethod(String method, Class arg1) {
098: return new ReflectionCallback(type, method,
099: new Class[] { arg1 }, false, true, Arity
100: .singleArgument(), false);
101: }
102:
103: public Callback getFastSingletonMethod(String method, Class arg1) {
104: return new ReflectionCallback(type, method,
105: new Class[] { arg1 }, false, true, Arity
106: .singleArgument(), true);
107: }
108:
109: public Callback getSingletonMethod(String method, Class arg1,
110: Class arg2) {
111: return new ReflectionCallback(type, method, new Class[] { arg1,
112: arg2 }, false, true, Arity.fixed(2), false);
113: }
114:
115: public Callback getFastSingletonMethod(String method, Class arg1,
116: Class arg2) {
117: return new ReflectionCallback(type, method, new Class[] { arg1,
118: arg2 }, false, true, Arity.fixed(2), true);
119: }
120:
121: public Callback getSingletonMethod(String method, Class arg1,
122: Class arg2, Class arg3) {
123: return new ReflectionCallback(type, method, new Class[] { arg1,
124: arg2, arg3 }, false, true, Arity.fixed(3), false);
125: }
126:
127: public Callback getFastSingletonMethod(String method, Class arg1,
128: Class arg2, Class arg3) {
129: return new ReflectionCallback(type, method, new Class[] { arg1,
130: arg2, arg3 }, false, true, Arity.fixed(3), true);
131: }
132:
133: public Callback getBlockMethod(String method) {
134: return new ReflectionCallback(type, method, new Class[] {
135: IRubyObject.class, IRubyObject.class }, false, true,
136: Arity.fixed(2), false);
137: }
138:
139: public CompiledBlockCallback getBlockCallback(String method) {
140: throw new RuntimeException("not implemented");
141: }
142:
143: public Callback getOptSingletonMethod(String method) {
144: return new ReflectionCallback(type, method,
145: new Class[] { IRubyObject[].class }, true, true, Arity
146: .optional(), false);
147: }
148:
149: public Callback getFastOptSingletonMethod(String method) {
150: return new ReflectionCallback(type, method,
151: new Class[] { IRubyObject[].class }, true, true, Arity
152: .optional(), true);
153: }
154:
155: public Callback getOptMethod(String method) {
156: return new ReflectionCallback(type, method,
157: new Class[] { IRubyObject[].class }, true, false, Arity
158: .optional(), false);
159: }
160:
161: public Callback getFastOptMethod(String method) {
162: return new ReflectionCallback(type, method,
163: new Class[] { IRubyObject[].class }, true, false, Arity
164: .optional(), true);
165: }
166: }
|