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

Side by Side Diff: pkg/analysis_server/lib/src/domain_context.dart

Issue 137703010: Add server and request handlers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library domain.context;
6
7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/source.dart';
9
10 import 'analysis_server.dart';
11 import 'protocol.dart';
12
13 /**
14 * Instances of the class [ContextDomainHandler] implement a [RequestHandler]
15 * that handles requests in the server domain.
danrubel 2014/01/22 01:04:07 server domain -> context domain ?
Brian Wilkerson 2014/01/24 21:49:27 Done
16 */
17 class ContextDomainHandler implements RequestHandler {
18 /**
19 * The name of the context.applyChanges request.
20 */
21 static const String APPLY_CHANGES_NAME = 'context.applyChanges';
22
23 /**
24 * The name of the context.setOptions request.
25 */
26 static const String SET_OPTIONS_NAME = 'context.setOptions';
27
28 /**
29 * The name of the context.setPrioritySources request.
30 */
31 static const String SET_PRIORITY_SOURCES_NAME = 'context.setPrioritySources';
32
33 /**
34 * The name of the changes parameter.
35 */
36 static const String CHANGES_PARAM = 'changes';
37
38 /**
39 * The name of the contextId parameter.
40 */
41 static const String CONTEXT_ID_PARAM = 'contextId';
42
43 /**
44 * The name of the options parameter.
45 */
46 static const String OPTIONS_PARAM = 'options';
47
48 /**
49 * The name of the sources parameter.
50 */
51 static const String SOURCES_PARAM = 'sources';
52
53 /**
54 * The name of the cacheSize option.
55 */
56 static const String CACHE_SIZE_OPTION = 'cacheSize';
57
58 /**
59 * The name of the generateHints option.
60 */
61 static const String GENERATE_HINTS_OPTION = 'generateHints';
62
63 /**
64 * The name of the generateDart2jsHints option.
65 */
66 static const String GENERATE_DART2JS_OPTION = 'generateDart2jsHints';
67
68 /**
69 * The name of the provideErrors option.
70 */
71 static const String PROVIDE_ERRORS_OPTION = 'provideErrors';
72
73 /**
74 * The name of the provideNavigation option.
75 */
76 static const String PROVIDE_NAVIGATION_OPTION = 'provideNavigation';
77
78 /**
79 * The name of the provideOutline option.
80 */
81 static const String PROVIDE_OUTLINE_OPTION = 'provideOutline';
82
83 /**
84 * The analysis server that is using this handler to process requests.
85 */
86 final AnalysisServer server;
87
88 /**
89 * Initialize a newly created handler to handle requests for the given [server ].
90 */
91 ContextDomainHandler(this.server);
92
93 @override
94 Response handleRequest(Request request) {
95 try {
96 String requestName = request.method;
97 if (requestName == APPLY_CHANGES_NAME) {
98 applyChanges(request);
99 } else if (requestName == SET_OPTIONS_NAME) {
100 setOptions(request);
101 } else if (requestName == SET_PRIORITY_SOURCES_NAME) {
102 setPrioritySources(request);
103 }
104 } on RequestFailure catch (exception) {
105 return exception.response;
106 }
107 }
108
109 /**
110 * Inform the specified context that the changes encoded in the change set
111 * have been made. Any invalidated analysis results will be flushed from the
112 * context.
113 */
114 Response applyChanges(Request request) {
115 AnalysisContext context = getAnalysisContext(request);
116 Map<String, Object> changesData = request.getRequiredParameter(CHANGES_PARAM );
117 ChangeSet changeSet = createChangeSet(changesData);
118
119 context.applyChanges(changeSet);
120 }
121
122 /**
123 * Convert the given JSON object into a [ChangeSet].
124 */
125 ChangeSet createChangeSet(Map<String, Object> jsonData) {
126 // TODO(brianwilkerson) Implement this.
127 return null;
128 }
129
130 /**
131 * Set the options controlling analysis within a context to the given set of
132 * options.
133 */
134 Response setOptions(Request request) {
135 AnalysisContext context = getAnalysisContext(request);
136
137 context.analysisOptions = createAnalysisOptions(request);
138 }
139
140 /**
141 * Return the set of analysis options associated with the given [request], or
142 * throw a [RequestFailure] exception if the analysis options are not valid.
143 */
144 AnalysisOptions createAnalysisOptions(Request request) {
145 Map<String, Object> optionsData = request.getRequiredParameter(OPTIONS_PARAM );
146 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
147 optionsData.forEach((String key, Object value) {
148 if (key == CACHE_SIZE_OPTION) {
149 options.cacheSize = request.toInt(value);
150 } else if (key == GENERATE_HINTS_OPTION) {
151 options.hint = request.toBool(value);
152 } else if (key == GENERATE_DART2JS_OPTION) {
153 options.dart2jsHint = request.toBool(value);
154 } else if (key == PROVIDE_ERRORS_OPTION) {
155 // options.provideErrors = toBool(request, value);
156 } else if (key == PROVIDE_NAVIGATION_OPTION) {
157 // options.provideNavigation = toBool(request, value);
158 } else if (key == PROVIDE_OUTLINE_OPTION) {
159 // options.provideOutline = toBool(request, value);
160 } else {
161 throw new RequestFailure(new Response.unknownAnalysisOption(request, key ));
162 }
163 });
164 return options;
165 }
166
167 /**
168 * Set the priority sources in the specified context to the sources in the
169 * given array.
170 */
171 Response setPrioritySources(Request request) {
172 AnalysisContext context = getAnalysisContext(request);
173 List<String> sourcesData = request.getRequiredParameter(SOURCES_PARAM);
174 List<Source> sources = convertToSources(context.sourceFactory, sourcesData);
175
176 context.analysisPriorityOrder = sources;
177 }
178
179 /**
180 * Convert the given list of strings into a list of sources owned by the given
181 * [sourceFactory].
182 */
183 List<Source> convertToSources(SourceFactory sourceFactory, List<String> source sData) {
184 List<Source> sources = new List<Source>();
185 sourcesData.forEach((String string) {
186 sources.add(sourceFactory.fromEncoding(string));
187 });
188 return sources;
189 }
190
191 /**
192 * Return the analysis context specified by the given request, or throw a
193 * [RequestFailure] exception if either there is no specified context or if
194 * the specified context does not exist.
195 */
196 AnalysisContext getAnalysisContext(Request request) {
197 String contextId = request.getRequiredParameter(CONTEXT_ID_PARAM);
198 AnalysisContext context = server.contextMap[contextId];
199 if (context == null) {
200 throw new RequestFailure(new Response.contextDoesNotExist(request));
201 }
202 return context;
203 }
204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698