OLD | NEW |
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 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 verifyNoTestUnitErrors = false; | 904 verifyNoTestUnitErrors = false; |
905 _indexTestUnit(''' | 905 _indexTestUnit(''' |
906 main(p) { | 906 main(p) { |
907 p.x; | 907 p.x; |
908 p.x = 1; | 908 p.x = 1; |
909 p.x += 2; | 909 p.x += 2; |
910 p.x(); | 910 p.x(); |
911 } | 911 } |
912 '''); | 912 '''); |
913 assertThatName('x') | 913 assertThatName('x') |
914 ..isUsed('x;', IndexRelationKind.IS_READ_BY) | 914 ..isUsedQ('x;', IndexRelationKind.IS_READ_BY) |
915 ..isUsed('x = 1;', IndexRelationKind.IS_WRITTEN_BY) | 915 ..isUsedQ('x = 1;', IndexRelationKind.IS_WRITTEN_BY) |
916 ..isUsed('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) | 916 ..isUsedQ('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) |
917 ..isUsed('x();', IndexRelationKind.IS_INVOKED_BY); | 917 ..isUsedQ('x();', IndexRelationKind.IS_INVOKED_BY); |
918 } | 918 } |
919 | 919 |
920 void test_usedName_unqualified() { | 920 void test_usedName_unqualified_resolved() { |
921 verifyNoTestUnitErrors = false; | 921 verifyNoTestUnitErrors = false; |
922 _indexTestUnit(''' | 922 _indexTestUnit(''' |
923 class C { | 923 class C { |
924 var x; | 924 var x; |
| 925 m() { |
| 926 x; |
| 927 x = 1; |
| 928 x += 2; |
| 929 x(); |
| 930 } |
925 } | 931 } |
| 932 '''); |
| 933 assertThatName('x') |
| 934 ..isNotUsed('x;', IndexRelationKind.IS_READ_BY) |
| 935 ..isNotUsed('x = 1;', IndexRelationKind.IS_WRITTEN_BY) |
| 936 ..isNotUsed('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) |
| 937 ..isNotUsed('x();', IndexRelationKind.IS_INVOKED_BY); |
| 938 } |
| 939 |
| 940 void test_usedName_unqualified_unresolved() { |
| 941 verifyNoTestUnitErrors = false; |
| 942 _indexTestUnit(''' |
926 main() { | 943 main() { |
927 x; | 944 x; |
928 x = 1; | 945 x = 1; |
929 x += 2; | 946 x += 2; |
930 x(); | 947 x(); |
931 } | 948 } |
932 '''); | 949 '''); |
933 assertThatName('x') | 950 assertThatName('x') |
934 ..isNotUsed('x;', IndexRelationKind.IS_READ_BY) | 951 ..isUsed('x;', IndexRelationKind.IS_READ_BY) |
935 ..isNotUsed('x = 1;', IndexRelationKind.IS_WRITTEN_BY) | 952 ..isUsed('x = 1;', IndexRelationKind.IS_WRITTEN_BY) |
936 ..isNotUsed('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) | 953 ..isUsed('x += 2;', IndexRelationKind.IS_READ_WRITTEN_BY) |
937 ..isNotUsed('x();', IndexRelationKind.IS_INVOKED_BY); | 954 ..isUsed('x();', IndexRelationKind.IS_INVOKED_BY); |
938 } | 955 } |
939 | 956 |
940 void _assertDefinedName(String name, IndexNameKind kind, String search) { | 957 void _assertDefinedName(String name, IndexNameKind kind, String search) { |
941 int offset = findOffset(search); | 958 int offset = findOffset(search); |
942 int nameId = _getStringId(name); | 959 int nameId = _getStringId(name); |
943 for (int i = 0; i < unitIndex.definedNames.length; i++) { | 960 for (int i = 0; i < unitIndex.definedNames.length; i++) { |
944 if (unitIndex.definedNames[i] == nameId && | 961 if (unitIndex.definedNames[i] == nameId && |
945 unitIndex.definedNameKinds[i] == kind && | 962 unitIndex.definedNameKinds[i] == kind && |
946 unitIndex.definedNameOffsets[i] == offset) { | 963 unitIndex.definedNameOffsets[i] == offset) { |
947 return; | 964 return; |
(...skipping 21 matching lines...) Expand all Loading... |
969 _failWithIndexDump( | 986 _failWithIndexDump( |
970 'not found\n$element $expectedRelationKind at $expectedLocation'); | 987 'not found\n$element $expectedRelationKind at $expectedLocation'); |
971 } | 988 } |
972 | 989 |
973 void _assertUsedName(String name, IndexRelationKind kind, | 990 void _assertUsedName(String name, IndexRelationKind kind, |
974 ExpectedLocation expectedLocation, bool isNot) { | 991 ExpectedLocation expectedLocation, bool isNot) { |
975 int nameId = _getStringId(name); | 992 int nameId = _getStringId(name); |
976 for (int i = 0; i < unitIndex.usedNames.length; i++) { | 993 for (int i = 0; i < unitIndex.usedNames.length; i++) { |
977 if (unitIndex.usedNames[i] == nameId && | 994 if (unitIndex.usedNames[i] == nameId && |
978 unitIndex.usedNameKinds[i] == kind && | 995 unitIndex.usedNameKinds[i] == kind && |
979 unitIndex.usedNameOffsets[i] == expectedLocation.offset) { | 996 unitIndex.usedNameOffsets[i] == expectedLocation.offset && |
| 997 unitIndex.usedNameIsQualifiedFlags[i] == |
| 998 expectedLocation.isQualified) { |
980 if (isNot) { | 999 if (isNot) { |
981 _failWithIndexDump('Unexpected $name $kind at $expectedLocation'); | 1000 _failWithIndexDump('Unexpected $name $kind at $expectedLocation'); |
982 } | 1001 } |
983 return; | 1002 return; |
984 } | 1003 } |
985 } | 1004 } |
986 if (isNot) { | 1005 if (isNot) { |
987 return; | 1006 return; |
988 } | 1007 } |
989 _failWithIndexDump('Not found $name $kind at $expectedLocation'); | 1008 _failWithIndexDump('Not found $name $kind at $expectedLocation'); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 | 1171 |
1153 _NameIndexAssert(this.test, this.name); | 1172 _NameIndexAssert(this.test, this.name); |
1154 | 1173 |
1155 void isNotUsed(String search, IndexRelationKind kind) { | 1174 void isNotUsed(String search, IndexRelationKind kind) { |
1156 test._assertUsedName( | 1175 test._assertUsedName( |
1157 name, kind, test._expectedLocation(search, true), true); | 1176 name, kind, test._expectedLocation(search, true), true); |
1158 } | 1177 } |
1159 | 1178 |
1160 void isUsed(String search, IndexRelationKind kind) { | 1179 void isUsed(String search, IndexRelationKind kind) { |
1161 test._assertUsedName( | 1180 test._assertUsedName( |
| 1181 name, kind, test._expectedLocation(search, false), false); |
| 1182 } |
| 1183 |
| 1184 void isUsedQ(String search, IndexRelationKind kind) { |
| 1185 test._assertUsedName( |
1162 name, kind, test._expectedLocation(search, true), false); | 1186 name, kind, test._expectedLocation(search, true), false); |
1163 } | 1187 } |
1164 } | 1188 } |
1165 | 1189 |
1166 class _Relation { | 1190 class _Relation { |
1167 final IndexRelationKind kind; | 1191 final IndexRelationKind kind; |
1168 final int offset; | 1192 final int offset; |
1169 final int length; | 1193 final int length; |
1170 final bool isQualified; | 1194 final bool isQualified; |
1171 | 1195 |
1172 _Relation(this.kind, this.offset, this.length, this.isQualified); | 1196 _Relation(this.kind, this.offset, this.length, this.isQualified); |
1173 | 1197 |
1174 @override | 1198 @override |
1175 String toString() { | 1199 String toString() { |
1176 return '_Relation{kind: $kind, offset: $offset, length: $length, ' | 1200 return '_Relation{kind: $kind, offset: $offset, length: $length, ' |
1177 'isQualified: $isQualified}'; | 1201 'isQualified: $isQualified}'; |
1178 } | 1202 } |
1179 } | 1203 } |
OLD | NEW |