KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > runtime > builtin > IRubyObject


1 /***** BEGIN LICENSE BLOCK *****
2  * Version: CPL 1.0/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Common Public
5  * License Version 1.0 (the "License"); you may not use this file
6  * except in compliance with the License. You may obtain a copy of
7  * the License at http://www.eclipse.org/legal/cpl-v10.html
8  *
9  * Software distributed under the License is distributed on an "AS
10  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * rights and limitations under the License.
13  *
14  * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
15  * Copyright (C) 2002-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
16  * Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
17  * Copyright (C) 2004 Charles O Nutter <headius@headius.com>
18  * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
19  * Copyright (C) 2006 Ola Bini <ola.bini@ki.se>
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * either of the GNU General Public License Version 2 or later (the "GPL"),
23  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
24  * in which case the provisions of the GPL or the LGPL are applicable instead
25  * of those above. If you wish to allow use of your version of this file only
26  * under the terms of either the GPL or the LGPL, and not to allow others to
27  * use your version of this file under the terms of the CPL, indicate your
28  * decision by deleting the provisions above and replace them with the notice
29  * and other provisions required by the GPL or the LGPL. If you do not delete
30  * the provisions above, a recipient may use your version of this file under
31  * the terms of any one of the CPL, the GPL or the LGPL.
32  ***** END LICENSE BLOCK *****/

33 package org.jruby.runtime.builtin;
34
35 import java.util.Iterator JavaDoc;
36 import java.util.Map JavaDoc;
37
38 import org.jruby.Ruby;
39 import org.jruby.RubyArray;
40 import org.jruby.RubyClass;
41 import org.jruby.RubyFloat;
42 import org.jruby.RubyInteger;
43 import org.jruby.RubyModule;
44 import org.jruby.RubyFixnum;
45 import org.jruby.RubyString;
46 import org.jruby.ast.Node;
47 import org.jruby.runtime.Block;
48 import org.jruby.runtime.CallType;
49 import org.jruby.runtime.ThreadContext;
50 import org.jruby.runtime.callback.Callback;
51
52 /** Object is the parent class of all classes in Ruby. Its methods are
53  * therefore available to all objects unless explicitly overridden.
54  *
55  * @author jpetersen
56  */

57 public interface IRubyObject {
58     public static final IRubyObject[] NULL_ARRAY = new IRubyObject[0];
59     
60     /**
61      * Return the ClassIndex value for the native type this object was
62      * constructed from. Particularly useful for determining marshalling
63      * format. All instances of Hash instances of subclasses of Hash, for example
64      * are of Java type RubyHash, and so should utilize RubyHash marshalling
65      * logic in addition to user-defined class marshalling logic.
66      *
67      * @return the ClassIndex of the native type this object was constructed from
68      */

69     int getNativeTypeIndex();
70     
71     /**
72      * Gets a copy of the instance variables for this object, if any exist.
73      * Returns null if this object has no instance variables.
74      * "safe" in that it doesn't cause the instance var map to be created.
75      *
76      * @return A snapshot of the instance vars, or null if none.
77      */

78     Map JavaDoc safeGetInstanceVariables();
79     
80     /**
81      * Returns true if the object has any instance variables, false otherwise.
82      * "safe" in that it doesn't cause the instance var map to be created.
83      *
84      * @return true if the object has instance variables, false otherwise.
85      */

86     boolean safeHasInstanceVariables();
87     
88     /**
89      * RubyMethod getInstanceVar.
90      * @param string
91      * @return RubyObject
92      */

93     IRubyObject getInstanceVariable(String JavaDoc string);
94
95     /**
96      * RubyMethod setInstanceVar.
97      * @param string
98      * @param rubyObject
99      * @return RubyObject
100      */

101     IRubyObject setInstanceVariable(String JavaDoc string, IRubyObject rubyObject);
102     
103     Map JavaDoc getInstanceVariables();
104     Map JavaDoc getInstanceVariablesSnapshot();
105
106     IRubyObject callMethod(ThreadContext context, RubyModule rubyclass, String JavaDoc name, IRubyObject[] args, CallType callType, Block block);
107     IRubyObject callMethod(ThreadContext context, RubyModule rubyclass, byte switchvalue, String JavaDoc name, IRubyObject[] args, CallType callType);
108     
109     IRubyObject callMethod(ThreadContext context, byte switchValue, String JavaDoc name, IRubyObject arg);
110     IRubyObject callMethod(ThreadContext context, byte switchValue, String JavaDoc name, IRubyObject[] args);
111     IRubyObject callMethod(ThreadContext context, byte switchValue, String JavaDoc name, IRubyObject[] args, CallType callType);
112     IRubyObject callMethod(ThreadContext context, byte switchValue, String JavaDoc name, IRubyObject[] args, CallType callType, Block block);
113     
114     IRubyObject callMethod(ThreadContext context, String JavaDoc name, IRubyObject[] args, CallType callType);
115     IRubyObject callMethod(ThreadContext context, String JavaDoc name, IRubyObject[] args, CallType callType, Block block);
116     
117     /**
118      * RubyMethod funcall.
119      * @param context TODO
120      * @param string
121      * @return RubyObject
122      */

123     IRubyObject callMethod(ThreadContext context, String JavaDoc string);
124     IRubyObject callMethod(ThreadContext context, String JavaDoc string, Block aBlock);
125
126     /**
127      * RubyMethod funcall.
128      * @param context TODO
129      * @param string
130      * @param arg
131      * @return RubyObject
132      */

133     IRubyObject callMethod(ThreadContext context, String JavaDoc string, IRubyObject arg);
134
135     /**
136      * RubyMethod callMethod.
137      * @param context TODO
138      * @param method
139      * @param rubyArgs
140      * @return IRubyObject
141      */

142     IRubyObject callMethod(ThreadContext context, String JavaDoc method, IRubyObject[] rubyArgs);
143     IRubyObject callMethod(ThreadContext context, String JavaDoc method, IRubyObject[] rubyArgs, Block block);
144
145     /**
146      * RubyMethod isNil.
147      * @return boolean
148      */

149     boolean isNil();
150
151     boolean isTrue();
152
153     /**
154      * RubyMethod isTaint.
155      * @return boolean
156      */

157     boolean isTaint();
158
159     /**
160      * RubyMethod isFrozen.
161      * @return boolean
162      */

163     boolean isFrozen();
164
165     boolean isImmediate();
166
167     /**
168      * RubyMethod getRubyClass.
169      */

170     RubyClass getMetaClass();
171
172     void setMetaClass(RubyClass metaClass);
173
174     /**
175      * RubyMethod getSingletonClass.
176      * @return RubyClass
177      */

178     RubyClass getSingletonClass();
179
180     /**
181      * RubyMethod getType.
182      * @return RubyClass
183      */

184     RubyClass getType();
185
186     /**
187      * RubyMethod isKindOf.
188      * @param rubyClass
189      * @return boolean
190      */

191     boolean isKindOf(RubyModule rubyClass);
192
193     /**
194      * RubyMethod respondsTo.
195      * @param string
196      * @return boolean
197      */

198     boolean respondsTo(String JavaDoc string);
199
200     /**
201      * RubyMethod getRuntime.
202      */

203     Ruby getRuntime();
204
205     /**
206      * RubyMethod getJavaClass.
207      * @return Class
208      */

209     Class JavaDoc getJavaClass();
210
211     /**
212      * RubyMethod eval.
213      * @param iNode
214      * @return IRubyObject
215      */

216     IRubyObject eval(Node iNode);
217
218     /**
219      * Evaluate the given string under the specified binding object. If the binding is not a Proc or Binding object
220      * (RubyProc or RubyBinding) throw an appropriate type error.
221      * @param context TODO
222      * @param evalString The string containing the text to be evaluated
223      * @param binding The binding object under which to perform the evaluation
224      * @param file The filename to use when reporting errors during the evaluation
225      * @return An IRubyObject result from the evaluation
226      */

227     IRubyObject evalWithBinding(ThreadContext context, IRubyObject evalString, IRubyObject binding, String JavaDoc file);
228
229     /**
230      * Evaluate the given string.
231      * @param context TODO
232      * @param evalString The string containing the text to be evaluated
233      * @param file The filename to use when reporting errors during the evaluation
234      * @param binding The binding object under which to perform the evaluation
235      * @return An IRubyObject result from the evaluation
236      */

237     IRubyObject evalSimple(ThreadContext context, IRubyObject evalString, String JavaDoc file);
238
239     /**
240      * RubyMethod extendObject.
241      * @param rubyModule
242      */

243     void extendObject(RubyModule rubyModule);
244
245     /**
246      * Convert the object into a symbol name if possible.
247      *
248      * @return String the symbol name
249      */

250     String JavaDoc asSymbol();
251
252     /**
253      * Methods which perform to_xxx if the object has such a method
254      */

255     RubyArray convertToArray();
256     RubyFloat convertToFloat();
257     RubyInteger convertToInteger();
258     RubyString convertToString();
259
260     /** rb_obj_as_string
261      */

262     RubyString objAsString();
263
264     /**
265      * Converts this object to type 'targetType' using 'convertMethod' method (MRI: convert_type).
266      *
267      * @param targetType is the type we are trying to convert to
268      * @param convertMethod is the method to be called to try and convert to targeType
269      * @param raiseOnError will throw an Error if conversion does not work
270      * @return the converted value
271      */

272     IRubyObject convertToType(String JavaDoc targetType, String JavaDoc convertMethod, boolean raiseOnError);
273
274     /**
275      * Higher level conversion utility similiar to convertToType but it can throw an
276      * additional TypeError during conversion (MRI: rb_check_convert_type).
277      *
278      * @param targetType is the type we are trying to convert to
279      * @param convertMethod is the method to be called to try and convert to targeType
280      * @return the converted value
281      */

282     IRubyObject convertToTypeWithCheck(String JavaDoc targetType, String JavaDoc convertMethod);
283
284
285     /**
286      * RubyMethod setTaint.
287      * @param b
288      */

289     void setTaint(boolean b);
290
291     /**
292      * RubyMethod checkSafeString.
293      */

294     void checkSafeString();
295
296     /**
297      * RubyMethod convertType.
298      * @param type
299      * @param string
300      * @param string1
301      */

302     IRubyObject convertType(Class JavaDoc type, String JavaDoc string, String JavaDoc string1);
303
304     /**
305      * RubyMethod dup.
306      */

307     IRubyObject dup();
308
309     /**
310      * RubyMethod setupClone.
311      * @param original
312      */

313     void initCopy(IRubyObject original);
314
315     /**
316      * RubyMethod setFrozen.
317      * @param b
318      */

319     void setFrozen(boolean b);
320
321     /**
322      * RubyMethod inspect.
323      * @return String
324      */

325     IRubyObject inspect();
326
327     /**
328      * Make sure the arguments fit the range specified by minimum and maximum. On
329      * a failure, The Ruby runtime will generate an ArgumentError.
330      *
331      * @param arguments to check
332      * @param minimum number of args
333      * @param maximum number of args (-1 for any number of args)
334      * @return the number of arguments in args
335      */

336     int checkArgumentCount(IRubyObject[] arguments, int minimum, int maximum);
337
338     /**
339      * RubyMethod rbClone.
340      * @return IRubyObject
341      */

342     IRubyObject rbClone();
343
344
345     public void callInit(IRubyObject[] args, Block block);
346
347     /**
348      * RubyMethod defineSingletonMethod.
349      * @param name
350      * @param callback
351      */

352     void defineSingletonMethod(String JavaDoc name, Callback callback);
353
354     
355     boolean isSingleton();
356     Iterator JavaDoc instanceVariableNames();
357
358     /**
359      * rb_scan_args
360      *
361      * This method will take the arguments specified, fill in an array and return it filled
362      * with nils for every argument not provided. It's guaranteed to always return a new array.
363      *
364      * @param args the arguments to check
365      * @param required the amount of required arguments
366      * @param optional the amount of optional arguments
367      * @return a new array containing all arguments provided, and nils in those spots not provided.
368      *
369      */

370     IRubyObject[] scanArgs(IRubyObject[] args, int required, int optional);
371
372     /**
373      * Our version of Data_Wrap_Struct.
374      *
375      * This method will just set a private pointer to the object provided. This pointer is transient
376      * and will not be accessible from Ruby.
377      *
378      * @param obj the object to wrap
379      */

380     void dataWrapStruct(Object JavaDoc obj);
381
382     /**
383      * Our version of Data_Get_Struct.
384      *
385      * Returns a wrapped data value if there is one, otherwise returns null.
386      *
387      * @return the object wrapped.
388      */

389     Object JavaDoc dataGetStruct();
390
391     RubyFixnum id();
392
393     IRubyObject anyToString();
394
395     IRubyObject checkStringType();
396
397     IRubyObject checkArrayType();
398     
399     IRubyObject equalInternal(final ThreadContext context, final IRubyObject other);
400
401     void attachToObjectSpace();
402
403     IRubyObject send(IRubyObject[] args, Block block);
404     IRubyObject method(IRubyObject method);
405 }
406
Popular Tags