class
compilerJava::JavaBridge
sys::Obj compiler::CompilerSupport compiler::CBridge compilerJava::JavaBridge
JavaBridge is the compiler plugin for bringing Java classes into the Fantom type system.
Slots
- areParamsSameSource
-
static Bool areParamsSame(CMethod a, CMethod b)
Do the two methods have the exact same parameter types.
-
private Expr arrayToList(Expr expr, CType of)
Generate List.make(of, expr) where expr is Object[]
- boolTypesSource
-
const static Str[] boolTypes := ...
-
Ensure value type is boxed.
-
private Void checkMethodOverride(TypeDef t, JavaMethod base, MethodDef def)
Called on method/method overrides in the checkOverride callback.
- checkOverrideSource
-
override Void checkOverride(TypeDef t, CSlot base, SlotDef def)
Overrides compiler::CBridge.checkOverride
Called during Inherit step when a Fantom slot overrides a FFI slot. Log and throw compiler error if there is a problem.
- checkTypeSource
-
override Void checkType(TypeDef def)
Overrides compiler::CBridge.checkType
Called during CheckErrors step for a type which extends a FFI class or implements any FFI mixins.
- classTypeSource
-
JavaType classType()
Get a CType representation for
java.lang.Class
- coerceSource
-
override Expr coerce(Expr expr, CType expected, |->| onErr)
Overrides compiler::CBridge.coerce
Coerce expression to expected type. If not a type match then run the onErr function.
- coerceFromArraySource
-
Expr coerceFromArray(Expr expr, CType expected, |->| onErr)
Coerce a Java array to a Fantom list.
- coerceFromPrimitiveSource
-
Expr coerceFromPrimitive(Expr expr, CType expected, |->| onErr)
Coerce a Java primitive to a Fantom type.
- coerceFuncToInterfaceSource
-
Expr coerceFuncToInterface(Expr expr, JavaType expected, |->| onErr)
Attempt to coerce a parameterized sys::Func expr to a Java interface if the interface supports exactly one matching method.
- coerceToArraySource
-
Expr coerceToArray(Expr expr, CType expected, |->| onErr)
Coerce a Fantom list to Java array.
- coerceToPrimitiveSource
-
Expr coerceToPrimitive(Expr expr, JavaType expected, |->| onErr)
Coerce a fan expression to a Java primitive (other than the ones we support natively)
- cpSource
-
readonly ClassPath cp
- decimalTypesSource
-
const static Str[] decimalTypes := ...
- fitsSource
-
Bool fits(CType actual, CType expected)
Return if we can make the actual type fit the expected type, potentially using a coercion.
- floatTypesSource
-
const static Str[] floatTypes := ...
- generateFuncToInterfaceWrapperSource
-
CMethod generateFuncToInterfaceWrapper(Loc loc, FuncType funcType, CType expected, CMethod method)
Generate the wrapper which implements the specified expected interface and overrides the specified method which calls the function.
- intTypesSource
-
const static Str[] intTypes := ...
- isFuncToInterfaceMatchSource
-
Bool isFuncToInterfaceMatch(FuncType funcType, CMethod method)
Return if the specified function type can be used to implement the specified interface method.
-
static internal Bool isMoreSpecific(CallMatch a, CallMatch b)
Is
a
more specific thanb
such thata
could be used passed tob
without a compile time error. -
static private Bool isOverrideInferredType(CType base, CType def)
When overriding a Java method check if the base type is is a Java primitive or array and the override definition is matches how the Java type is inferred in the Fantom type system. If we have a match return true and we'll swizzle things in checkMethodOverride.
- listAsArraySource
-
CMethod listAsArray()
Get a CMethod representation for
Object[] List.asArray()
- listMakeFromArraySource
-
CMethod listMakeFromArray()
Get a CMethod representation for
List.make(Type, Object[])
- loadTypeSource
-
virtual Void loadType(JavaType type, Str:CSlot slots)
Map class meta-data and Java members to Fantom slots for the specified JavaType.
- makeSource
-
new make(Compiler c, ClassPath cp := ClassPath.makeForCurrent())
Construct a JavaBridge for current environment
-
internal CallMatch? matchCall(CallExpr call, CMethod m)
Check if the call matches the specified overload method. If so return method and coerced args otherwise return null.
- objectArrayTypeSource
-
JavaType objectArrayType()
Get a CType representation for
java.lang.Object[]
- primitivesSource
-
readonly JavaPrimitives primitives := JavaPrimitives(this)
- resolveCallSource
-
override CallExpr resolveCall(CallExpr call)
Overrides compiler::CBridge.resolveCall
Resolve a method call: try to find the best match and apply any coercions needed.
- resolveConstructionSource
-
override Expr resolveConstruction(CallExpr call)
Overrides compiler::CBridge.resolveConstruction
Resolve a construction call to a Java constructor.
- resolveConstructorChainSource
-
override Expr resolveConstructorChain(CallExpr call)
Resolve a construction chain call where a Fantom constructor calls the super-class constructor. Type check the arguments and insert any conversions needed.
-
static internal CallMatch? resolveMostSpecific(CallMatch[] matches)
Given a list of overloaed methods find the most specific method according to Java Language Specification 15.11.2.2. The "informal intuition" rule is that a method is more specific than another if the first could be could be passed onto the second one.
- resolvePodSource
-
override CPod resolvePod(Str name, Loc? loc)
Overrides compiler::CBridge.resolvePod
Map a FFI "podName" to a Java package.
- resolveSlotAccessSource
-
override CSlot? resolveSlotAccess(CType base, Str name, Bool noParens)
Overrides compiler::CBridge.resolveSlotAccess
Given a dot operator slot access on the given foreign base type, determine the appopriate slot to use based on whether parens were used
base.name => noParens = true base.name() => noParens = false
In Java a given name could be bound to both a field and a method. In this case we only resolve the field if no parens are used. We also handle the special case of Java annotations here because their element methods are also mapped as Fantom fields (instance based mixin field).
- strTypesSource
-
const static Str[] strTypes := ...