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

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

Issue 1337143002: Add OCCURRENCES_CONTRIBUTOR_EXTENSION_POINT_ID. (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
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_core.dart';
11 import 'package:analysis_server/analysis/occurrences_core.dart';
11 import 'package:analysis_server/plugin/navigation.dart'; 12 import 'package:analysis_server/plugin/navigation.dart';
13 import 'package:analysis_server/plugin/occurrences.dart';
12 import 'package:analysis_server/src/constants.dart'; 14 import 'package:analysis_server/src/constants.dart';
13 import 'package:analysis_server/src/protocol.dart'; 15 import 'package:analysis_server/src/protocol.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 16 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/task/dart.dart'; 18 import 'package:analyzer/task/dart.dart';
17 import 'package:plugin/plugin.dart'; 19 import 'package:plugin/plugin.dart';
18 import 'package:test_reflective_loader/test_reflective_loader.dart'; 20 import 'package:test_reflective_loader/test_reflective_loader.dart';
19 import 'package:unittest/unittest.dart'; 21 import 'package:unittest/unittest.dart';
20 22
21 import '../analysis_abstract.dart'; 23 import '../analysis_abstract.dart';
22 import '../utils.dart'; 24 import '../utils.dart';
23 25
24 main() { 26 main() {
25 initializeTestEnvironment(); 27 initializeTestEnvironment();
26 if (AnalysisEngine.instance.useTaskModel) { 28 if (AnalysisEngine.instance.useTaskModel) {
27 defineReflectiveTests(SetAnalysisDomainTest); 29 defineReflectiveTests(SetAnalysisDomainTest);
28 } 30 }
29 } 31 }
30 32
31 /** 33 /**
32 * This test uses [SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID] and 34 * This test uses [SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID] and
33 * [NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID] extension points to validate 35 * [NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID] extension points to validate
34 * that plugins can listen for analysis and force sending navigation 36 * that plugins can listen for analysis and force sending navigation
35 * notifications. 37 * notifications.
36 */ 38 */
37 @reflectiveTest 39 @reflectiveTest
38 class SetAnalysisDomainTest extends AbstractAnalysisTest { 40 class SetAnalysisDomainTest extends AbstractAnalysisTest {
39 final Set<String> parsedUnitFiles = new Set<String>(); 41 final Set<String> parsedUnitFiles = new Set<String>();
40 42
41 List<NavigationRegion> regions; 43 AnalysisNavigationParams navigationParams;
42 List<NavigationTarget> targets; 44 AnalysisOccurrencesParams occurrencesParams;
43 List<String> targetFiles;
44 45
45 @override 46 @override
46 void addServerPlugins(List<Plugin> plugins) { 47 void addServerPlugins(List<Plugin> plugins) {
47 var plugin = new TestSetAnalysisDomainPlugin(this); 48 var plugin = new TestSetAnalysisDomainPlugin(this);
48 plugins.add(plugin); 49 plugins.add(plugin);
49 } 50 }
50 51
51 @override 52 @override
52 void processNotification(Notification notification) { 53 void processNotification(Notification notification) {
53 if (notification.event == ANALYSIS_NAVIGATION) { 54 if (notification.event == ANALYSIS_NAVIGATION) {
54 var params = new AnalysisNavigationParams.fromNotification(notification); 55 var params = new AnalysisNavigationParams.fromNotification(notification);
55 if (params.file == testFile) { 56 if (params.file == testFile) {
56 regions = params.regions; 57 navigationParams = params;
57 targets = params.targets; 58 }
58 targetFiles = params.files; 59 }
60 if (notification.event == ANALYSIS_OCCURRENCES) {
61 var params = new AnalysisOccurrencesParams.fromNotification(notification);
62 if (params.file == testFile) {
63 occurrencesParams = params;
59 } 64 }
60 } 65 }
61 } 66 }
62 67
63 Future test_contributorIsInvoked() async { 68 Future test_contributorIsInvoked() async {
64 createProject(); 69 createProject();
65 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile); 70 addAnalysisSubscription(AnalysisService.NAVIGATION, testFile);
71 addAnalysisSubscription(AnalysisService.OCCURRENCES, testFile);
66 addTestFile('// usually no navigation'); 72 addTestFile('// usually no navigation');
67 await server.onAnalysisComplete; 73 await server.onAnalysisComplete;
68 // we have PARSED_UNIT 74 // we have PARSED_UNIT
69 expect(parsedUnitFiles, contains(testFile)); 75 expect(parsedUnitFiles, contains(testFile));
70 // we have an additional navigation region/target 76 // we have an additional navigation region/target
71 expect(regions, hasLength(1));
72 { 77 {
73 NavigationRegion region = regions.single; 78 expect(navigationParams.regions, hasLength(1));
74 expect(region.offset, 1); 79 {
75 expect(region.length, 5); 80 NavigationRegion region = navigationParams.regions.single;
76 expect(region.targets.single, 0); 81 expect(region.offset, 1);
82 expect(region.length, 5);
83 expect(region.targets.single, 0);
84 }
85 {
86 NavigationTarget target = navigationParams.targets.single;
87 expect(target.fileIndex, 0);
88 expect(target.offset, 1);
89 expect(target.length, 2);
90 expect(target.startLine, 3);
91 expect(target.startColumn, 4);
92 }
93 expect(navigationParams.files.single, '/testLocation.dart');
77 } 94 }
95 // we have additional occurrences
78 { 96 {
79 NavigationTarget target = targets.single; 97 expect(occurrencesParams.occurrences, hasLength(1));
80 expect(target.fileIndex, 0); 98 Occurrences occurrences = occurrencesParams.occurrences.single;
81 expect(target.offset, 1); 99 expect(occurrences.element.name, 'TestElement');
82 expect(target.length, 2); 100 expect(occurrences.length, 5);
83 expect(target.startLine, 3); 101 expect(occurrences.offsets, unorderedEquals([1, 2, 3]));
84 expect(target.startColumn, 4);
85 } 102 }
86 expect(targetFiles.single, '/testLocation.dart');
87 } 103 }
88 } 104 }
89 105
90 class TestNavigationContributor implements NavigationContributor { 106 class TestNavigationContributor implements NavigationContributor {
91 final SetAnalysisDomainTest test; 107 final SetAnalysisDomainTest test;
92 108
93 TestNavigationContributor(this.test); 109 TestNavigationContributor(this.test);
94 110
95 @override 111 @override
96 void computeNavigation(NavigationCollector collector, AnalysisContext context, 112 void computeNavigation(NavigationCollector collector, AnalysisContext context,
97 Source source, int offset, int length) { 113 Source source, int offset, int length) {
98 collector.addRegion(1, 5, ElementKind.CLASS, 114 collector.addRegion(1, 5, ElementKind.CLASS,
99 new Location('/testLocation.dart', 1, 2, 3, 4)); 115 new Location('/testLocation.dart', 1, 2, 3, 4));
100 } 116 }
101 } 117 }
102 118
119 class TestOccurrencesContributor implements OccurrencesContributor {
120 final SetAnalysisDomainTest test;
121
122 TestOccurrencesContributor(this.test);
123
124 @override
125 void computeOccurrences(
126 OccurrencesCollector collector, AnalysisContext context, Source source) {
127 collector.addOccurrences(new Occurrences(
128 new Element(ElementKind.UNKNOWN, 'TestElement', 0), <int>[1, 2, 3], 5));
129 }
130 }
131
103 class TestSetAnalysisDomainPlugin implements Plugin { 132 class TestSetAnalysisDomainPlugin implements Plugin {
104 final SetAnalysisDomainTest test; 133 final SetAnalysisDomainTest test;
105 134
106 TestSetAnalysisDomainPlugin(this.test); 135 TestSetAnalysisDomainPlugin(this.test);
107 136
108 @override 137 @override
109 String get uniqueIdentifier => 'test'; 138 String get uniqueIdentifier => 'test';
110 139
111 @override 140 @override
112 void registerExtensionPoints(RegisterExtensionPoint register) {} 141 void registerExtensionPoints(RegisterExtensionPoint register) {}
113 142
114 @override 143 @override
115 void registerExtensions(RegisterExtension register) { 144 void registerExtensions(RegisterExtension register) {
116 register(SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID, _setAnalysisDomain); 145 register(SET_ANALYSIS_DOMAIN_EXTENSION_POINT_ID, _setAnalysisDomain);
117 register(NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID, 146 register(NAVIGATION_CONTRIBUTOR_EXTENSION_POINT_ID,
118 new TestNavigationContributor(test)); 147 new TestNavigationContributor(test));
148 register(OCCURRENCES_CONTRIBUTOR_EXTENSION_POINT_ID,
149 new TestOccurrencesContributor(test));
119 } 150 }
120 151
121 void _setAnalysisDomain(AnalysisDomain domain) { 152 void _setAnalysisDomain(AnalysisDomain domain) {
122 domain.onResultComputed(PARSED_UNIT).listen((result) { 153 domain.onResultComputed(PARSED_UNIT).listen((result) {
123 expect(result.context, isNotNull); 154 expect(result.context, isNotNull);
124 expect(result.target, isNotNull); 155 expect(result.target, isNotNull);
125 expect(result.value, isNotNull); 156 expect(result.value, isNotNull);
126 Source source = result.target.source; 157 Source source = result.target.source;
127 test.parsedUnitFiles.add(source.fullName); 158 test.parsedUnitFiles.add(source.fullName);
128 domain.scheduleNotification( 159 domain.scheduleNotification(
129 result.context, source, AnalysisService.NAVIGATION); 160 result.context, source, AnalysisService.NAVIGATION);
161 domain.scheduleNotification(
162 result.context, source, AnalysisService.OCCURRENCES);
130 }); 163 });
131 } 164 }
132 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698