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

Side by Side Diff: pkg/polymer/lib/src/instance.dart

Issue 26734004: use symbol literals instead of const ctor in packages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of polymer; 5 part of polymer;
6 6
7 /** 7 /**
8 * Use this annotation to publish a field as an attribute. For example: 8 * Use this annotation to publish a field as an attribute. For example:
9 * 9 *
10 * class MyPlaybackElement extends PolymerElement { 10 * class MyPlaybackElement extends PolymerElement {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // TODO(jmesserly): this should probably take a ClassMirror instead of 327 // TODO(jmesserly): this should probably take a ClassMirror instead of
328 // TypeMirror, but it is currently impossible to get from a TypeMirror to a 328 // TypeMirror, but it is currently impossible to get from a TypeMirror to a
329 // ClassMirror. 329 // ClassMirror.
330 Object deserializeValue(String value, Object defaultValue, TypeMirror type) => 330 Object deserializeValue(String value, Object defaultValue, TypeMirror type) =>
331 deserialize.deserializeValue(value, defaultValue, type); 331 deserialize.deserializeValue(value, defaultValue, type);
332 332
333 String serializeValue(Object value, TypeMirror inferredType) { 333 String serializeValue(Object value, TypeMirror inferredType) {
334 if (value == null) return null; 334 if (value == null) return null;
335 335
336 final type = inferredType.qualifiedName; 336 final type = inferredType.qualifiedName;
337 if (type == const Symbol('dart.core.bool')) { 337 if (type == #dart.core.bool) {
338 return _toBoolean(value) ? '' : null; 338 return _toBoolean(value) ? '' : null;
339 } else if (type == const Symbol('dart.core.String') 339 } else if (type == #dart.core.String
340 || type == const Symbol('dart.core.int') 340 || type == #dart.core.int
341 || type == const Symbol('dart.core.double')) { 341 || type == #dart.core.double) {
342 return '$value'; 342 return '$value';
343 } 343 }
344 return null; 344 return null;
345 } 345 }
346 346
347 void reflectPropertyToAttribute(String name) { 347 void reflectPropertyToAttribute(String name) {
348 // TODO(sjmiles): consider memoizing this 348 // TODO(sjmiles): consider memoizing this
349 final self = reflect(this); 349 final self = reflect(this);
350 // try to intelligently serialize property value 350 // try to intelligently serialize property value
351 // TODO(jmesserly): cache symbol? 351 // TODO(jmesserly): cache symbol?
352 final propValue = self.getField(new Symbol(name)).reflectee; 352 final propValue = self.getField(new Symbol(name)).reflectee;
353 final property = _declaration._publish[name]; 353 final property = _declaration._publish[name];
354 var inferredType = _inferPropertyType(propValue, property); 354 var inferredType = _inferPropertyType(propValue, property);
355 final serializedValue = serializeValue(propValue, inferredType); 355 final serializedValue = serializeValue(propValue, inferredType);
356 // boolean properties must reflect as boolean attributes 356 // boolean properties must reflect as boolean attributes
357 if (serializedValue != null) { 357 if (serializedValue != null) {
358 attributes[name] = serializedValue; 358 attributes[name] = serializedValue;
359 // TODO(sorvell): we should remove attr for all properties 359 // TODO(sorvell): we should remove attr for all properties
360 // that have undefined serialization; however, we will need to 360 // that have undefined serialization; however, we will need to
361 // refine the attr reflection system to achieve this; pica, for example, 361 // refine the attr reflection system to achieve this; pica, for example,
362 // relies on having inferredType object properties not removed as 362 // relies on having inferredType object properties not removed as
363 // attrs. 363 // attrs.
364 } else if (inferredType.qualifiedName == const Symbol('dart.core.bool')) { 364 } else if (inferredType.qualifiedName == #dart.core.bool) {
365 attributes.remove(name); 365 attributes.remove(name);
366 } 366 }
367 } 367 }
368 368
369 /** 369 /**
370 * Creates the document fragment to use for each instance of the custom 370 * Creates the document fragment to use for each instance of the custom
371 * element, given the `<template>` node. By default this is equivalent to: 371 * element, given the `<template>` node. By default this is equivalent to:
372 * 372 *
373 * template.createInstance(this, polymerSyntax); 373 * template.createInstance(this, polymerSyntax);
374 * 374 *
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 903
904 bool _toBoolean(value) => null != value && false != value; 904 bool _toBoolean(value) => null != value && false != value;
905 905
906 TypeMirror _propertyType(DeclarationMirror property) => 906 TypeMirror _propertyType(DeclarationMirror property) =>
907 property is VariableMirror 907 property is VariableMirror
908 ? (property as VariableMirror).type 908 ? (property as VariableMirror).type
909 : (property as MethodMirror).returnType; 909 : (property as MethodMirror).returnType;
910 910
911 TypeMirror _inferPropertyType(Object value, DeclarationMirror property) { 911 TypeMirror _inferPropertyType(Object value, DeclarationMirror property) {
912 var type = _propertyType(property); 912 var type = _propertyType(property);
913 if (type.qualifiedName == const Symbol('dart.core.Object') || 913 if (type.qualifiedName == #dart.core.Object ||
914 type.qualifiedName == const Symbol('dynamic')) { 914 type.qualifiedName == #dynamic) {
915 // Attempt to infer field type from the default value. 915 // Attempt to infer field type from the default value.
916 if (value != null) { 916 if (value != null) {
917 type = reflect(value).type; 917 type = reflect(value).type;
918 } 918 }
919 } 919 }
920 return type; 920 return type;
921 } 921 }
922 922
923 final Logger _observeLog = new Logger('polymer.observe'); 923 final Logger _observeLog = new Logger('polymer.observe');
924 final Logger _eventsLog = new Logger('polymer.events'); 924 final Logger _eventsLog = new Logger('polymer.events');
925 final Logger _unbindLog = new Logger('polymer.unbind'); 925 final Logger _unbindLog = new Logger('polymer.unbind');
926 final Logger _bindLog = new Logger('polymer.bind'); 926 final Logger _bindLog = new Logger('polymer.bind');
927 927
928 final Expando _shadowHost = new Expando<Element>(); 928 final Expando _shadowHost = new Expando<Element>();
929 929
930 final Expando _eventHandledTable = new Expando<Set<Node>>(); 930 final Expando _eventHandledTable = new Expando<Set<Node>>();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698