| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library analysis_server.test.stress.utilities.server; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:collection'; |
| 9 |
| 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 11 |
| 12 import '../../integration/integration_test_methods.dart'; |
| 13 import '../../integration/integration_tests.dart' as base; |
| 14 |
| 15 /** |
| 16 * An interface for starting and communicating with an analysis server running |
| 17 * in a separate process. |
| 18 */ |
| 19 class Server extends base.Server with IntegrationTestMixin { |
| 20 /** |
| 21 * A list containing the paths of files for which an overlay has been created. |
| 22 */ |
| 23 List<String> filesWithOverlays = <String>[]; |
| 24 |
| 25 /** |
| 26 * A table mapping the absolute paths of files to the most recent set of |
| 27 * errors received for that file. |
| 28 */ |
| 29 Map<String, List<AnalysisError>> _errorMap = |
| 30 new HashMap<String, List<AnalysisError>>(); |
| 31 |
| 32 /** |
| 33 * Initialize a new analysis server. The analysis server is not running and |
| 34 * must be started using [start]. |
| 35 */ |
| 36 Server() { |
| 37 initializeInttestMixin(); |
| 38 onAnalysisErrors.listen(_recordErrors); |
| 39 } |
| 40 |
| 41 /** |
| 42 * Return a table mapping the absolute paths of files to the most recent set |
| 43 * of errors received for that file. The content of the map will not change |
| 44 * when new sets of errors are received. |
| 45 */ |
| 46 Map<String, List<AnalysisError>> get errorMap => |
| 47 new HashMap<String, List<AnalysisError>>.from(_errorMap); |
| 48 |
| 49 @override |
| 50 base.Server get server => this; |
| 51 |
| 52 /** |
| 53 * Remove any existing overlays. |
| 54 */ |
| 55 Future<AnalysisUpdateContentResult> removeAllOverlays() { |
| 56 Map<String, dynamic> files = new HashMap<String, dynamic>(); |
| 57 for (String path in filesWithOverlays) { |
| 58 files[path] = new RemoveContentOverlay(); |
| 59 } |
| 60 return sendAnalysisUpdateContent(files); |
| 61 } |
| 62 |
| 63 @override |
| 64 Future<AnalysisUpdateContentResult> sendAnalysisUpdateContent( |
| 65 Map<String, dynamic> files) { |
| 66 files.forEach((String path, dynamic overlay) { |
| 67 if (overlay is AddContentOverlay) { |
| 68 filesWithOverlays.add(path); |
| 69 } else if (overlay is RemoveContentOverlay) { |
| 70 filesWithOverlays.remove(path); |
| 71 } |
| 72 }); |
| 73 return super.sendAnalysisUpdateContent(files); |
| 74 } |
| 75 |
| 76 /** |
| 77 * Record the errors in the given [params]. |
| 78 */ |
| 79 void _recordErrors(AnalysisErrorsParams params) { |
| 80 _errorMap[params.file] = params.errors; |
| 81 } |
| 82 } |
| OLD | NEW |