OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'package:analysis_server/plugin/protocol/protocol_dart.dart'; | 5 import 'package:analysis_server/plugin/protocol/protocol_dart.dart'; |
6 import 'package:analyzer/dart/ast/ast.dart' as engine; | 6 import 'package:analyzer/dart/ast/ast.dart' as engine; |
7 import 'package:analyzer/dart/ast/visitor.dart' as engine; | 7 import 'package:analyzer/dart/ast/visitor.dart' as engine; |
8 import 'package:analyzer/dart/element/element.dart' as engine; | 8 import 'package:analyzer/dart/element/element.dart' as engine; |
9 import 'package:analyzer/dart/element/type.dart' as engine; | 9 import 'package:analyzer/dart/element/type.dart' as engine; |
10 import 'package:analyzer/error/error.dart' as engine; | 10 import 'package:analyzer/error/error.dart' as engine; |
11 import 'package:analyzer/src/dart/ast/utilities.dart' as engine; | 11 import 'package:analyzer/src/dart/ast/utilities.dart' as engine; |
12 import 'package:analyzer/src/dart/element/element.dart' as engine; | 12 import 'package:analyzer/src/dart/element/element.dart' as engine; |
13 import 'package:analyzer/src/error/codes.dart' as engine; | 13 import 'package:analyzer/src/error/codes.dart' as engine; |
14 import 'package:analyzer/src/generated/source.dart' as engine; | 14 import 'package:analyzer/src/generated/source.dart' as engine; |
| 15 import 'package:analyzer/src/generated/testing/search.dart'; |
15 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 16 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
16 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
17 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
18 | 19 |
19 import '../abstract_context.dart'; | 20 import '../abstract_context.dart'; |
20 | 21 |
21 main() { | 22 main() { |
22 defineReflectiveSuite(() { | 23 defineReflectiveSuite(() { |
23 defineReflectiveTests(ElementTest); | 24 defineReflectiveTests(ElementTest); |
24 defineReflectiveTests(ElementKindTest); | 25 defineReflectiveTests(ElementKindTest); |
25 }); | 26 }); |
26 } | 27 } |
27 | 28 |
28 /** | |
29 * Search the [unit] for the [engine.Element]s with the given [name]. | |
30 */ | |
31 List<engine.Element> findElementsByName( | |
32 engine.CompilationUnit unit, String name) { | |
33 var finder = new _ElementsByNameFinder(name); | |
34 unit.accept(finder); | |
35 return finder.elements; | |
36 } | |
37 | |
38 @reflectiveTest | 29 @reflectiveTest |
39 class ElementKindTest { | 30 class ElementKindTest { |
40 void test_fromEngine() { | 31 void test_fromEngine() { |
41 expect(convertElementKind(engine.ElementKind.CLASS), ElementKind.CLASS); | 32 expect(convertElementKind(engine.ElementKind.CLASS), ElementKind.CLASS); |
42 expect(convertElementKind(engine.ElementKind.COMPILATION_UNIT), | 33 expect(convertElementKind(engine.ElementKind.COMPILATION_UNIT), |
43 ElementKind.COMPILATION_UNIT); | 34 ElementKind.COMPILATION_UNIT); |
44 expect(convertElementKind(engine.ElementKind.CONSTRUCTOR), | 35 expect(convertElementKind(engine.ElementKind.CONSTRUCTOR), |
45 ElementKind.CONSTRUCTOR); | 36 ElementKind.CONSTRUCTOR); |
46 expect(convertElementKind(engine.ElementKind.FIELD), ElementKind.FIELD); | 37 expect(convertElementKind(engine.ElementKind.FIELD), ElementKind.FIELD); |
47 expect( | 38 expect( |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 expect(location.offset, 16); | 472 expect(location.offset, 16); |
482 expect(location.length, 'mySetter'.length); | 473 expect(location.length, 'mySetter'.length); |
483 expect(location.startLine, 2); | 474 expect(location.startLine, 2); |
484 expect(location.startColumn, 7); | 475 expect(location.startColumn, 7); |
485 } | 476 } |
486 expect(element.parameters, '(String x)'); | 477 expect(element.parameters, '(String x)'); |
487 expect(element.returnType, isNull); | 478 expect(element.returnType, isNull); |
488 expect(element.flags, 0); | 479 expect(element.flags, 0); |
489 } | 480 } |
490 } | 481 } |
491 | |
492 class _ElementsByNameFinder extends engine.RecursiveAstVisitor<Null> { | |
493 final String name; | |
494 final List<engine.Element> elements = []; | |
495 | |
496 _ElementsByNameFinder(this.name); | |
497 | |
498 @override | |
499 visitSimpleIdentifier(engine.SimpleIdentifier node) { | |
500 if (node.name == name && node.inDeclarationContext()) { | |
501 elements.add(node.staticElement); | |
502 } | |
503 } | |
504 } | |
OLD | NEW |