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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/index_test.dart

Issue 2521913004: Deoptimize Search - request a new resolved unit for local search. (Closed)
Patch Set: Created 4 years 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
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:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/visitor.dart';
11 import 'package:analyzer/src/dart/analysis/driver.dart'; 10 import 'package:analyzer/src/dart/analysis/driver.dart';
12 import 'package:analyzer/src/dart/analysis/index.dart'; 11 import 'package:analyzer/src/dart/analysis/index.dart';
13 import 'package:analyzer/src/summary/format.dart'; 12 import 'package:analyzer/src/summary/format.dart';
14 import 'package:analyzer/src/summary/idl.dart'; 13 import 'package:analyzer/src/summary/idl.dart';
15 import 'package:test/test.dart'; 14 import 'package:test/test.dart';
16 import 'package:test_reflective_loader/test_reflective_loader.dart'; 15 import 'package:test_reflective_loader/test_reflective_loader.dart';
17 16
18 import 'base.dart'; 17 import 'base.dart';
19 18
20 main() { 19 main() {
21 defineReflectiveSuite(() { 20 defineReflectiveSuite(() {
22 defineReflectiveTests(IndexTest); 21 defineReflectiveTests(IndexTest);
23 }); 22 });
24 } 23 }
25 24
26 /**
27 * Finds an [Element] with the given [name].
28 */
29 Element findChildElement(Element root, String name, [ElementKind kind]) {
30 Element result = null;
31 root.accept(new _ElementVisitorFunctionWrapper((Element element) {
32 if (element.name != name) {
33 return;
34 }
35 if (kind != null && element.kind != kind) {
36 return;
37 }
38 result = element;
39 }));
40 return result;
41 }
42
43 /**
44 * A function to be called for every [Element].
45 */
46 typedef void _ElementVisitorFunction(Element element);
47
48 class ExpectedLocation { 25 class ExpectedLocation {
49 final CompilationUnitElement unitElement; 26 final CompilationUnitElement unitElement;
50 final int offset; 27 final int offset;
51 final int length; 28 final int length;
52 final bool isQualified; 29 final bool isQualified;
53 30
54 ExpectedLocation( 31 ExpectedLocation(
55 this.unitElement, this.offset, this.length, this.isQualified); 32 this.unitElement, this.offset, this.length, this.isQualified);
56 33
57 @override 34 @override
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 IndexRelationKind.IS_REFERENCED_BY, 1180 IndexRelationKind.IS_REFERENCED_BY,
1204 test._expectedLocation(search, isQualified, length: length)); 1181 test._expectedLocation(search, isQualified, length: length));
1205 } 1182 }
1206 1183
1207 void isWrittenAt(String search, bool isQualified, {int length}) { 1184 void isWrittenAt(String search, bool isQualified, {int length}) {
1208 test._assertHasRelation(element, relations, IndexRelationKind.IS_WRITTEN_BY, 1185 test._assertHasRelation(element, relations, IndexRelationKind.IS_WRITTEN_BY,
1209 test._expectedLocation(search, isQualified, length: length)); 1186 test._expectedLocation(search, isQualified, length: length));
1210 } 1187 }
1211 } 1188 }
1212 1189
1213 /**
1214 * Wraps an [_ElementVisitorFunction] into a [GeneralizingElementVisitor].
1215 */
1216 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor {
1217 final _ElementVisitorFunction function;
1218
1219 _ElementVisitorFunctionWrapper(this.function);
1220
1221 visitElement(Element element) {
1222 function(element);
1223 super.visitElement(element);
1224 }
1225 }
1226
1227 class _NameIndexAssert { 1190 class _NameIndexAssert {
1228 final IndexTest test; 1191 final IndexTest test;
1229 final String name; 1192 final String name;
1230 1193
1231 _NameIndexAssert(this.test, this.name); 1194 _NameIndexAssert(this.test, this.name);
1232 1195
1233 void isNotUsed(String search, IndexRelationKind kind) { 1196 void isNotUsed(String search, IndexRelationKind kind) {
1234 test._assertUsedName( 1197 test._assertUsedName(
1235 name, kind, test._expectedLocation(search, false), true); 1198 name, kind, test._expectedLocation(search, false), true);
1236 } 1199 }
(...skipping 21 matching lines...) Expand all
1258 final bool isQualified; 1221 final bool isQualified;
1259 1222
1260 _Relation(this.kind, this.offset, this.length, this.isQualified); 1223 _Relation(this.kind, this.offset, this.length, this.isQualified);
1261 1224
1262 @override 1225 @override
1263 String toString() { 1226 String toString() {
1264 return '_Relation{kind: $kind, offset: $offset, length: $length, ' 1227 return '_Relation{kind: $kind, offset: $offset, length: $length, '
1265 'isQualified: $isQualified}lified)'; 1228 'isQualified: $isQualified}lified)';
1266 } 1229 }
1267 } 1230 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/analysis/base.dart ('k') | pkg/analyzer/test/src/dart/analysis/search_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698