| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/protocol/protocol.dart'; | 7 import 'package:analysis_server/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/protocol/protocol_constants.dart'; | 8 import 'package:analysis_server/protocol/protocol_constants.dart'; |
| 9 import 'package:analysis_server/protocol/protocol_generated.dart'; | 9 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 10 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 10 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 13 | 13 |
| 14 import '../analysis_abstract.dart'; | 14 import '../analysis_abstract.dart'; |
| 15 | 15 |
| 16 main() { | 16 main() { |
| 17 defineReflectiveSuite(() { | 17 defineReflectiveSuite(() { |
| 18 defineReflectiveTests(_AnalysisNotificationOutlineTest); | 18 defineReflectiveTests(_AnalysisNotificationOutlineTest); |
| 19 }); | 19 }); |
| 20 } | 20 } |
| 21 | 21 |
| 22 @reflectiveTest | 22 @reflectiveTest |
| 23 class _AnalysisNotificationOutlineTest extends AbstractAnalysisTest { | 23 class _AnalysisNotificationOutlineTest extends AbstractAnalysisTest { |
| 24 FileKind fileKind; | 24 FileKind fileKind; |
| 25 String libraryName; | 25 String libraryName; |
| 26 Outline outline; | 26 Outline outline; |
| 27 | 27 |
| 28 Completer _resultsAvailable = new Completer(); | 28 Completer _outlineReceived = new Completer(); |
| 29 Completer _highlightsReceived = new Completer(); |
| 29 | 30 |
| 30 Future prepareOutline() { | 31 Future prepareOutline() { |
| 31 addAnalysisSubscription(AnalysisService.OUTLINE, testFile); | 32 addAnalysisSubscription(AnalysisService.OUTLINE, testFile); |
| 32 return _resultsAvailable.future; | 33 return _outlineReceived.future; |
| 33 } | 34 } |
| 34 | 35 |
| 35 void processNotification(Notification notification) { | 36 void processNotification(Notification notification) { |
| 36 if (notification.event == ANALYSIS_NOTIFICATION_OUTLINE) { | 37 if (notification.event == ANALYSIS_NOTIFICATION_OUTLINE) { |
| 37 var params = new AnalysisOutlineParams.fromNotification(notification); | 38 var params = new AnalysisOutlineParams.fromNotification(notification); |
| 38 if (params.file == testFile) { | 39 if (params.file == testFile) { |
| 39 fileKind = params.kind; | 40 fileKind = params.kind; |
| 40 libraryName = params.libraryName; | 41 libraryName = params.libraryName; |
| 41 outline = params.outline; | 42 outline = params.outline; |
| 42 _resultsAvailable.complete(null); | 43 _outlineReceived.complete(null); |
| 44 } |
| 45 } |
| 46 if (notification.event == ANALYSIS_NOTIFICATION_HIGHLIGHTS) { |
| 47 var params = new AnalysisHighlightsParams.fromNotification(notification); |
| 48 if (params.file == testFile) { |
| 49 _highlightsReceived?.complete(null); |
| 50 _highlightsReceived = null; |
| 43 } | 51 } |
| 44 } | 52 } |
| 45 } | 53 } |
| 46 | 54 |
| 47 @override | 55 @override |
| 48 void setUp() { | 56 void setUp() { |
| 49 super.setUp(); | 57 super.setUp(); |
| 50 createProject(); | 58 createProject(); |
| 51 } | 59 } |
| 52 | 60 |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 expect(element.name, "fieldD"); | 718 expect(element.name, "fieldD"); |
| 711 { | 719 { |
| 712 int offset = testCode.indexOf(" // marker"); | 720 int offset = testCode.indexOf(" // marker"); |
| 713 int end = testCode.indexOf(" // marker2"); | 721 int end = testCode.indexOf(" // marker2"); |
| 714 expect(outline.offset, offset); | 722 expect(outline.offset, offset); |
| 715 expect(outline.length, end - offset); | 723 expect(outline.length, end - offset); |
| 716 } | 724 } |
| 717 } | 725 } |
| 718 } | 726 } |
| 719 | 727 |
| 728 test_subscribeWhenCachedResultIsAvailable() async { |
| 729 // https://github.com/dart-lang/sdk/issues/30238 |
| 730 // We need to get notifications for new subscriptions even when the |
| 731 // file is a priority file, and there is a cached result available. |
| 732 addTestFile(''' |
| 733 class A {} |
| 734 class B {} |
| 735 '''); |
| 736 |
| 737 // Make the file a priority one and subscribe for other notification. |
| 738 // This will pre-cache the analysis result for the file. |
| 739 setPriorityFiles([testFile]); |
| 740 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile); |
| 741 await _highlightsReceived.future; |
| 742 |
| 743 // Now subscribe for outline notification, we must get it even though |
| 744 // the result which is used is pre-cached, and not a newly computed. |
| 745 await prepareOutline(); |
| 746 expect(outline.children, hasLength(2)); |
| 747 } |
| 748 |
| 720 test_topLevel() async { | 749 test_topLevel() async { |
| 721 addTestFile(''' | 750 addTestFile(''' |
| 722 typedef String FTA<K, V>(int i, String s); | 751 typedef String FTA<K, V>(int i, String s); |
| 723 typedef FTB(int p); | 752 typedef FTB(int p); |
| 724 class A<T> {} | 753 class A<T> {} |
| 725 class B {} | 754 class B {} |
| 726 class CTA<T> = A<T> with B; | 755 class CTA<T> = A<T> with B; |
| 727 class CTB = A with B; | 756 class CTB = A with B; |
| 728 String fA(int i, String s) => null; | 757 String fA(int i, String s) => null; |
| 729 fB(int p) => null; | 758 fB(int p) => null; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 } | 876 } |
| 848 | 877 |
| 849 void _isEnumConstant(Outline outline, String name) { | 878 void _isEnumConstant(Outline outline, String name) { |
| 850 Element element = outline.element; | 879 Element element = outline.element; |
| 851 expect(element.kind, ElementKind.ENUM_CONSTANT); | 880 expect(element.kind, ElementKind.ENUM_CONSTANT); |
| 852 expect(element.name, name); | 881 expect(element.name, name); |
| 853 expect(element.parameters, isNull); | 882 expect(element.parameters, isNull); |
| 854 expect(element.returnType, isNull); | 883 expect(element.returnType, isNull); |
| 855 } | 884 } |
| 856 } | 885 } |
| OLD | NEW |