visitProvideFactory method
void
visitProvideFactory(
- int index,
- TokenElement token,
- Expression tokenExpression,
- Reference returnType,
- Reference function,
- List<
Expression> dependencies, - bool isMulti,
override
Implement providing token
by calling function
.
Any dependencies
are expected to invoke local methods as appropriate:
refer('inject').call([refer('Dep1')])
Implementation
@override
void visitProvideFactory(
int index,
TokenElement token,
Expression tokenExpression,
Reference returnType,
Reference function,
List<Expression> dependencies,
bool isMulti,
) {
final fieldName = '_field$index';
final types =
returnType is TypeReference ? returnType.types : <Reference>[];
_fieldCache.add(Field((b) => b
..name = '_field$index'
..type = TypeReference((b) => b
..symbol = returnType.symbol
..url = returnType.url
..types.addAll(types)
..isNullable = true)));
final methodName = '_get${returnType.symbol}\$$index';
_methodCache.add(
Method(
(b) => b
..name = methodName
..returns = returnType
..body = refer(fieldName)
.assignNullAware(function.call(dependencies))
.code,
),
);
if (isMulti) {
_addToMulti(token, tokenExpression, methodName);
} else {
_addToBody(tokenExpression, methodName);
}
}