OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 buffer.write(' show '); | 593 buffer.write(' show '); |
594 buffer.write(e.shownNames.join(', ')); | 594 buffer.write(e.shownNames.join(', ')); |
595 } else if (e is HideElementCombinator) { | 595 } else if (e is HideElementCombinator) { |
596 buffer.write(' hide '); | 596 buffer.write(' hide '); |
597 buffer.write(e.hiddenNames.join(', ')); | 597 buffer.write(e.hiddenNames.join(', ')); |
598 } | 598 } |
599 } | 599 } |
600 | 600 |
601 void writeParameterElement(ParameterElement e) { | 601 void writeParameterElement(ParameterElement e) { |
602 String defaultValueSeparator; | 602 String defaultValueSeparator; |
603 Expression defaultValue = e is ConstVariableElement | 603 Expression defaultValue; |
604 ? (e as ConstVariableElement).constantInitializer | |
605 : null; | |
606 String closeString; | 604 String closeString; |
607 ParameterKind kind = e.parameterKind; | 605 ParameterKind kind = e.parameterKind; |
608 if (kind == ParameterKind.REQUIRED) { | 606 if (kind == ParameterKind.REQUIRED) { |
609 closeString = ''; | 607 closeString = ''; |
610 } else if (kind == ParameterKind.POSITIONAL) { | 608 } else if (kind == ParameterKind.POSITIONAL) { |
611 buffer.write('['); | 609 buffer.write('['); |
612 defaultValueSeparator = ' = '; | 610 defaultValueSeparator = ' = '; |
| 611 defaultValue = (e as ConstVariableElement).constantInitializer; |
613 closeString = ']'; | 612 closeString = ']'; |
614 } else if (kind == ParameterKind.NAMED) { | 613 } else if (kind == ParameterKind.NAMED) { |
615 buffer.write('{'); | 614 buffer.write('{'); |
616 defaultValueSeparator = ': '; | 615 defaultValueSeparator = ': '; |
| 616 defaultValue = (e as ConstVariableElement).constantInitializer; |
617 closeString = '}'; | 617 closeString = '}'; |
618 } else { | 618 } else { |
619 fail('Unknown parameter kind: $kind'); | 619 fail('Unknown parameter kind: $kind'); |
620 } | 620 } |
621 | 621 |
| 622 // Kernel desugars omitted default parameter values to 'null'. |
| 623 // Analyzer does not set initializer at all. |
| 624 // It is not an interesting distinction, so we skip NullLiteral(s). |
| 625 if (defaultValue is NullLiteral) { |
| 626 defaultValue = null; |
| 627 } |
| 628 |
622 writeMetadata(e, '', ' '); | 629 writeMetadata(e, '', ' '); |
623 | 630 |
624 writeIf(e.isCovariant, 'covariant '); | 631 writeIf(e.isCovariant, 'covariant '); |
625 writeIf(e.isFinal, 'final '); | 632 writeIf(e.isFinal, 'final '); |
626 | 633 |
627 writeType2(e.type); | 634 writeType2(e.type); |
628 | 635 |
629 if (e is FieldFormalParameterElement) { | 636 if (e is FieldFormalParameterElement) { |
630 buffer.write('this.'); | 637 buffer.write('this.'); |
631 } | 638 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 return components.join(';'); | 878 return components.join(';'); |
872 } | 879 } |
873 } | 880 } |
874 | 881 |
875 class _Replacement { | 882 class _Replacement { |
876 final int offset; | 883 final int offset; |
877 final int end; | 884 final int end; |
878 final String text; | 885 final String text; |
879 _Replacement(this.offset, this.end, this.text); | 886 _Replacement(this.offset, this.end, this.text); |
880 } | 887 } |
OLD | NEW |