classafBeanUtils::ReflectUtils

sys::Obj
  afBeanUtils::ReflectUtils

@Js

Static methods for finding fields, methods and ctors that match given parameter types.

argTypesFitFunc

Source

static Bool argTypesFitFunc(Type?[] argTypes, Func func)

Returns true if the given parameter types fit the given func.

argTypesFitMethod

Source

static Bool argTypesFitMethod(Type?[] argTypes, Method method, Bool matchArity := false)

Returns true if the given parameter types fit the method signature.

This has the same leniency as if you were calling the method function - so will return true even if there are more argTypes than method parameters.

Set matchArity to true for a stricter match, more appropriate for methods.

findCtor

Source

static Method? findCtor(Type type, Str ctorName, Type?[]? params := null)

Finds a named ctor with the given parameter types.

Returns null if not found.

findCtors

Source

static Method[] findCtors(Type type, Type?[]? params := null, Bool matchArity := false)

Find ctors with the given parameter types.

findField

Source

static Field? findField(Type type, Str fieldName, Type? fieldType := null, Bool? isStatic := null)

Finds a named field.

Returns null if not found.

findFields

Source

static Field[] findFields(Type type, Type fieldType, Bool? isStatic := null)

Find fields.

findMethod

Source

static Method? findMethod(Type type, Str methodName, Type?[]? params := null, Bool? isStatic := null, Type? returnType := null)

Finds a named method with the given parameter types.

Returns null if not found.

findMethods

Source

static Method[] findMethods(Type type, Type?[]? params := null, Bool? isStatic := null, Type? returnType := null, Bool matchArity := false)

Find methods with the given parameter types.

fits

Source

static Bool fits(Type? typeA, Type? typeB)

A replacement for Type.fits() that takes into account type inference for Lists and Maps, and fixes Famtom bugs. Returns true if typeA fits into typeB.

Standard usage:

Str#.fits(Obj#)        // --> true
fits(Str#, Obj#)       // --> true

List (and Map) type checking:

Int[]#.fits(Obj[]#)    // --> true
fits(Int[]#, Obj[]#)   // --> true

List (and Map) type inference. Items in Obj[] may fit into Int[].

Obj[]#.fits(Int[]#)    // --> false
fits(Obj[]#, Int[]#)   // --> true

This is particularly important when calling methods, for many Lists and Maps are defined by the shortcuts [,] and [:] which create Obj?[] and Obj:Obj? respectively.

But List (and Map) types than can never fit still return false:

Str[]#.fits(Int[]#)    // --> false
fits(Str[]#, Int[]#)   // --> false

Fantom (nullable) bug fix for Lists (and Maps):

Int[]#.fits(Int[]?#)   // --> false
fits(Int[]#, Int[]?#)  // --> true

See List Types and Nullability for bug details.