| 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 testing.abstract_context; | 5 library testing.abstract_context; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/source/package_map_resolver.dart'; | 9 import 'package:analyzer/source/package_map_resolver.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/source_io.dart'; | 15 import 'package:analyzer/src/generated/source_io.dart'; |
| 15 | 16 |
| 16 import 'mock_sdk.dart'; | 17 import 'mock_sdk.dart'; |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * Finds an [Element] with the given [name]. | 20 * Finds an [Element] with the given [name]. |
| 20 */ | 21 */ |
| 21 Element findChildElement(Element root, String name, [ElementKind kind]) { | 22 Element findChildElement(Element root, String name, [ElementKind kind]) { |
| 22 Element result = null; | 23 Element result = null; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 85 |
| 85 void setUp() { | 86 void setUp() { |
| 86 setupResourceProvider(); | 87 setupResourceProvider(); |
| 87 resourceResolver = new ResourceUriResolver(provider); | 88 resourceResolver = new ResourceUriResolver(provider); |
| 88 packageMap = new Map<String, List<Folder>>(); | 89 packageMap = new Map<String, List<Folder>>(); |
| 89 PackageMapUriResolver packageResolver = | 90 PackageMapUriResolver packageResolver = |
| 90 new PackageMapUriResolver(provider, packageMap); | 91 new PackageMapUriResolver(provider, packageMap); |
| 91 context = AnalysisEngine.instance.createAnalysisContext(); | 92 context = AnalysisEngine.instance.createAnalysisContext(); |
| 92 context.sourceFactory = | 93 context.sourceFactory = |
| 93 new SourceFactory([SDK_RESOLVER, packageResolver, resourceResolver]); | 94 new SourceFactory([SDK_RESOLVER, packageResolver, resourceResolver]); |
| 95 AnalysisEngine.instance.logger = PrintLogger.instance; |
| 94 } | 96 } |
| 95 | 97 |
| 96 void setupResourceProvider() { | 98 void setupResourceProvider() { |
| 97 provider = new MemoryResourceProvider(); | 99 provider = new MemoryResourceProvider(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void tearDown() { | 102 void tearDown() { |
| 101 context = null; | 103 context = null; |
| 102 provider = null; | 104 provider = null; |
| 105 AnalysisEngine.instance.logger = null; |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 | 108 |
| 109 /** |
| 110 * Instances of the class [PrintLogger] print all of the errors. |
| 111 */ |
| 112 class PrintLogger implements Logger { |
| 113 static final Logger instance = new PrintLogger(); |
| 114 |
| 115 @override |
| 116 void logError(String message, [CaughtException exception]) { |
| 117 print(message); |
| 118 if (exception != null) { |
| 119 print(exception); |
| 120 } |
| 121 } |
| 122 |
| 123 @override |
| 124 void logError2(String message, Object exception) { |
| 125 print(message); |
| 126 if (exception != null) { |
| 127 print(exception); |
| 128 } |
| 129 } |
| 130 |
| 131 @override |
| 132 void logInformation(String message, [CaughtException exception]) { |
| 133 print(message); |
| 134 if (exception != null) { |
| 135 print(exception); |
| 136 } |
| 137 } |
| 138 |
| 139 @override |
| 140 void logInformation2(String message, Object exception) { |
| 141 print(message); |
| 142 if (exception != null) { |
| 143 print(exception); |
| 144 } |
| 145 } |
| 146 } |
| 147 |
| 106 /** | 148 /** |
| 107 * Wraps the given [_ElementVisitorFunction] into an instance of | 149 * Wraps the given [_ElementVisitorFunction] into an instance of |
| 108 * [engine.GeneralizingElementVisitor]. | 150 * [engine.GeneralizingElementVisitor]. |
| 109 */ | 151 */ |
| 110 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor { | 152 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor { |
| 111 final _ElementVisitorFunction function; | 153 final _ElementVisitorFunction function; |
| 112 _ElementVisitorFunctionWrapper(this.function); | 154 _ElementVisitorFunctionWrapper(this.function); |
| 113 visitElement(Element element) { | 155 visitElement(Element element) { |
| 114 function(element); | 156 function(element); |
| 115 super.visitElement(element); | 157 super.visitElement(element); |
| 116 } | 158 } |
| 117 } | 159 } |
| OLD | NEW |