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

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

Issue 1789663003: Index synthetic top-level variable and 'loadLibrary' references. (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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 main() { 307 main() {
308 pref.foo(); // q 308 pref.foo(); // q
309 foo(); // nq 309 foo(); // nq
310 }'''); 310 }''');
311 FunctionElement element = importedUnit().functions[0]; 311 FunctionElement element = importedUnit().functions[0];
312 assertThat(element) 312 assertThat(element)
313 ..isInvokedAt('foo(); // q', true) 313 ..isInvokedAt('foo(); // q', true)
314 ..isInvokedAt('foo(); // nq', false); 314 ..isInvokedAt('foo(); // nq', false);
315 } 315 }
316 316
317 void test_isInvokedBy_FunctionElement_synthetic_loadLibrary() {
318 verifyNoTestUnitErrors = false;
319 _indexTestUnit('''
320 import 'dart:math' deferred as math;
321 main() {
322 math.loadLibrary(); // 1
323 math.loadLibrary(); // 2
324 }
325 ''');
326 LibraryElement mathLib = testLibraryElement.imports[0].importedLibrary;
327 FunctionElement element = mathLib.loadLibraryFunction;
328 assertThat(element).isInvokedAt('loadLibrary(); // 1', true);
329 assertThat(element).isInvokedAt('loadLibrary(); // 2', true);
330 }
331
317 void test_isInvokedBy_MethodElement() { 332 void test_isInvokedBy_MethodElement() {
318 _indexTestUnit(''' 333 _indexTestUnit('''
319 class A { 334 class A {
320 foo() {} 335 foo() {}
321 main() { 336 main() {
322 this.foo(); // q 337 this.foo(); // q
323 foo(); // nq 338 foo(); // nq
324 } 339 }
325 }'''); 340 }''');
326 Element element = findElement('foo'); 341 Element element = findElement('foo');
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 TopLevelVariableElement variable = importedUnit().topLevelVariables[0]; 798 TopLevelVariableElement variable = importedUnit().topLevelVariables[0];
784 assertThat(variable)..isReferencedAt('V; // imp', true); 799 assertThat(variable)..isReferencedAt('V; // imp', true);
785 assertThat(variable.getter) 800 assertThat(variable.getter)
786 ..isReferencedAt('V); // q', true) 801 ..isReferencedAt('V); // q', true)
787 ..isReferencedAt('V); // nq', false); 802 ..isReferencedAt('V); // nq', false);
788 assertThat(variable.setter) 803 assertThat(variable.setter)
789 ..isReferencedAt('V = 5; // q', true) 804 ..isReferencedAt('V = 5; // q', true)
790 ..isReferencedAt('V = 5; // nq', false); 805 ..isReferencedAt('V = 5; // nq', false);
791 } 806 }
792 807
808 void test_isReferencedBy_TopLevelVariableElement_synthetic_hasGetterSetter() {
809 verifyNoTestUnitErrors = false;
810 addSource(
811 '/lib.dart',
812 '''
813 int get V => 0;
814 void set V(_) {}
815 ''');
816 _indexTestUnit('''
817 import 'lib.dart' show V;
818 ''');
819 TopLevelVariableElement element = importedUnit().topLevelVariables[0];
820 assertThat(element).isReferencedAt('V;', true);
821 }
822
823 void test_isReferencedBy_TopLevelVariableElement_synthetic_hasSetter() {
824 verifyNoTestUnitErrors = false;
825 addSource(
826 '/lib.dart',
827 '''
828 void set V(_) {}
829 ''');
830 _indexTestUnit('''
831 import 'lib.dart' show V;
832 ''');
833 TopLevelVariableElement element = importedUnit().topLevelVariables[0];
834 assertThat(element).isReferencedAt('V;', true);
835 }
836
793 void test_isReferencedBy_typeInVariableList() { 837 void test_isReferencedBy_typeInVariableList() {
794 _indexTestUnit(''' 838 _indexTestUnit('''
795 class A {} 839 class A {}
796 A myVariable = null; 840 A myVariable = null;
797 '''); 841 ''');
798 Element element = findElement('A'); 842 Element element = findElement('A');
799 assertThat(element).isReferencedAt('A myVariable', false); 843 assertThat(element).isReferencedAt('A myVariable', false);
800 } 844 }
801 845
802 void test_usedName_isInvokedBy() { 846 void test_usedName_isInvokedBy() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 899 }
856 900
857 /** 901 /**
858 * Asserts that [unitIndex] has an item with the expected properties. 902 * Asserts that [unitIndex] has an item with the expected properties.
859 */ 903 */
860 void _assertHasRelation( 904 void _assertHasRelation(
861 Element element, 905 Element element,
862 List<_Relation> relations, 906 List<_Relation> relations,
863 IndexRelationKind expectedRelationKind, 907 IndexRelationKind expectedRelationKind,
864 ExpectedLocation expectedLocation) { 908 ExpectedLocation expectedLocation) {
865 for (var relation in relations) { 909 for (_Relation relation in relations) {
866 if (relation.kind == expectedRelationKind && 910 if (relation.kind == expectedRelationKind &&
867 relation.offset == expectedLocation.offset && 911 relation.offset == expectedLocation.offset &&
868 relation.length == expectedLocation.length && 912 relation.length == expectedLocation.length &&
869 relation.isQualified == expectedLocation.isQualified) { 913 relation.isQualified == expectedLocation.isQualified) {
870 return; 914 return;
871 } 915 }
872 } 916 }
873 _failWithIndexDump( 917 _failWithIndexDump(
874 'not found\n$element $expectedRelationKind at $expectedLocation'); 918 'not found\n$element $expectedRelationKind at $expectedLocation');
875 } 919 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 final bool isQualified; 1123 final bool isQualified;
1080 1124
1081 _Relation(this.kind, this.offset, this.length, this.isQualified); 1125 _Relation(this.kind, this.offset, this.length, this.isQualified);
1082 1126
1083 @override 1127 @override
1084 String toString() { 1128 String toString() {
1085 return '_Relation{kind: $kind, offset: $offset, length: $length, ' 1129 return '_Relation{kind: $kind, offset: $offset, length: $length, '
1086 'isQualified: $isQualified}'; 1130 'isQualified: $isQualified}';
1087 } 1131 }
1088 } 1132 }
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