Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: pkg/analyzer/test/src/summary/index_unit_test.dart

Issue 1738213003: Use separate relation kinds for qualified usages. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/index_unit.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:convert'; 5 import 'dart:convert';
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/summary/format.dart'; 9 import 'package:analyzer/src/summary/format.dart';
10 import 'package:analyzer/src/summary/idl.dart'; 10 import 'package:analyzer/src/summary/idl.dart';
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 _indexTestUnit(''' 101 _indexTestUnit('''
102 class A { 102 class A {
103 var field; 103 var field;
104 main() { 104 main() {
105 this.field(); // q 105 this.field(); // q
106 field(); // nq 106 field(); // nq
107 } 107 }
108 }'''); 108 }''');
109 FieldElement field = findElement('field'); 109 FieldElement field = findElement('field');
110 assertThat(field.getter) 110 assertThat(field.getter)
111 ..isInvokedAt('field(); // q', qualified: true) 111 ..isInvokedQualifiedAt('field(); // q')
112 ..isInvokedAt('field(); // nq'); 112 ..isInvokedAt('field(); // nq');
113 } 113 }
114 114
115 void test_isInvokedBy_FunctionElement() { 115 void test_isInvokedBy_FunctionElement() {
116 addSource( 116 addSource(
117 '/lib.dart', 117 '/lib.dart',
118 ''' 118 '''
119 library lib; 119 library lib;
120 foo() {} 120 foo() {}
121 '''); 121 ''');
122 _indexTestUnit(''' 122 _indexTestUnit('''
123 import 'lib.dart'; 123 import 'lib.dart';
124 import 'lib.dart' as pref; 124 import 'lib.dart' as pref;
125 main() { 125 main() {
126 pref.foo(); // q 126 pref.foo(); // q
127 foo(); // nq 127 foo(); // nq
128 }'''); 128 }''');
129 FunctionElement element = importedUnit().functions[0]; 129 FunctionElement element = importedUnit().functions[0];
130 assertThat(element) 130 assertThat(element)
131 ..isInvokedAt('foo(); // q', qualified: true) 131 ..isInvokedQualifiedAt('foo(); // q')
132 ..isInvokedAt('foo(); // nq'); 132 ..isInvokedAt('foo(); // nq');
133 } 133 }
134 134
135 void test_isInvokedBy_MethodElement() { 135 void test_isInvokedBy_MethodElement() {
136 _indexTestUnit(''' 136 _indexTestUnit('''
137 class A { 137 class A {
138 foo() {} 138 foo() {}
139 main() { 139 main() {
140 this.foo(); // q 140 this.foo(); // q
141 foo(); // nq 141 foo(); // nq
142 } 142 }
143 }'''); 143 }''');
144 Element element = findElement('foo'); 144 Element element = findElement('foo');
145 assertThat(element) 145 assertThat(element)
146 ..isInvokedAt('foo(); // q', qualified: true) 146 ..isInvokedQualifiedAt('foo(); // q')
147 ..isInvokedAt('foo(); // nq'); 147 ..isInvokedAt('foo(); // nq');
148 } 148 }
149 149
150 void test_isInvokedBy_MethodElement_propagatedType() { 150 void test_isInvokedBy_MethodElement_propagatedType() {
151 _indexTestUnit(''' 151 _indexTestUnit('''
152 class A { 152 class A {
153 foo() {} 153 foo() {}
154 } 154 }
155 main() { 155 main() {
156 var a = new A(); 156 var a = new A();
157 a.foo(); 157 a.foo();
158 } 158 }
159 '''); 159 ''');
160 Element element = findElement('foo'); 160 Element element = findElement('foo');
161 assertThat(element).isInvokedAt('foo();', qualified: true); 161 assertThat(element).isInvokedQualifiedAt('foo();');
162 } 162 }
163 163
164 void test_isInvokedBy_operator_binary() { 164 void test_isInvokedBy_operator_binary() {
165 _indexTestUnit(''' 165 _indexTestUnit('''
166 class A { 166 class A {
167 operator +(other) => this; 167 operator +(other) => this;
168 } 168 }
169 main(A a) { 169 main(A a) {
170 print(a + 1); 170 print(a + 1);
171 a += 2; 171 a += 2;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 '''); 403 ''');
404 FieldElement field = findElement('field'); 404 FieldElement field = findElement('field');
405 PropertyAccessorElement getter = field.getter; 405 PropertyAccessorElement getter = field.getter;
406 PropertyAccessorElement setter = field.setter; 406 PropertyAccessorElement setter = field.setter;
407 // A() 407 // A()
408 assertThat(field)..isReferencedAt('field});'); 408 assertThat(field)..isReferencedAt('field});');
409 // m() 409 // m()
410 assertThat(setter)..isReferencedAt('field = 1; // nq'); 410 assertThat(setter)..isReferencedAt('field = 1; // nq');
411 assertThat(getter)..isReferencedAt('field); // nq'); 411 assertThat(getter)..isReferencedAt('field); // nq');
412 // main() 412 // main()
413 assertThat(setter)..isReferencedAt('field = 2; // q', qualified: true); 413 assertThat(setter)..isReferencedQualifiedAt('field = 2; // q');
414 assertThat(getter)..isReferencedAt('field); // q', qualified: true); 414 assertThat(getter)..isReferencedQualifiedAt('field); // q');
415 assertThat(field)..isReferencedAt('field: 3'); 415 assertThat(field)..isReferencedAt('field: 3');
416 } 416 }
417 417
418 void test_isReferencedBy_FunctionElement() { 418 void test_isReferencedBy_FunctionElement() {
419 _indexTestUnit(''' 419 _indexTestUnit('''
420 foo() {} 420 foo() {}
421 main() { 421 main() {
422 print(foo); 422 print(foo);
423 print(foo()); 423 print(foo());
424 } 424 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 _indexTestUnit(''' 460 _indexTestUnit('''
461 class A { 461 class A {
462 method() {} 462 method() {}
463 main() { 463 main() {
464 print(this.method); // q 464 print(this.method); // q
465 print(method); // nq 465 print(method); // nq
466 } 466 }
467 }'''); 467 }''');
468 MethodElement element = findElement('method'); 468 MethodElement element = findElement('method');
469 assertThat(element) 469 assertThat(element)
470 ..isReferencedAt('method); // q', qualified: true) 470 ..isReferencedQualifiedAt('method); // q')
471 ..isReferencedAt('method); // nq'); 471 ..isReferencedAt('method); // nq');
472 } 472 }
473 473
474 void test_isReferencedBy_ParameterElement() { 474 void test_isReferencedBy_ParameterElement() {
475 _indexTestUnit(''' 475 _indexTestUnit('''
476 foo({var p}) {} 476 foo({var p}) {}
477 main() { 477 main() {
478 foo(p: 1); 478 foo(p: 1);
479 } 479 }
480 '''); 480 ''');
(...skipping 13 matching lines...) Expand all
494 import 'lib.dart' as pref; 494 import 'lib.dart' as pref;
495 main() { 495 main() {
496 pref.V = 5; // q 496 pref.V = 5; // q
497 print(pref.V); // q 497 print(pref.V); // q
498 V = 5; // nq 498 V = 5; // nq
499 print(V); // nq 499 print(V); // nq
500 }'''); 500 }''');
501 TopLevelVariableElement variable = importedUnit().topLevelVariables[0]; 501 TopLevelVariableElement variable = importedUnit().topLevelVariables[0];
502 assertThat(variable)..isReferencedAt('V; // imp'); 502 assertThat(variable)..isReferencedAt('V; // imp');
503 assertThat(variable.getter) 503 assertThat(variable.getter)
504 ..isReferencedAt('V); // q', qualified: true) 504 ..isReferencedQualifiedAt('V); // q')
505 ..isReferencedAt('V); // nq'); 505 ..isReferencedAt('V); // nq');
506 assertThat(variable.setter) 506 assertThat(variable.setter)
507 ..isReferencedAt('V = 5; // q', qualified: true) 507 ..isReferencedQualifiedAt('V = 5; // q')
508 ..isReferencedAt('V = 5; // nq'); 508 ..isReferencedAt('V = 5; // nq');
509 } 509 }
510 510
511 void test_isReferencedBy_typeInVariableList() { 511 void test_isReferencedBy_typeInVariableList() {
512 _indexTestUnit(''' 512 _indexTestUnit('''
513 class A {} 513 class A {}
514 A myVariable = null; 514 A myVariable = null;
515 '''); 515 ''');
516 Element element = findElement('A'); 516 Element element = findElement('A');
517 assertThat(element).isReferencedAt('A myVariable'); 517 assertThat(element).isReferencedAt('A myVariable');
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 void isExtendedAt(String search, {int length}) { 631 void isExtendedAt(String search, {int length}) {
632 test._assertHasRelation(element, IndexRelationKind.IS_EXTENDED_BY, 632 test._assertHasRelation(element, IndexRelationKind.IS_EXTENDED_BY,
633 test._expectedLocation(search, length: length)); 633 test._expectedLocation(search, length: length));
634 } 634 }
635 635
636 void isImplementedAt(String search, {int length}) { 636 void isImplementedAt(String search, {int length}) {
637 test._assertHasRelation(element, IndexRelationKind.IS_IMPLEMENTED_BY, 637 test._assertHasRelation(element, IndexRelationKind.IS_IMPLEMENTED_BY,
638 test._expectedLocation(search, length: length)); 638 test._expectedLocation(search, length: length));
639 } 639 }
640 640
641 void isInvokedAt(String search, {int length, bool qualified: false}) { 641 void isInvokedAt(String search, {int length}) {
642 // TODO(scheglov) use 'qualified'
643 test._assertHasRelation(element, IndexRelationKind.IS_INVOKED_BY, 642 test._assertHasRelation(element, IndexRelationKind.IS_INVOKED_BY,
644 test._expectedLocation(search, length: length)); 643 test._expectedLocation(search, length: length));
645 } 644 }
646 645
646 void isInvokedQualifiedAt(String search, {int length}) {
647 test._assertHasRelation(element, IndexRelationKind.IS_INVOKED_QUALIFIED_BY,
648 test._expectedLocation(search, length: length));
649 }
650
647 void isMixedInAt(String search, {int length}) { 651 void isMixedInAt(String search, {int length}) {
648 test._assertHasRelation(element, IndexRelationKind.IS_MIXED_IN_BY, 652 test._assertHasRelation(element, IndexRelationKind.IS_MIXED_IN_BY,
649 test._expectedLocation(search, length: length)); 653 test._expectedLocation(search, length: length));
650 } 654 }
651 655
652 void isReferencedAt(String search, {int length, bool qualified: false}) { 656 void isReferencedAt(String search, {int length}) {
653 // TODO(scheglov) use 'qualified'
654 test._assertHasRelation(element, IndexRelationKind.IS_REFERENCED_BY, 657 test._assertHasRelation(element, IndexRelationKind.IS_REFERENCED_BY,
655 test._expectedLocation(search, length: length)); 658 test._expectedLocation(search, length: length));
656 } 659 }
660
661 void isReferencedQualifiedAt(String search, {int length}) {
662 test._assertHasRelation(
663 element,
664 IndexRelationKind.IS_REFERENCED_QUALIFIED_BY,
665 test._expectedLocation(search, length: length));
666 }
657 } 667 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/index_unit.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698