Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Side by Side Diff: pkg/analysis_server/test/plugin/set_analysis_domain_test.dart

Issue 1307143004: Make navigation notification operation Source based, without Dart knowledge. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_analysis.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.plugin.analysis_contributor; 5 library test.plugin.analysis_contributor;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/analysis/analysis_domain.dart'; 9 import 'package:analysis_server/analysis/analysis_domain.dart';
10 import 'package:analysis_server/analysis/navigation/navigation_core.dart'; 10 import 'package:analysis_server/analysis/navigation/navigation_core.dart';
(...skipping 19 matching lines...) Expand all
30 30
31 /** 31 /**
32 * This test uses [SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID] and 32 * This test uses [SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID] and
33 * [NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID] extension points to validate 33 * [NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID] extension points to validate
34 * that plugins can listen for analysis and force sending navigation 34 * that plugins can listen for analysis and force sending navigation
35 * notifications. 35 * notifications.
36 */ 36 */
37 @reflectiveTest 37 @reflectiveTest
38 class SetAnalysisDomainTest extends AbstractAnalysisTest { 38 class SetAnalysisDomainTest extends AbstractAnalysisTest {
39 final Set<String> parsedUnitFiles = new Set<String>(); 39 final Set<String> parsedUnitFiles = new Set<String>();
40 bool contributorMayAddRegion = false;
41 40
42 List<NavigationRegion> regions; 41 List<NavigationRegion> regions;
43 List<NavigationTarget> targets; 42 List<NavigationTarget> targets;
44 List<String> targetFiles; 43 List<String> targetFiles;
45 44
46 @override 45 @override
47 void addServerPlugins(List<Plugin> plugins) { 46 void addServerPlugins(List<Plugin> plugins) {
48 var plugin = new TestSetAnalysisDomainPlugin(this); 47 var plugin = new TestSetAnalysisDomainPlugin(this);
49 plugins.add(plugin); 48 plugins.add(plugin);
50 } 49 }
51 50
52 @override 51 @override
53 void processNotification(Notification notification) { 52 void processNotification(Notification notification) {
54 if (notification.event == ANALYSIS_NAVIGATION) { 53 if (notification.event == ANALYSIS_NAVIGATION) {
55 var params = new AnalysisNavigationParams.fromNotification(notification); 54 var params = new AnalysisNavigationParams.fromNotification(notification);
56 // TODO(scheglov) we check for "params.regions.isNotEmpty" because 55 if (params.file == testFile) {
57 // normal, Dart only, navigation notifications are scheduled as
58 // operations, but plugins use "notificationSite.scheduleNavigation"
59 // which is not scheduled yet. So, it comes *before* the Dart one, and
60 // gets lost.
61 if (params.file == testFile && params.regions.isNotEmpty) {
62 regions = params.regions; 56 regions = params.regions;
63 targets = params.targets; 57 targets = params.targets;
64 targetFiles = params.files; 58 targetFiles = params.files;
65 } 59 }
66 } 60 }
67 } 61 }
68 62
69 Future test_contributorIsInvoked() async { 63 Future test_contributorIsInvoked() async {
70 createProject(); 64 createProject();
71 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile); 65 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile);
(...skipping 22 matching lines...) Expand all
94 } 88 }
95 89
96 class TestNavigationContributor implements NavigationContributor { 90 class TestNavigationContributor implements NavigationContributor {
97 final SetAnalysisDomainTest test; 91 final SetAnalysisDomainTest test;
98 92
99 TestNavigationContributor(this.test); 93 TestNavigationContributor(this.test);
100 94
101 @override 95 @override
102 void computeNavigation(NavigationHolder holder, AnalysisContext context, 96 void computeNavigation(NavigationHolder holder, AnalysisContext context,
103 Source source, int offset, int length) { 97 Source source, int offset, int length) {
104 if (test.contributorMayAddRegion) { 98 holder.addRegion(1, 5, ElementKind.CLASS,
105 holder.addRegion(1, 5, ElementKind.CLASS, 99 new Location('/testLocation.dart', 1, 2, 3, 4));
106 new Location('/testLocation.dart', 1, 2, 3, 4));
107 }
108 } 100 }
109 } 101 }
110 102
111 class TestSetAnalysisDomainPlugin implements Plugin { 103 class TestSetAnalysisDomainPlugin implements Plugin {
112 final SetAnalysisDomainTest test; 104 final SetAnalysisDomainTest test;
113 105
114 TestSetAnalysisDomainPlugin(this.test); 106 TestSetAnalysisDomainPlugin(this.test);
115 107
116 @override 108 @override
117 String get uniqueIdentifier => 'test'; 109 String get uniqueIdentifier => 'test';
118 110
119 @override 111 @override
120 void registerExtensionPoints(RegisterExtensionPoint register) {} 112 void registerExtensionPoints(RegisterExtensionPoint register) {}
121 113
122 @override 114 @override
123 void registerExtensions(RegisterExtension register) { 115 void registerExtensions(RegisterExtension register) {
124 register(SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID, _setAnalysisDomain); 116 register(SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID, _setAnalysisDomain);
125 register(NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID, 117 register(NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID,
126 new TestNavigationContributor(test)); 118 new TestNavigationContributor(test));
127 } 119 }
128 120
129 void _setAnalysisDomain(AnalysisDomain domain) { 121 void _setAnalysisDomain(AnalysisDomain domain) {
130 domain.onResultComputed(PARSED_UNIT).listen((result) { 122 domain.onResultComputed(PARSED_UNIT).listen((result) {
131 expect(result.context, isNotNull); 123 expect(result.context, isNotNull);
132 expect(result.target, isNotNull); 124 expect(result.target, isNotNull);
133 expect(result.value, isNotNull); 125 expect(result.value, isNotNull);
134 Source source = result.target.source; 126 Source source = result.target.source;
135 test.parsedUnitFiles.add(source.fullName); 127 test.parsedUnitFiles.add(source.fullName);
136 // let the navigation contributor to work 128 domain.scheduleNotification(
137 test.contributorMayAddRegion = true; 129 result.context, source, AnalysisService.NAVIGATION);
138 try {
139 domain.scheduleNotification(
140 result.context, source, AnalysisService.NAVIGATION);
141 } finally {
142 test.contributorMayAddRegion = false;
143 }
144 }); 130 });
145 } 131 }
146 } 132 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_analysis.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698