accept method
Uses visitor
to emit the results of this reader.
Implementation
void accept(InjectorVisitor visitor) {
visitor.visitMeta('_Injector\$${field.name}', '${field.name}\$Injector');
var index = 0;
for (final provider in providers) {
if (provider is UseValueProviderElement) {
Expression actualValue;
try {
actualValue = _reviveAny(provider, provider.useValue);
} on ReviveError catch (e) {
throw BuildError.forElement(
field,
'While reviving providers for Injector: $e\n'
'For complicated objects, use a FactoryProvider instead of '
'a ValueProvider');
}
visitor.visitProvideValue(
index,
provider.token,
_tokenToIdentifier(provider.token),
linkToReference(provider.providerType!, libraryReader),
actualValue,
provider.isMulti,
);
} else if (provider is UseClassProviderElement) {
final name = provider.dependencies.bound.name;
visitor.visitProvideClass(
index,
provider.token,
_tokenToIdentifier(provider.token),
_referSafe(provider.useClass.symbol, provider.useClass.import),
name.isNotEmpty ? name : null,
_computeDependencies(provider.dependencies.positional),
provider.isMulti,
);
} else if (provider is UseFactoryProviderElement) {
visitor.visitProvideFactory(
index,
provider.token,
_tokenToIdentifier(provider.token),
linkToReference(provider.providerType!, libraryReader),
_referSafe(
provider.useFactory.fragment,
provider.useFactory.removeFragment().toString(),
),
_computeDependencies(provider.dependencies.positional),
provider.isMulti,
);
} else if (provider is UseExistingProviderElement) {
visitor.visitProvideExisting(
index,
provider.token,
_tokenToIdentifier(provider.token),
linkToReference(provider.providerType!, libraryReader),
_tokenToIdentifier(provider.redirect),
provider.isMulti,
);
}
index++;
}
// Implicit provider: provide(Injector).
visitor.visitProvideValue(
index,
null,
_$Injector,
_$Injector,
refer('this'),
false,
);
}