| OLD | NEW | 
| (Empty) |  | 
 |    1 // Copyright (c) 2017, 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 import 'dart:async'; | 
 |    6  | 
 |    7 import 'package:analyzer/file_system/file_system.dart'; | 
 |    8 import 'package:analyzer/src/dart/analysis/driver.dart'; | 
 |    9 import 'package:analyzer/src/generated/source.dart'; | 
 |   10 import 'package:analyzer_plugin/channel/channel.dart'; | 
 |   11 import 'package:analyzer_plugin/plugin/plugin.dart'; | 
 |   12 import 'package:analyzer_plugin/protocol/protocol.dart'; | 
 |   13 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; | 
 |   14 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; | 
 |   15 import 'package:front_end/src/base/timestamped_data.dart'; | 
 |   16 import 'package:test/test.dart'; | 
 |   17  | 
 |   18 class MockAnalysisDriver extends AnalysisDriverGeneric { | 
 |   19   /** | 
 |   20    * The files that have been added to this driver. | 
 |   21    */ | 
 |   22   List<String> addedFiles = <String>[]; | 
 |   23  | 
 |   24   @override | 
 |   25   bool get hasFilesToAnalyze => false; | 
 |   26  | 
 |   27   @override | 
 |   28   set priorityFiles(List<String> priorityPaths) {} | 
 |   29  | 
 |   30   @override | 
 |   31   AnalysisDriverPriority get workPriority => AnalysisDriverPriority.nothing; | 
 |   32  | 
 |   33   @override | 
 |   34   void addFile(String path) { | 
 |   35     addedFiles.add(path); | 
 |   36   } | 
 |   37  | 
 |   38   @override | 
 |   39   void dispose() {} | 
 |   40  | 
 |   41   @override | 
 |   42   Future<Null> performWork() => new Future.value(null); | 
 |   43 } | 
 |   44  | 
 |   45 class MockChannel implements PluginCommunicationChannel { | 
 |   46   bool _closed = false; | 
 |   47  | 
 |   48   void Function(Request) _onRequest; | 
 |   49   Function _onError; | 
 |   50   void Function() _onDone; | 
 |   51  | 
 |   52   int idCounter = 0; | 
 |   53  | 
 |   54   Map<String, Completer<Response>> completers = <String, Completer<Response>>{}; | 
 |   55  | 
 |   56   @override | 
 |   57   void close() { | 
 |   58     _closed = true; | 
 |   59   } | 
 |   60  | 
 |   61   @override | 
 |   62   void listen(void onRequest(Request request), | 
 |   63       {Function onError, void onDone()}) { | 
 |   64     _onRequest = onRequest; | 
 |   65     _onError = onError; | 
 |   66     _onDone = onDone; | 
 |   67   } | 
 |   68  | 
 |   69   void sendDone() { | 
 |   70     _onDone(); | 
 |   71   } | 
 |   72  | 
 |   73   void sendError(Object exception, StackTrace stackTrace) { | 
 |   74     _onError(exception, stackTrace); | 
 |   75   } | 
 |   76  | 
 |   77   @override | 
 |   78   void sendNotification(Notification notification) { | 
 |   79     if (_closed) { | 
 |   80       throw new StateError('Sent a notification to a closed channel'); | 
 |   81     } | 
 |   82     fail('Unexpected invocation of sendNotification'); | 
 |   83   } | 
 |   84  | 
 |   85   Future<Response> sendRequest(RequestParams params) { | 
 |   86     String id = (idCounter++).toString(); | 
 |   87     Request request = params.toRequest(id); | 
 |   88     Completer<Response> completer = new Completer<Response>(); | 
 |   89     completers[request.id] = completer; | 
 |   90     _onRequest(request); | 
 |   91     return completer.future; | 
 |   92   } | 
 |   93  | 
 |   94   @override | 
 |   95   void sendResponse(Response response) { | 
 |   96     if (_closed) { | 
 |   97       throw new StateError('Sent a response to a closed channel'); | 
 |   98     } | 
 |   99     Completer<Response> completer = completers.remove(response.id); | 
 |  100     completer.complete(response); | 
 |  101   } | 
 |  102 } | 
 |  103  | 
 |  104 /** | 
 |  105  * A concrete implementation of a server plugin that is suitable for testing. | 
 |  106  */ | 
 |  107 class MockServerPlugin extends ServerPlugin { | 
 |  108   MockServerPlugin(ResourceProvider resourceProvider) : super(resourceProvider); | 
 |  109  | 
 |  110   @override | 
 |  111   List<String> get fileGlobsToAnalyze => <String>['*.dart']; | 
 |  112  | 
 |  113   @override | 
 |  114   String get name => 'Test Plugin'; | 
 |  115  | 
 |  116   @override | 
 |  117   String get version => '0.1.0'; | 
 |  118  | 
 |  119   @override | 
 |  120   AnalysisDriverGeneric createAnalysisDriver(ContextRoot contextRoot) { | 
 |  121     return new MockAnalysisDriver(); | 
 |  122   } | 
 |  123  | 
 |  124   @override | 
 |  125   void sendNotificationsForSubscriptions( | 
 |  126       Map<String, List<AnalysisService>> subscriptions) {} | 
 |  127 } | 
 |  128  | 
 |  129 class MockSource implements Source { | 
 |  130   @override | 
 |  131   TimestampedData<String> get contents => null; | 
 |  132  | 
 |  133   @override | 
 |  134   String get encoding => null; | 
 |  135  | 
 |  136   @override | 
 |  137   String get fullName => '/pkg/lib/test.dart'; | 
 |  138  | 
 |  139   @override | 
 |  140   bool get isInSystemLibrary => false; | 
 |  141  | 
 |  142   @override | 
 |  143   Source get librarySource => this; | 
 |  144  | 
 |  145   @override | 
 |  146   int get modificationStamp => 0; | 
 |  147  | 
 |  148   @override | 
 |  149   String get shortName => 'test.dart'; | 
 |  150  | 
 |  151   @override | 
 |  152   Source get source => this; | 
 |  153  | 
 |  154   @override | 
 |  155   Uri get uri => Uri.parse('package:test/test.dart'); | 
 |  156  | 
 |  157   @override | 
 |  158   UriKind get uriKind => UriKind.PACKAGE_URI; | 
 |  159  | 
 |  160   @override | 
 |  161   bool exists() => true; | 
 |  162 } | 
| OLD | NEW |