| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 void writeDocumentation(Element e, [String prefix = '']) { | 255 void writeDocumentation(Element e, [String prefix = '']) { |
| 256 if (e.documentationComment != null) { | 256 if (e.documentationComment != null) { |
| 257 buffer.write(prefix); | 257 buffer.write(prefix); |
| 258 buffer.writeln(e.documentationComment); | 258 buffer.writeln(e.documentationComment); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 void writeExportElement(ExportElement e) { | 262 void writeExportElement(ExportElement e) { |
| 263 writeMetadata(e, '', '\n'); | 263 writeMetadata(e, '', '\n'); |
| 264 buffer.write('export '); | 264 buffer.write('export '); |
| 265 writeUri(e, e.exportedLibrary?.source); | 265 writeUri(e.exportedLibrary?.source); |
| 266 | 266 |
| 267 e.combinators.forEach(writeNamespaceCombinator); | 267 e.combinators.forEach(writeNamespaceCombinator); |
| 268 | 268 |
| 269 buffer.writeln(';'); | 269 buffer.writeln(';'); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void writeExpression(AstNode e) { | 272 void writeExpression(AstNode e) { |
| 273 if (e is Annotation) { | 273 if (e is Annotation) { |
| 274 buffer.write('@'); | 274 buffer.write('@'); |
| 275 writeExpression(e.name); | 275 writeExpression(e.name); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 void writeIf(bool flag, String str) { | 472 void writeIf(bool flag, String str) { |
| 473 if (flag) { | 473 if (flag) { |
| 474 buffer.write(str); | 474 buffer.write(str); |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 | 477 |
| 478 void writeImportElement(ImportElement e) { | 478 void writeImportElement(ImportElement e) { |
| 479 if (!e.isSynthetic) { | 479 if (!e.isSynthetic) { |
| 480 writeMetadata(e, '', '\n'); | 480 writeMetadata(e, '', '\n'); |
| 481 buffer.write('import '); | 481 buffer.write('import '); |
| 482 writeUri(e, e.importedLibrary?.source); | 482 writeUri(e.importedLibrary?.source); |
| 483 | 483 |
| 484 writeIf(e.isDeferred, ' deferred'); | 484 writeIf(e.isDeferred, ' deferred'); |
| 485 | 485 |
| 486 if (e.prefix != null) { | 486 if (e.prefix != null) { |
| 487 buffer.write(' as '); | 487 buffer.write(' as '); |
| 488 writeName(e.prefix); | 488 writeName(e.prefix); |
| 489 if (withOffsets) { | 489 if (withOffsets) { |
| 490 buffer.write('(${e.prefixOffset})'); | 490 buffer.write('(${e.prefixOffset})'); |
| 491 } | 491 } |
| 492 } | 492 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 } | 630 } |
| 631 | 631 |
| 632 void writeParameterElements(List<ParameterElement> elements) { | 632 void writeParameterElements(List<ParameterElement> elements) { |
| 633 writeList('(', ')', elements, ', ', writeParameterElement, | 633 writeList('(', ')', elements, ', ', writeParameterElement, |
| 634 includeEmpty: true); | 634 includeEmpty: true); |
| 635 } | 635 } |
| 636 | 636 |
| 637 void writePartElement(CompilationUnitElement e) { | 637 void writePartElement(CompilationUnitElement e) { |
| 638 writeMetadata(e, '', '\n'); | 638 writeMetadata(e, '', '\n'); |
| 639 buffer.write('part '); | 639 buffer.write('part '); |
| 640 writeUri(e, e.source); | 640 writeUri(e.source); |
| 641 buffer.writeln(';'); | 641 buffer.writeln(';'); |
| 642 } | 642 } |
| 643 | 643 |
| 644 void writePropertyAccessorElement(PropertyAccessorElement e) { | 644 void writePropertyAccessorElement(PropertyAccessorElement e) { |
| 645 if (e.isSynthetic && !withSyntheticAccessors) { | 645 if (e.isSynthetic && !withSyntheticAccessors) { |
| 646 return; | 646 return; |
| 647 } | 647 } |
| 648 | 648 |
| 649 if (!e.isSynthetic) { | 649 if (!e.isSynthetic) { |
| 650 PropertyInducingElement variable = e.variable; | 650 PropertyInducingElement variable = e.variable; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 buffer.writeln(); | 799 buffer.writeln(); |
| 800 } | 800 } |
| 801 e.functionTypeAliases.forEach(writeFunctionTypeAliasElement); | 801 e.functionTypeAliases.forEach(writeFunctionTypeAliasElement); |
| 802 e.enums.forEach(writeClassElement); | 802 e.enums.forEach(writeClassElement); |
| 803 e.types.forEach(writeClassElement); | 803 e.types.forEach(writeClassElement); |
| 804 e.topLevelVariables.forEach(writePropertyInducingElement); | 804 e.topLevelVariables.forEach(writePropertyInducingElement); |
| 805 e.accessors.forEach(writePropertyAccessorElement); | 805 e.accessors.forEach(writePropertyAccessorElement); |
| 806 e.functions.forEach(writeFunctionElement); | 806 e.functions.forEach(writeFunctionElement); |
| 807 } | 807 } |
| 808 | 808 |
| 809 void writeUri(UriReferencedElement e, Source source) { | 809 void writeUri(Source source) { |
| 810 String uri = e.uri ?? source.uri.toString(); | 810 if (source != null) { |
| 811 buffer.write('\'$uri\''); | 811 Uri uri = source.uri; |
| 812 if (withOffsets) { | 812 String uriStr = uri.toString(); |
| 813 buffer.write('('); | 813 if (uri.isScheme('file')) { |
| 814 buffer.write('${e.uriOffset}, '); | 814 uriStr = uri.pathSegments.last; |
| 815 buffer.write('${e.uriEnd})'); | 815 } |
| 816 buffer.write(')'); | 816 buffer.write('\'$uriStr\''); |
| 817 } else { |
| 818 buffer.write('\'<unresolved>\''); |
| 817 } | 819 } |
| 818 } | 820 } |
| 819 | 821 |
| 820 void writeVariableTypeInferenceError(VariableElement e) { | 822 void writeVariableTypeInferenceError(VariableElement e) { |
| 821 if (e is VariableElementImpl) { | 823 if (e is VariableElementImpl) { |
| 822 TopLevelInferenceError inferenceError = e.typeInferenceError; | 824 TopLevelInferenceError inferenceError = e.typeInferenceError; |
| 823 if (inferenceError != null) { | 825 if (inferenceError != null) { |
| 824 String kindName = inferenceError.kind.toString(); | 826 String kindName = inferenceError.kind.toString(); |
| 825 if (kindName.startsWith('TopLevelInferenceErrorKind.')) { | 827 if (kindName.startsWith('TopLevelInferenceErrorKind.')) { |
| 826 kindName = kindName.substring('TopLevelInferenceErrorKind.'.length); | 828 kindName = kindName.substring('TopLevelInferenceErrorKind.'.length); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 856 return components.join(';'); | 858 return components.join(';'); |
| 857 } | 859 } |
| 858 } | 860 } |
| 859 | 861 |
| 860 class _Replacement { | 862 class _Replacement { |
| 861 final int offset; | 863 final int offset; |
| 862 final int end; | 864 final int end; |
| 863 final String text; | 865 final String text; |
| 864 _Replacement(this.offset, this.end, this.text); | 866 _Replacement(this.offset, this.end, this.text); |
| 865 } | 867 } |
| OLD | NEW |