File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -628,6 +628,26 @@ print();
628
628
String [!a^bc!] = '';
629
629
''' , contains ('This is a string.' ));
630
630
631
+ Future <void > test_method_callMethod () async {
632
+ var content = '''
633
+ /// f doc.
634
+ void f(int i) {
635
+ f.[!call^!](1);
636
+ }
637
+ ''' ;
638
+ var expected = '''
639
+ ```dart
640
+ void f(int i)
641
+ ```
642
+ Type: `void Function(int)`
643
+
644
+ Declared in _package:test/main.dart_.
645
+
646
+ ---
647
+ f doc.''' ;
648
+ await assertStringContents (content, equals (expected));
649
+ }
650
+
631
651
Future <void > test_method_mixin_onImplementation () async {
632
652
var content = '''
633
653
abstract class A {
Original file line number Diff line number Diff line change 5
5
import 'package:analyzer/dart/ast/ast.dart' ;
6
6
import 'package:analyzer/dart/ast/visitor.dart' ;
7
7
import 'package:analyzer/dart/element/element.dart' ;
8
+ import 'package:analyzer/dart/element/type.dart' ;
8
9
import 'package:analyzer/src/dart/ast/extensions.dart' ;
9
10
10
11
/// An object used to locate the [Element] associated with a given [AstNode] .
@@ -192,6 +193,14 @@ class _ElementMapper2 extends GeneralizingAstVisitor<Element> {
192
193
return grandParent.element;
193
194
}
194
195
return null ;
196
+ } else if (parent is MethodInvocation &&
197
+ parent.methodName == node &&
198
+ parent.methodName.name == MethodElement .CALL_METHOD_NAME ) {
199
+ // Handle .call() invocations on functions.
200
+ var method = parent.realTarget;
201
+ if (method is Identifier && method.staticType is FunctionType ) {
202
+ return method.element;
203
+ }
195
204
}
196
205
return node.writeOrReadElement;
197
206
}
Original file line number Diff line number Diff line change @@ -453,6 +453,51 @@ class A {
453
453
''' );
454
454
}
455
455
456
+ test_locate_MethodInvocation_class_callMethod_argument () async {
457
+ await resolveTestCode (r'''
458
+ class A {
459
+ void call(int i) {}
460
+ }
461
+ void f(A a) {
462
+ a.call(1);
463
+ }
464
+ ''' );
465
+ var node = findNode.methodInvocation ('call(1)' ).methodName;
466
+ var element = ElementLocator .locate (node);
467
+ _assertElement (element, r'''
468
+ <testLibrary>::@class::A::@method::call
469
+ ''' );
470
+ }
471
+
472
+ test_locate_MethodInvocation_class_callMethod_constructor () async {
473
+ await resolveTestCode (r'''
474
+ class A {
475
+ void call(int i) {}
476
+ }
477
+ void f() {
478
+ A().call(1);
479
+ }
480
+ ''' );
481
+ var node = findNode.methodInvocation ('call(1)' ).methodName;
482
+ var element = ElementLocator .locate (node);
483
+ _assertElement (element, r'''
484
+ <testLibrary>::@class::A::@method::call
485
+ ''' );
486
+ }
487
+
488
+ test_locate_MethodInvocation_function_callMethod () async {
489
+ await resolveTestCode (r'''
490
+ void f(int i) {
491
+ f.call(1);
492
+ }
493
+ ''' );
494
+ var node = findNode.methodInvocation ('call' ).methodName;
495
+ var element = ElementLocator .locate (node);
496
+ _assertElement (element, r'''
497
+ <testLibrary>::@function::f
498
+ ''' );
499
+ }
500
+
456
501
test_locate_MethodInvocation_method () async {
457
502
await resolveTestCode (r'''
458
503
class A {
You can’t perform that action at this time.
0 commit comments