| OLD | NEW |
| 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 | 4 |
| 5 /** | 5 /** |
| 6 * This file contains code to generate serialization/deserialization logic for | 6 * This file contains code to generate serialization/deserialization logic for |
| 7 * summaries based on an "IDL" description of the summary format (written in | 7 * summaries based on an "IDL" description of the summary format (written in |
| 8 * stylized Dart). | 8 * stylized Dart). |
| 9 * | 9 * |
| 10 * For each class in the "IDL" input, two corresponding classes are generated: | 10 * For each class in the "IDL" input, two corresponding classes are generated: |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 String defSuffix = def == null ? '' : ' ??= $def'; | 561 String defSuffix = def == null ? '' : ' ??= $def'; |
| 562 out(); | 562 out(); |
| 563 out('@override'); | 563 out('@override'); |
| 564 if (field.isDeprecated) { | 564 if (field.isDeprecated) { |
| 565 out('$typeStr get $fieldName => $_throwDeprecated;'); | 565 out('$typeStr get $fieldName => $_throwDeprecated;'); |
| 566 } else { | 566 } else { |
| 567 out('$typeStr get $fieldName => _$fieldName$defSuffix;'); | 567 out('$typeStr get $fieldName => _$fieldName$defSuffix;'); |
| 568 out(); | 568 out(); |
| 569 outDoc(field.documentation); | 569 outDoc(field.documentation); |
| 570 constructorParams.add('$typeStr $fieldName'); | 570 constructorParams.add('$typeStr $fieldName'); |
| 571 out('void set $fieldName($typeStr _value) {'); | 571 out('void set $fieldName($typeStr value) {'); |
| 572 indent(() { | 572 indent(() { |
| 573 String stateFieldName = '_' + fieldName; | 573 String stateFieldName = '_' + fieldName; |
| 574 // Validate that int(s) are non-negative. | 574 // Validate that int(s) are non-negative. |
| 575 if (fieldType.typeName == 'int') { | 575 if (fieldType.typeName == 'int') { |
| 576 if (!fieldType.isList) { | 576 if (!fieldType.isList) { |
| 577 out('assert(_value == null || _value >= 0);'); | 577 out('assert(value == null || value >= 0);'); |
| 578 } else { | 578 } else { |
| 579 out('assert(_value == null || _value.every((e) => e >= 0));'); | 579 out('assert(value == null || value.every((e) => e >= 0));'); |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 // Set the value. | 582 // Set the value. |
| 583 out('$stateFieldName = _value;'); | 583 out('this.$stateFieldName = value;'); |
| 584 }); | 584 }); |
| 585 out('}'); | 585 out('}'); |
| 586 } | 586 } |
| 587 } | 587 } |
| 588 // Generate constructor. | 588 // Generate constructor. |
| 589 out(); | 589 out(); |
| 590 out('$builderName({${constructorParams.join(', ')}})'); | 590 out('$builderName({${constructorParams.join(', ')}})'); |
| 591 List<idlModel.FieldDeclaration> fields = cls.fields.toList(); | 591 List<idlModel.FieldDeclaration> fields = cls.fields.toList(); |
| 592 for (int i = 0; i < fields.length; i++) { | 592 for (int i = 0; i < fields.length; i++) { |
| 593 idlModel.FieldDeclaration field = fields[i]; | 593 idlModel.FieldDeclaration field = fields[i]; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 return token.lexeme.split('\n').map((String line) { | 1023 return token.lexeme.split('\n').map((String line) { |
| 1024 if (line.startsWith(indent)) { | 1024 if (line.startsWith(indent)) { |
| 1025 line = line.substring(indent.length); | 1025 line = line.substring(indent.length); |
| 1026 } | 1026 } |
| 1027 return line; | 1027 return line; |
| 1028 }).join('\n'); | 1028 }).join('\n'); |
| 1029 } | 1029 } |
| 1030 return null; | 1030 return null; |
| 1031 } | 1031 } |
| 1032 } | 1032 } |
| OLD | NEW |