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

Side by Side Diff: packages/initialize/lib/build/initializer_plugin.dart

Issue 3014633002: Roll to pickup pool changes (Closed)
Patch Set: Created 3 years, 2 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 | « packages/initialize/CHANGELOG.md ('k') | packages/initialize/lib/src/init_method.dart » ('j') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library initialize.build.initializer_plugin; 4 library initialize.build.initializer_plugin;
5 5
6 import 'package:analyzer/dart/ast/ast.dart'; 6 import 'package:analyzer/dart/ast/ast.dart';
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/generated/constant.dart'; 8 import 'package:analyzer/src/generated/constant.dart';
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:code_transformers/resolver.dart'; 10 import 'package:code_transformers/resolver.dart';
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 buffer.write('}'); 228 buffer.write('}');
229 } else if (expression is Identifier) { 229 } else if (expression is Identifier) {
230 var element = expression.bestElement; 230 var element = expression.bestElement;
231 if (element == null) { 231 if (element == null) {
232 logger.error('Unable to get `bestElement` for expression: $expression'); 232 logger.error('Unable to get `bestElement` for expression: $expression');
233 } else if (!element.isPublic) { 233 } else if (!element.isPublic) {
234 // Inline the evaluated value of private identifiers. 234 // Inline the evaluated value of private identifiers.
235 buffer.write(_evaluateExpression(expression, pluginData)); 235 buffer.write(_evaluateExpression(expression, pluginData));
236 } else { 236 } else {
237 libraryPrefixes.putIfAbsent( 237 libraryPrefixes.putIfAbsent(
238 element.library, () => 'i${libraryPrefixes.length}'); 238 element.library, () => 'i${libraryPrefixes.length}');
239 239
240 buffer.write('${libraryPrefixes[element.library]}.'); 240 buffer.write('${libraryPrefixes[element.library]}.');
241 if (element is ClassElement) { 241 if (element is ClassElement) {
242 buffer.write(element.name); 242 buffer.write(element.name);
243 } else if (element is PropertyAccessorElement) { 243 } else if (element is PropertyAccessorElement) {
244 var variable = element.variable; 244 var variable = element.variable;
245 if (variable is FieldElement) { 245 if (variable is FieldElement) {
246 buffer.write('${variable.enclosingElement.name}.'); 246 buffer.write('${variable.enclosingElement.name}.');
247 } 247 }
248 buffer.write('${variable.name}'); 248 buffer.write('${variable.name}');
249 } else { 249 } else {
250 logger.error('Unsupported argument to initializer constructor.'); 250 logger.error('Unsupported argument to initializer constructor.');
251 } 251 }
252 } 252 }
253 } else if (expression is PropertyAccess) { 253 } else if (expression is PropertyAccess) {
254 buffer.write(buildExpression(expression.target, pluginData)); 254 buffer.write(buildExpression(expression.target, pluginData));
255 buffer.write('.${expression.propertyName}'); 255 buffer.write('.${expression.propertyName}');
256 } else if (expression is InstanceCreationExpression) { 256 } else if (expression is InstanceCreationExpression) {
257 logger.error('Unsupported expression in initializer, found $expression. ' 257 logger.error('Unsupported expression in initializer, found $expression. '
258 'Instance creation expressions are not supported (yet). Instead, ' 258 'Instance creation expressions are not supported (yet). Instead, '
259 'please assign it to a const variable and use that instead.'); 259 'please assign it to a const variable and use that instead.');
260 } else { 260 } else {
261 buffer.write(_evaluateExpression(expression, pluginData)); 261 buffer.write(_evaluateExpression(expression, pluginData));
262 } 262 }
263 return buffer.toString(); 263 return buffer.toString();
264 } 264 }
265 265
266 _evaluateExpression( 266 _evaluateExpression(Expression expression, InitializerPluginData pluginData) {
267 Expression expression, InitializerPluginData pluginData) {
268 var logger = pluginData.logger; 267 var logger = pluginData.logger;
269 var result = pluginData.resolver.evaluateConstant( 268 var result = pluginData.resolver.evaluateConstant(
270 pluginData.initializer.targetElement.library, expression); 269 pluginData.initializer.targetElement.library, expression);
271 if (!result.isValid) { 270 if (!result.isValid) {
272 logger.error('Invalid expression in initializer, found $expression. ' 271 logger.error('Invalid expression in initializer, found $expression. '
273 'And got the following errors: ${result.errors}.'); 272 'And got the following errors: ${result.errors}.');
274 return null; 273 return null;
275 } 274 }
276 275
277 var value = _getValue(result.value); 276 var value = _getValue(result.value);
(...skipping 17 matching lines...) Expand all
295 } 294 }
296 295
297 // Gets an actual value for a [DartObject]. 296 // Gets an actual value for a [DartObject].
298 _getValue(DartObject object) { 297 _getValue(DartObject object) {
299 if (object == null) return null; 298 if (object == null) return null;
300 var value = object.toBoolValue() ?? 299 var value = object.toBoolValue() ??
301 object.toDoubleValue() ?? 300 object.toDoubleValue() ??
302 object.toIntValue() ?? 301 object.toIntValue() ??
303 object.toStringValue(); 302 object.toStringValue();
304 if (value == null) { 303 if (value == null) {
305 value = object.toListValue(); 304 List list = object.toListValue();
306 if (value != null) { 305 if (list != null) {
307 return value.map((DartObject element) => _getValue(element)).toList(); 306 return list.map((DartObject element) => _getValue(element)).toList();
308 } 307 }
309 Map<DartObject, DartObject> map = object.toMapValue(); 308 Map<DartObject, DartObject> map = object.toMapValue();
310 if (map != null) { 309 if (map != null) {
311 Map result = {}; 310 Map result = {};
312 map.forEach((DartObject key, DartObject value) { 311 map.forEach((DartObject key, DartObject value) {
313 dynamic mappedKey = _getValue(key); 312 dynamic mappedKey = _getValue(key);
314 if (mappedKey != null) { 313 if (mappedKey != null) {
315 result[mappedKey] = _getValue(value); 314 result[mappedKey] = _getValue(value);
316 } 315 }
317 }); 316 });
318 return result; 317 return result;
319 } 318 }
320 } 319 }
321 return value; 320 return value;
322 } 321 }
323 } 322 }
OLDNEW
« no previous file with comments | « packages/initialize/CHANGELOG.md ('k') | packages/initialize/lib/src/init_method.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698