visitMethodInvocation method
void
visitMethodInvocation(
- MethodInvocation node
)
override
Implementation
@override
void visitMethodInvocation(MethodInvocation node) {
if (node.target == null &&
_handleConstructorLikeInvocation(
typeName: node.methodName.name,
typeArguments: node.typeArguments,
argumentList: node.argumentList,
offset: node.offset,
length: node.length,
)) {
super.visitMethodInvocation(node);
return;
}
if (node.target != null &&
node.target!.beginToken.lexeme == 'Provider' &&
node.methodName.name == 'of') {
final typeArgs = node.typeArguments;
if (typeArgs != null && typeArgs.arguments.isNotEmpty) {
final consumedType = typeArgs.arguments.first.beginToken.lexeme;
final isReactiveBuildContext = _inBuildMethod && _callbackDepth == 0;
final hasListenFalse = node.toSource().contains('listen: false');
nodes.add(
ProviderOfNode(
consumedClass: consumedType,
isInBuildMethod: isReactiveBuildContext && !hasListenFalse,
isMethodCall: _isFollowedByMethodCall(node),
filePath: filePath,
offset: node.offset,
length: node.length,
),
);
}
} else if (node.target != null &&
node.target!.beginToken.lexeme == 'context' &&
(node.methodName.name == 'read' || node.methodName.name == 'watch')) {
final typeArgs = node.typeArguments;
if (typeArgs != null && typeArgs.arguments.isNotEmpty) {
final consumedType = typeArgs.arguments.first.beginToken.lexeme;
final isReactiveBuildContext = _inBuildMethod && _callbackDepth == 0;
final isWatch = node.methodName.name == 'watch';
nodes.add(
ProviderOfNode(
consumedClass: consumedType,
isInBuildMethod: isWatch && isReactiveBuildContext,
isMethodCall: _isFollowedByMethodCall(node),
filePath: filePath,
offset: node.offset,
length: node.length,
),
);
}
} else if (node.target != null &&
node.target!.beginToken.lexeme == 'context' &&
node.methodName.name == 'select') {
// context.select<T, R>((T v) => v.field) → ref.watch(tProvider.select((v) => v.field))
final typeArgs = node.typeArguments;
if (typeArgs != null && typeArgs.arguments.isNotEmpty) {
final consumedType = typeArgs.arguments.first.beginToken.lexeme;
final selectorSnippet = node.argumentList.arguments.isNotEmpty
? node.argumentList.arguments.first.toSource()
: '(state) => state';
nodes.add(
ContextSelectNode(
consumedClass: consumedType,
selectorSnippet: selectorSnippet,
filePath: filePath,
offset: node.offset,
length: node.length,
),
);
}
}
super.visitMethodInvocation(node);
}