| 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.analysis.notification.implemented; | 5 library test.analysis.notification.implemented; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ' in $implementedMembers'); | 83 ' in $implementedMembers'); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 @override | 88 @override |
| 89 Index createIndex() { | 89 Index createIndex() { |
| 90 return createLocalMemoryIndex(); | 90 return createLocalMemoryIndex(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** |
| 94 * Subscribe for `IMPLEMENTED` and wait to the notification. |
| 95 */ |
| 93 Future prepareImplementedElements() { | 96 Future prepareImplementedElements() { |
| 94 addAnalysisSubscription(AnalysisService.IMPLEMENTED, testFile); | 97 subscribeForImplemented(); |
| 95 Future waitForNotification(int times) { | 98 return waitForImplementedElements(); |
| 96 if (times == 0 || implementedClasses != null) { | |
| 97 return new Future.value(); | |
| 98 } | |
| 99 return new Future.delayed( | |
| 100 Duration.ZERO, () => waitForNotification(times - 1)); | |
| 101 } | |
| 102 return waitForNotification(100); | |
| 103 } | 99 } |
| 104 | 100 |
| 105 void processNotification(Notification notification) { | 101 void processNotification(Notification notification) { |
| 106 if (notification.event == ANALYSIS_IMPLEMENTED) { | 102 if (notification.event == ANALYSIS_IMPLEMENTED) { |
| 107 var params = new AnalysisImplementedParams.fromNotification(notification); | 103 var params = new AnalysisImplementedParams.fromNotification(notification); |
| 108 if (params.file == testFile) { | 104 if (params.file == testFile) { |
| 109 implementedClasses = params.classes; | 105 implementedClasses = params.classes; |
| 110 implementedMembers = params.members; | 106 implementedMembers = params.members; |
| 111 } | 107 } |
| 112 } | 108 } |
| 113 } | 109 } |
| 114 | 110 |
| 115 void setUp() { | 111 void setUp() { |
| 116 super.setUp(); | 112 super.setUp(); |
| 117 createProject(); | 113 createProject(); |
| 118 } | 114 } |
| 119 | 115 |
| 116 void subscribeForImplemented() { |
| 117 addAnalysisSubscription(AnalysisService.IMPLEMENTED, testFile); |
| 118 } |
| 119 |
| 120 test_afterAnalysis() async { | 120 test_afterAnalysis() async { |
| 121 addTestFile(''' | 121 addTestFile(''' |
| 122 class A {} | 122 class A {} |
| 123 class B extends A {} | 123 class B extends A {} |
| 124 '''); | 124 '''); |
| 125 await waitForTasksFinished(); | 125 await waitForTasksFinished(); |
| 126 await prepareImplementedElements(); | 126 await prepareImplementedElements(); |
| 127 assertHasImplementedClass('A {'); | 127 assertHasImplementedClass('A {'); |
| 128 } | 128 } |
| 129 | 129 |
| 130 test_afterIncrementalResolution() async { |
| 131 subscribeForImplemented(); |
| 132 addTestFile(''' |
| 133 class A {} |
| 134 class B extends A {} |
| 135 '''); |
| 136 await prepareImplementedElements(); |
| 137 assertHasImplementedClass('A {'); |
| 138 // add a space |
| 139 implementedClasses = null; |
| 140 server.updateContent('1', { |
| 141 testFile: new AddContentOverlay(''' |
| 142 class A {} |
| 143 class B extends A {} |
| 144 ''') |
| 145 }); |
| 146 await waitForImplementedElements(); |
| 147 assertHasImplementedClass('A {'); |
| 148 } |
| 149 |
| 130 test_class_extended() async { | 150 test_class_extended() async { |
| 131 addTestFile(''' | 151 addTestFile(''' |
| 132 class A {} | 152 class A {} |
| 133 class B extends A {} | 153 class B extends A {} |
| 134 '''); | 154 '''); |
| 135 await prepareImplementedElements(); | 155 await prepareImplementedElements(); |
| 136 assertHasImplementedClass('A {'); | 156 assertHasImplementedClass('A {'); |
| 137 } | 157 } |
| 138 | 158 |
| 139 test_class_implemented() async { | 159 test_class_implemented() async { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 class A { | 299 class A { |
| 280 set f(_) {} // A | 300 set f(_) {} // A |
| 281 } | 301 } |
| 282 class B extends A { | 302 class B extends A { |
| 283 set f(_) {} // B | 303 set f(_) {} // B |
| 284 } | 304 } |
| 285 '''); | 305 '''); |
| 286 await prepareImplementedElements(); | 306 await prepareImplementedElements(); |
| 287 assertHasImplementedMember('f(_) {} // A'); | 307 assertHasImplementedMember('f(_) {} // A'); |
| 288 } | 308 } |
| 309 |
| 310 Future waitForImplementedElements() { |
| 311 Future waitForNotification(int times) { |
| 312 if (times == 0 || implementedClasses != null) { |
| 313 return new Future.value(); |
| 314 } |
| 315 return new Future.delayed( |
| 316 Duration.ZERO, () => waitForNotification(times - 1)); |
| 317 } |
| 318 return waitForNotification(100); |
| 319 } |
| 289 } | 320 } |
| OLD | NEW |