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. | |
Brian Wilkerson
2015/09/30 18:05:16
nit: "to" --> "for"
| |
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 testCode = ''' | |
141 class A {} | |
142 class B extends A {} | |
143 '''; | |
144 server.updateContent('1', {testFile: new AddContentOverlay(testCode)}); | |
145 await waitForImplementedElements(); | |
146 assertHasImplementedClass('A {'); | |
147 } | |
148 | |
130 test_class_extended() async { | 149 test_class_extended() async { |
131 addTestFile(''' | 150 addTestFile(''' |
132 class A {} | 151 class A {} |
133 class B extends A {} | 152 class B extends A {} |
134 '''); | 153 '''); |
135 await prepareImplementedElements(); | 154 await prepareImplementedElements(); |
136 assertHasImplementedClass('A {'); | 155 assertHasImplementedClass('A {'); |
137 } | 156 } |
138 | 157 |
139 test_class_implemented() async { | 158 test_class_implemented() async { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 class A { | 298 class A { |
280 set f(_) {} // A | 299 set f(_) {} // A |
281 } | 300 } |
282 class B extends A { | 301 class B extends A { |
283 set f(_) {} // B | 302 set f(_) {} // B |
284 } | 303 } |
285 '''); | 304 '''); |
286 await prepareImplementedElements(); | 305 await prepareImplementedElements(); |
287 assertHasImplementedMember('f(_) {} // A'); | 306 assertHasImplementedMember('f(_) {} // A'); |
288 } | 307 } |
308 | |
309 Future waitForImplementedElements() { | |
310 Future waitForNotification(int times) { | |
311 if (times == 0 || implementedClasses != null) { | |
312 return new Future.value(); | |
313 } | |
314 return new Future.delayed( | |
315 Duration.ZERO, () => waitForNotification(times - 1)); | |
316 } | |
317 return waitForNotification(100); | |
318 } | |
289 } | 319 } |
OLD | NEW |