Module tea.java
Tea reflection over Java objects.
The functions in this module attempt to ease the use of
a Java code base without having to write Java wrapper classes
(wich can be loaded into the Tea runtime using the
load or load-function functions).
The functions provided allow for instatiation with
constructor invocation, static method invocation, member
field get/set access, and instance method invocation.
Method invocation provides limited support for method overloading.
Method invocation search (as described in the Java Language Specification
, Third Edition , section 15.12) is simplified by searching all methods
with the same name and number of arguments, 1 - in the class of the
object being invoked, then 2 - on the interfaces,
and 3 - on the superclass.
For the set of method that matches the name and number of arguments,
the type of the arguments matches if the Java method argument
is assignable (using java.lang.Class.isAssignable()) from the
Tea value, or by unboxing to a Java primitive type.
(No support is provided for narrowing convertions.)
No support is provided for invocation of methods with variable
argument lists.
Method arguments,
return values, and field get/set values are converted from Tea to Java
ana Java to Tea using a few simple rules.
- Tea $null -
$null is converted to java's null.
- Tea numbers (java.lang.Integer, java.lang.Long,
and java.lang.Double) -
No convertion is needed. Unboxing convertion is performed on method invocation arguments when needed. Examples of Tea value literal/expressions and corresponding Java type:
- 1 -
java.lang.Integer
- 1L -
java.lang.Long
- 1.0 -
java.lang.Double
No support for narrowing convertions (yet).
- Tea strings(java.lang.String) -
Are assignable to java.lang.String. Examples of Tea value literal/expressions and corresponding Java type:
- Tea symbols (com.pdmfc.tea.runtime.SObjSymbol) -
Are converted to java.lang.String. Examples of Tea value literal/expressions and corresponding Java type:
- myFunction -
java.lang.String
- Tea booleans (java.lang.Boolean) -
Are assignable to java.lang.Boolean. Unboxing convertion is performed on method invocation arguments when needed. Examples of Tea value literal/expressions and corresponding Java type:
- $true -
java.lang.Boolean
- $false -
java.lang.Boolean
- Tea lists (com.pdmfc.tea.runtime.SObjPair) -
Are converted to java.util.ArrayList. Each element in the list is recursively converted according to these rules. Examples of Tea value literal/expressions and corresponding Java type:
- ( 1 2 "hello" $true 5.0 ) -
java.util.ArrayList<java.lang.Object>
- TDate (com.pdmfc.tea.runtime.STosObj) -
Are assignable to java.util.Date.
- THashtable (com.pdmfc.tea.runtime.STosObj) -
Are converted to java.util.HashMap. Each element in the hashtable is recursively converted according to these rules.
- TVector (com.pdmfc.tea.runtime.STosObj) -
Are assignable to java.util.ArrayList. Each element in the vector IS NOT recursively converted according to these rules.
- TConnection, TStatement, TResultSet (com.pdmfc.tea.runtime.STosObj) -
Are assignable to java.sql.Connection, java.sql.Statement, java.sql.ResultSet.
The support for exception handling is limited.
All Java Exceptions are converted to Tea runtime errors (as if they
were raised using the error function) regardless
of their original Java Exception class. The only
way to catch them is to use the catch function,
which catches all Tea runtime errors (but does not distinguishes
between originating Java Exception classes).
- Since:
3.2.1
| java-exec-method |
Executes the given static method and returns the result.
|
| java-get-method |
Returns an anonymous function that can be used to wrap Tea calls
to the specified static method.
|
| java-get-value |
Returns the value stored in the member on the given class or object.
|
| java-new-instance |
Returns a new instance of the given class using the given arguments.
|
| java-set-value |
Sets the value of a member on the given class or object.
|
|
Report a bug or request new features
© 2009