| OLD | NEW |
| 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 library dart2js.js_emitter.full_emitter.class_builder; | 5 library dart2js.js_emitter.full_emitter.class_builder; |
| 6 | 6 |
| 7 import '../../elements/elements.dart' | 7 import '../../elements/elements.dart' show Entity; |
| 8 show | 8 import '../../elements/entities.dart'; |
| 9 ClassElement, | |
| 10 Element; | |
| 11 import '../../js/js.dart' as jsAst; | 9 import '../../js/js.dart' as jsAst; |
| 12 import '../../js/js.dart' show js; | 10 import '../../js/js.dart' show js; |
| 13 import '../../js_backend/js_backend.dart' | 11 import '../../js_backend/js_backend.dart' show Namer; |
| 14 show | |
| 15 Namer; | |
| 16 | 12 |
| 17 /** | 13 /** |
| 18 * A data structure for collecting fragments of a class definition. | 14 * A data structure for collecting fragments of a class definition. |
| 19 */ | 15 */ |
| 20 class ClassBuilder { | 16 class ClassBuilder { |
| 21 final List<jsAst.Property> properties = <jsAst.Property>[]; | 17 final List<jsAst.Property> properties = <jsAst.Property>[]; |
| 22 final List<jsAst.Literal> fields = <jsAst.Literal>[]; | 18 final List<jsAst.Literal> fields = <jsAst.Literal>[]; |
| 23 | 19 |
| 24 jsAst.Name superName; | 20 jsAst.Name superName; |
| 25 jsAst.Node functionType; | 21 jsAst.Node functionType; |
| 26 List<jsAst.Node> fieldMetadata; | 22 List<jsAst.Node> fieldMetadata; |
| 27 | 23 |
| 28 final Element element; | 24 final Entity element; |
| 29 final Namer namer; | 25 final Namer namer; |
| 30 final bool isForActualClass; | 26 final bool isForActualClass; |
| 31 | 27 |
| 32 ClassBuilder(this.element, this.namer, this.isForActualClass); | 28 ClassBuilder(this.element, this.namer, this.isForActualClass); |
| 33 | 29 |
| 34 ClassBuilder.forClass(ClassElement cls, this.namer) | 30 ClassBuilder.forClass(ClassEntity cls, this.namer) |
| 35 : isForActualClass = true, | 31 : isForActualClass = true, |
| 36 element = cls; | 32 element = cls; |
| 37 | 33 |
| 38 ClassBuilder.forStatics(this.element, this.namer) : isForActualClass = false; | 34 ClassBuilder.forStatics(this.element, this.namer) : isForActualClass = false; |
| 39 | 35 |
| 40 jsAst.Property addProperty(jsAst.Literal name, jsAst.Expression value) { | 36 jsAst.Property addProperty(jsAst.Literal name, jsAst.Expression value) { |
| 41 jsAst.Property property = new jsAst.Property(js.quoteName(name), value); | 37 jsAst.Property property = new jsAst.Property(js.quoteName(name), value); |
| 42 properties.add(property); | 38 properties.add(property); |
| 43 return property; | 39 return property; |
| 44 } | 40 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 fieldsAndProperties = <jsAst.Property>[]; | 87 fieldsAndProperties = <jsAst.Property>[]; |
| 92 fieldsAndProperties.add(new jsAst.Property( | 88 fieldsAndProperties.add(new jsAst.Property( |
| 93 js.string(namer.classDescriptorProperty), classData)); | 89 js.string(namer.classDescriptorProperty), classData)); |
| 94 fieldsAndProperties.addAll(properties); | 90 fieldsAndProperties.addAll(properties); |
| 95 } else { | 91 } else { |
| 96 fieldsAndProperties = properties; | 92 fieldsAndProperties = properties; |
| 97 } | 93 } |
| 98 return new jsAst.ObjectInitializer(fieldsAndProperties, isOneLiner: false); | 94 return new jsAst.ObjectInitializer(fieldsAndProperties, isOneLiner: false); |
| 99 } | 95 } |
| 100 } | 96 } |
| OLD | NEW |