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

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

Issue 1779233002: Fix for indexing synthetic elements. (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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 A operator ~() => this; 385 A operator ~() => this;
386 } 386 }
387 main(A a) { 387 main(A a) {
388 print(~a); 388 print(~a);
389 } 389 }
390 '''); 390 ''');
391 MethodElement element = findElement('~'); 391 MethodElement element = findElement('~');
392 assertThat(element).isInvokedAt('~a', true, length: 1); 392 assertThat(element).isInvokedAt('~a', true, length: 1);
393 } 393 }
394 394
395 void test_isInvokedBy_PropertyAccessorElement_getter() {
396 _indexTestUnit('''
397 class A {
398 get ggg => null;
399 main() {
400 this.ggg(); // q
401 ggg(); // nq
402 }
403 }''');
404 PropertyAccessorElement element = findElement('ggg', ElementKind.GETTER);
405 assertThat(element)
406 ..isInvokedAt('ggg(); // q', true)
407 ..isInvokedAt('ggg(); // nq', false);
408 }
409
395 void test_isMixedInBy_ClassDeclaration() { 410 void test_isMixedInBy_ClassDeclaration() {
396 _indexTestUnit(''' 411 _indexTestUnit('''
397 class A {} // 1 412 class A {} // 1
398 class B extends Object with A {} // 2 413 class B extends Object with A {} // 2
399 '''); 414 ''');
400 ClassElement elementA = findElement('A'); 415 ClassElement elementA = findElement('A');
401 assertThat(elementA) 416 assertThat(elementA)
402 ..isMixedInAt('A {} // 2', false) 417 ..isMixedInAt('A {} // 2', false)
403 ..isReferencedAt('A {} // 2', false); 418 ..isReferencedAt('A {} // 2', false);
404 } 419 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 A.bar(); 633 A.bar();
619 } 634 }
620 '''); 635 ''');
621 ClassElement classA = findElement('A'); 636 ClassElement classA = findElement('A');
622 ConstructorElement constA = classA.constructors[0]; 637 ConstructorElement constA = classA.constructors[0];
623 ConstructorElement constA_bar = classA.constructors[2]; 638 ConstructorElement constA_bar = classA.constructors[2];
624 assertThat(constA).isReferencedAt('(); // 2', true, length: 0); 639 assertThat(constA).isReferencedAt('(); // 2', true, length: 0);
625 assertThat(constA_bar).isReferencedAt('.bar(); // 1', true, length: 4); 640 assertThat(constA_bar).isReferencedAt('.bar(); // 1', true, length: 4);
626 } 641 }
627 642
643 void test_isReferencedBy_ConstructorElement_synthetic() {
644 _indexTestUnit('''
645 class A {}
646 main() {
647 new A(); // 1
648 }
649 ''');
650 ClassElement classA = findElement('A');
651 ConstructorElement constA = classA.constructors[0];
652 // A()
653 assertThat(constA)..isReferencedAt('(); // 1', true, length: 0);
654 }
655
628 void test_isReferencedBy_ConstructorFieldInitializer() { 656 void test_isReferencedBy_ConstructorFieldInitializer() {
629 _indexTestUnit(''' 657 _indexTestUnit('''
630 class A { 658 class A {
631 int field; 659 int field;
632 A() : field = 5; 660 A() : field = 5;
633 } 661 }
634 '''); 662 ''');
635 FieldElement element = findElement('field'); 663 FieldElement element = findElement('field');
636 assertThat(element).isReferencedAt('field = 5', true); 664 assertThat(element).isReferencedAt('field = 5', true);
637 } 665 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 String packageIndexJsonString = 905 String packageIndexJsonString =
878 new JsonEncoder.withIndent(' ').convert(packageIndex.toJson()); 906 new JsonEncoder.withIndent(' ').convert(packageIndex.toJson());
879 fail('$msg in\n' + packageIndexJsonString); 907 fail('$msg in\n' + packageIndexJsonString);
880 } 908 }
881 909
882 /** 910 /**
883 * Return the [element] identifier in [packageIndex] or fail. 911 * Return the [element] identifier in [packageIndex] or fail.
884 */ 912 */
885 int _findElementId(Element element) { 913 int _findElementId(Element element) {
886 int unitId = _getUnitId(element); 914 int unitId = _getUnitId(element);
887 int offset = element.nameOffset; 915 ElementInfo info = PackageIndexAssembler.newElementInfo(unitId, element);
888 if (element is LibraryElement || element is CompilationUnitElement) {
889 offset = 0;
890 }
891 IndexSyntheticElementKind kind =
892 PackageIndexAssembler.getIndexElementKind(element);
893 for (int elementId = 0; 916 for (int elementId = 0;
894 elementId < packageIndex.elementUnits.length; 917 elementId < packageIndex.elementUnits.length;
895 elementId++) { 918 elementId++) {
896 if (packageIndex.elementUnits[elementId] == unitId && 919 if (packageIndex.elementUnits[elementId] == unitId &&
897 packageIndex.elementOffsets[elementId] == offset && 920 packageIndex.elementOffsets[elementId] == info.offset &&
898 packageIndex.elementKinds[elementId] == kind) { 921 packageIndex.elementKinds[elementId] == info.kind) {
899 return elementId; 922 return elementId;
900 } 923 }
901 } 924 }
902 _failWithIndexDump('Element $element is not referenced'); 925 _failWithIndexDump('Element $element is not referenced');
903 return 0; 926 return 0;
904 } 927 }
905 928
906 int _getStringId(String str) { 929 int _getStringId(String str) {
907 int id = packageIndex.strings.indexOf(str); 930 int id = packageIndex.strings.indexOf(str);
908 expect(id, isNonNegative); 931 expect(id, isNonNegative);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 void isNotReferencedAt(String search, {int length}) { 1025 void isNotReferencedAt(String search, {int length}) {
1003 test._assertUsedName(name, IndexRelationKind.IS_REFERENCED_BY, 1026 test._assertUsedName(name, IndexRelationKind.IS_REFERENCED_BY,
1004 test._expectedLocation(search, true, length: length), true); 1027 test._expectedLocation(search, true, length: length), true);
1005 } 1028 }
1006 1029
1007 void isReferencedAt(String search, {int length}) { 1030 void isReferencedAt(String search, {int length}) {
1008 test._assertUsedName(name, IndexRelationKind.IS_REFERENCED_BY, 1031 test._assertUsedName(name, IndexRelationKind.IS_REFERENCED_BY,
1009 test._expectedLocation(search, true, length: length), false); 1032 test._expectedLocation(search, true, length: length), false);
1010 } 1033 }
1011 } 1034 }
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