| 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 library test.index; | 5 library testing.abstract_context; |
| 6 | 6 |
| 7 import 'package:analysis_testing/mock_sdk.dart'; |
| 8 import 'package:analysis_testing/reflective_tests.dart'; |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 11 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/sdk.dart'; | 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 13 import 'package:analyzer/src/generated/source_io.dart'; | 15 import 'package:analyzer/src/generated/source_io.dart'; |
| 14 | 16 |
| 15 import 'mocks.dart'; | |
| 16 import 'reflective_tests.dart'; | |
| 17 | |
| 18 | 17 |
| 19 /** | 18 /** |
| 20 * Finds an [engine.Element] with the given [name]. | 19 * Finds an [engine.Element] with the given [name]. |
| 21 */ | 20 */ |
| 22 Element findElementInUnit(CompilationUnit unit, String name, [ElementKind kind]) | 21 Element findElementInUnit(CompilationUnit unit, String name, [ElementKind kind]) |
| 23 { | 22 { |
| 24 Element result = null; | 23 Element result = null; |
| 25 unit.element.accept(new _ElementVisitorFunctionWrapper((Element element) { | 24 unit.element.accept(new _ElementVisitorFunctionWrapper((Element element) { |
| 26 if (element.name != name) { | 25 if (element.name != name) { |
| 27 return; | 26 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 /** | 37 /** |
| 39 * A function to be called for every [Element]. | 38 * A function to be called for every [Element]. |
| 40 */ | 39 */ |
| 41 typedef void _ElementVisitorFunction(Element element); | 40 typedef void _ElementVisitorFunction(Element element); |
| 42 | 41 |
| 43 | 42 |
| 44 @ReflectiveTestCase() | 43 @ReflectiveTestCase() |
| 45 class AbstractContextTest { | 44 class AbstractContextTest { |
| 46 static final DartSdk SDK = new MockSdk(); | 45 static final DartSdk SDK = new MockSdk(); |
| 47 | 46 |
| 47 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 48 AnalysisContext context; | 48 AnalysisContext context; |
| 49 MemoryResourceProvider provider = new MemoryResourceProvider(); | |
| 50 | 49 |
| 51 Source addSource(String path, String content) { | 50 Source addSource(String path, String content) { |
| 52 File file = provider.newFile(path, content); | 51 File file = provider.newFile(path, content); |
| 53 Source source = file.createSource(UriKind.FILE_URI); | 52 Source source = file.createSource(UriKind.FILE_URI); |
| 54 ChangeSet changeSet = new ChangeSet(); | 53 ChangeSet changeSet = new ChangeSet(); |
| 55 changeSet.addedSource(source); | 54 changeSet.addedSource(source); |
| 56 context.applyChanges(changeSet); | 55 context.applyChanges(changeSet); |
| 57 context.setContents(source, content); | 56 context.setContents(source, content); |
| 58 return source; | 57 return source; |
| 59 } | 58 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 80 * [engine.GeneralizingElementVisitor]. | 79 * [engine.GeneralizingElementVisitor]. |
| 81 */ | 80 */ |
| 82 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor { | 81 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor { |
| 83 final _ElementVisitorFunction function; | 82 final _ElementVisitorFunction function; |
| 84 _ElementVisitorFunctionWrapper(this.function); | 83 _ElementVisitorFunctionWrapper(this.function); |
| 85 visitElement(Element element) { | 84 visitElement(Element element) { |
| 86 function(element); | 85 function(element); |
| 87 super.visitElement(element); | 86 super.visitElement(element); |
| 88 } | 87 } |
| 89 } | 88 } |
| OLD | NEW |