
<h1>Javasupport Low-level API</h1>

<h2>Class: Java</h2>

<h3>class methods</h3>

<div class="method">
<a name="java_to_primitive"><pre class="method-title">
java_to_primitive(obj) -> ruby primitive or obj
</pre></a>

<p>If obj is a Java object and either a boolean, numeric type or string, a 
corresponding instance of a primitive (boolean, numeric or string) Ruby type 
is returned. Otherwise obj is returned.</p>
</div>

<div class="method">
<a name="java_to_primitive"><pre class="method-title">
primitive_to_java(obj) -> aJavaObject
</pre></a>

<p>If obj is of a primitive Ruby type (boolean, numeric or string) a 
corresponding JavaObject is returned. Otherwise a JavaObject wrapping obj 
is returned.</p>
</div>

<h2>Class: Java::JavaClass</h2>

<h3>class methods</h3>

<div class="method">
<a name="for_name"><pre class="method-title">
for_name( aString ) -> aJavaClass
</pre></a>

<p>A JavaClass corresponding to the named class is returned. If no matching 
Java class is available a NameError is raised.</p>

<b>Example:</b><br/>

<pre class="code">
Java::JavaClass.for_name("java.util.Random")
</pre>
</div>

<h3>instance methods</h3>

<div class="method">
<a name="public_p"><pre class="method-title">
public? -> true or false
</pre></a>

<p>Returns true if the Java class is public.</p>
</div>

<div class="method">
<a name="final_p"><pre class="method-title">
final? -> true or false
</pre></a>

<p>Returns true if the Java class is final.</p>
</div>

<div class="method">
<a name="interface_p"><pre class="method-title">
interface? -> true or false
</pre></a>

<p>Returns true if the Java class is an Interface.</p>
</div>

<div class="method">
<a name="array_p"><pre class="method-title">
array? -> true or false
</pre></a>

<p>Returns true if the Java class represents a Java array.</p>
</div>

<div class="method">
<a name="name"><pre class="method-title">
name -> aString
</pre></a>

<p>Returns the name of the Java class, i.e "package.name.ClassName".</p>
</div>

<div class="method">
<a name="to_s"><pre class="method-title">
to_s -> aString
</pre></a>

<p>Synonym for <a href="#name">Java::JavaClass#name</a>.</p>
</div>

<div class="method">
<a name="superclass"><pre class="method-title">
superclass -> aJavaClass
</pre></a>

<p>Returns a JavaClass corresponding to the Java super-class of the current 
JavaClass.</p>
</div>

<div class="method">
<a name="cmp"><pre class="method-title">
jc <=> aJavaClass -> -1, 0, +1
</pre></a>

<p>Returns -1, 0, +1 depending on whether this class is a subclasss the same 
class, or neither, as aJavaClass.</p>
</div>

<div class="method">
<a name="java_instance_methods"><pre class="method-title">
java_instance_methods -> anArray
</pre></a>

<p>Returns a list of Java::JavaMethod's for the instance methods available on 
this Java class.</p>
</div>

<div class="method">
<a name="java_class_methods"><pre class="method-title">
java_class_methods -> anArray
</pre></a>

<p>Returns a list of Java::JavaMethod instances for the class (or "static") 
methods available on this Java class.</p>
</div>

<div class="method">
<a name="java_method"><pre class="method-title">
java_method( aString, [aString]* ) -> aJavaMethod
</pre></a>

<p>Returns a Java::JavaMethod for the method with the given name (first 
argument) and parameter types (remaining arguments).</p>

<p>Raises NameError if there isn't a matching method.</p>

<b>Example:</b><br/>
<pre class="code">
string_class = Java::JavaClass.for_name("java.lang.String")
string_class.method("valueOf", "int")
</pre>
</div>

<div class="method">
<a name="constructors"><pre class="method-title">
constructors -> anArray
</pre></a>

<p>Returns a list of Java::JavaConstructor instances for the constructors on 
this Java class.</p>
</div>

<div class="method">
<a name="constructor"><pre class="method-title">
constructor( [aString]* ) -> aJavaConstructor
</pre></a>

<p>Returns a Java::JavaConstructor with parameter types given. Raises 
NameError if there isn't a matching constructor.</p>
</div>

<div class="method">
<a name="public_p"><pre class="method-title">
cls.array_class -> aJavaClass
</pre></a>

<p>Returns a Java::JavaClass representing arrays of this Java class.</p>

<b>Example:</b><br/>
<pre class="code">
cls = Java::JavaClass.for_name("java.lang.String")
cls.array?                      # -> false
array_cls = cls.array_class
array_cls.array?                # -> true
array_cls.name                  # -> "[Ljava.lang.String;"
</pre>
</div>

<div class="method">
<a name="fields"><pre class="method-title">
cls.fields -> anArray
</pre></a>

<p>Returns a list of the public fields (Java::JavaField) on this Java class.</p>
</div>

<div class="method">
<a name="declared_fields"><pre class="method-title">
cls.declared_fields -> anArray
</pre></a>

<p>Returns a list of all (public, private, protected) fields (Java::JavaField) on this Java class.</p>
</div>

<div class="method">
<a name="field"><pre class="method-title">
cls.field( aString ) -> aJavaField
</pre></a>

<p>Returns a Java::JavaField for the named field.</p>

<p>Raises NameError if there is no field by that name.</p>
</div>

<div class="method">
<a name="interfaces"><pre class="method-title">
cls.interfaces -> anArray
</pre></a>

<p>Returns a list of the names of the interfaces implemented by this Java 
class.</p>
</div>

<div class="method">
<a name="primitive_p"><pre class="method-title">
cls.primitive? -> true or false
</pre></a>

<p>Returns true if the Java class represents a primitive type ('int', 
'boolean', etc...), false otherwise.</p>
</div>

<div class="method">
<a name="assignable_from_p"><pre class="method-title">
cls.assignable_from?( aJavaClass ) -> true or false
</pre></a>

<p>Returns true if instances of the given Java class can be assigned to 
variables of this Java class.</p>

<b>Example:</b><br/>
<pre class="code">
object_class.assignable_from?(string_class)  # -> true
string_class.assignable_from?(object_class)  # -> false
</pre>
</div>

<div class="method">
<a name="component_type"><pre class="method-title">
cls.component_type -> aJavaClass
</pre></a>

<p>If this Java class is an array class, then a JavaClass for the type of the 
elements is returned.</p>

<p>If this Java class isn't an array class, then a TypeError is raised.</p>
</div>

<h2>Class: Java::JavaMethod</h2>

<h3>instance methods</h3>

<div class="method">
<a name="method_name"><pre class="method-title">
meth.name -> aString
</pre></a>

<p>Returns the name of the method.</p>

<b>Example:</b><br/>
<pre class="code">
java_class.java_method("toString").name  # --> "toString"
</pre>
</div>

<div class="method">
<a name="arity"><pre class="method-title">
meth.arity -> aFixnum
</pre></a>

<p>Returns the number of arguments on this method.</p>
</div>

<div class="method">
<a name="method_public_p"><pre class="method-title">
meth.public? -> true or false
</pre></a>

<p>Returns true if the Java method is public, false otherwise.</p>
</div>

<div class="method">
<a name="method_final_p"><pre class="method-title">
meth.final? -> true or false
</pre></a>

<p>Returns true if the Java method is final, false otherwise.</p>
</div>

<div class="method">
<a name="invoke"><pre class="method-title">
meth.invoke( aJavaObject, [anObject]* ) -> aJavaObject
</pre></a>

<p>Invokes the corresponding Java instance method on the Java object given as 
first arguments. The remaining arguments are passed as arguments in the 
invokation.<p>

<b>Example:</b><br/>

<pre class="code">
meth.name    # -> "indexOf"
meth.arity   # -> 1
meth.invoke(java_string, another_java_string)
             # -> an instance of java.lang.Integer
</pre>
</div>

<div class="method">
<a name="invoke_static"><pre class="method-title">
meth.invoke_static( [anObject]* ) -> aJavaObject
</pre></a>

<p>Invokes the corresponding Java class ("static") method. All arguments are 
passed as arguments in the invokation.<p>

<b>Example:</b><br/>
<pre class="code">
meth = string_class.java_method("valueOf", "int")
meth.static?   # -> true
meth.invoke_static(java_integer_five)
               # -> the java.lang.String value "5"
</pre>
</div>

<div class="method">
<a name="argument_types"><pre class="method-title">
meth.argument_types -> anArray
</pre></a>

<p>Returns a list of the names of the Java argument types.</p>

<b>Example:</b><br/>
<pre class="code">
meth.argument_types  # -> ["int", "java.lang.String"]
</pre>
</div>

<div class="method">
<a name="inspect"><pre class="method-title">
meth.inspect -> aString
</pre></a>

<p>Returns a human-readable representation of this Java method.</p>
</div>

<div class="method">
<a name="method_static_p"><pre class="method-title">
meth.static? -> true or false
</pre></a>

<p>Returns true if this method is a class ("static") method, false 
otherwise.</p>
</div>

<div class="method">
<a name="return_type"><pre class="method-title">
meth.return_type -> aString
</pre></a>

<p>Returns the name of the Java return type for this method.</p>

<b>Example:</b><br/>
<pre class="code">
meth = java_obj.java_method("toString")
meth.return_type                        # -> "java.lang.String"
</pre>
</div>

<h2>Class: Java::JavaConstructor</h2>

<h3>instance methods</h3>

<div class="method">
<a name="constructor_arity"><pre class="method-title">
cons.arity -> aFixnum
</pre></a>

<p>Returns the number of arguments on this constructor.</p>
</div>

<div class="method">
<a name="new_instance"><pre class="method-title">
cons.new_instance( [anObject]* ) -> aJavaObject
</pre></a>

<p>Creates a new instance of the Java class this constructor belongs to, with 
the given arguments.</p>

<b>Example:</b><br/>
<pre class="code">
cons = integer_class.constructor("int")
result = cons.new_instance(java_integer_ten)
result.java_type     # -> "java.lang.Integer"
</pre>
</div>

<div class="method">
<a name="constructor_inspect"><pre class="method-title">
cons.inspect -> aString
</pre></a>

<p>Returns a human-readable representation of this Java method.</p>
</div>

<div class="method">
<a name="constructor_argument_types"><pre class="method-title">
cons.argument_types -> anArray
</pre></a>

<p>Returns a list of the names of the Java argument types.</p>
</div>


<h2>Class: Java::JavaField</h2>

<div class="method">
<a name="field_static_p"><pre class="method-title">
field.static? -> true or false
</pre></a>

<p>Returns true if this is a class ("static") field, false otherwise.</p>
</div>

<div class="method">
<a name="field_public_p"><pre class="method-title">
field.public? -> true or false
</pre></a>

<p>Returns true if this field is public, false otherwise.</p>
</div>

<div class="method">
<a name="field_final_p"><pre class="method-title">
field.final? -> true or false
</pre></a>

<p>Returns true if this field is final, false otherwise.</p>
</div>

<div class="method">
<a name="field_value"><pre class="method-title">
field.value( anInstance ) -> aJavaObject
</pre></a>

<p>Returns the value of the instance field on the object given as argument. 
The instance argument must be a JavaObject of the class that this field 
belongs to.</p>

<b>Example:</b><br/>
<pre class="code">
width_field = rectangle_class.field(:width)
a_rectangle.java_type            # -> "java.awt.Rectangle"
width_field.value(a_rectangle)   # -> some java.lang.Integer value
</pre>
</div>

<div class="method">
<a name="set_value"><pre class="method-title">
field.set_value( anInstance, aValue ) -> aValue
</pre></a>

<p>Sets the value of this field in the given instance to the given value. The 
instance argument must be a JavaObject of the class that this field belongs 
to. The value argument must be a JavaObject of the same type as this field. 
The value argument is returned.</p>
</div>

<div class="method">
<a name="field_name"><pre class="method-title">
field.name -> aString
</pre></a>

<p>Returns the name of the field.</p>
</div>
