Fantom

 

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.

boolTypesSource

const static Str[] boolTypes := ...

checkOverrideSource

override Void checkOverride(TypeDef t, CSlot base, SlotDef def)

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)

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)

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.

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

objectArrayTypeSource

JavaType objectArrayType()

Get a CType representation for java.lang.Object[]

primitivesSource

readonly JavaPrimitives primitives := JavaPrimitives(this)

resolveCallSource

override CallExpr resolveCall(CallExpr call)

Resolve a method call: try to find the best match and apply any coercions needed.

resolveConstructionSource

override Expr resolveConstruction(CallExpr call)

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.

resolvePodSource

override CPod resolvePod(Str name, Loc? loc)

Map a FFI "podName" to a Java package.

resolveSlotAccessSource

override CSlot? resolveSlotAccess(CType base, Str name, Bool noParens)

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 := ...