| 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 library dev_compiler.src.codegen.dart_codegen; | 5 library dev_compiler.src.codegen.dart_codegen; |
| 6 | 6 |
| 7 import 'dart:io' show File; | 7 import 'dart:io' show File; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' as analyzer; | 9 import 'package:analyzer/analyzer.dart' as analyzer; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/java_core.dart' as java_core; | 12 import 'package:analyzer/src/generated/java_core.dart' as java_core; |
| 13 import 'package:analyzer/src/generated/scanner.dart' show Token; | 13 import 'package:analyzer/src/generated/scanner.dart' show Token; |
| 14 import 'package:dart_style/dart_style.dart'; | |
| 15 import 'package:logging/logging.dart' as logger; | 14 import 'package:logging/logging.dart' as logger; |
| 16 import 'package:path/path.dart' as path; | 15 import 'package:path/path.dart' as path; |
| 17 | 16 |
| 18 import 'package:dev_compiler/devc.dart' show AbstractCompiler; | 17 import 'package:dev_compiler/devc.dart' show AbstractCompiler; |
| 19 import 'package:dev_compiler/src/info.dart'; | 18 import 'package:dev_compiler/src/info.dart'; |
| 20 import 'package:dev_compiler/src/options.dart'; | 19 import 'package:dev_compiler/src/options.dart'; |
| 21 import 'package:dev_compiler/src/utils.dart' as utils; | 20 import 'package:dev_compiler/src/utils.dart' as utils; |
| 22 import 'ast_builder.dart'; | 21 import 'ast_builder.dart'; |
| 23 import 'code_generator.dart' as codegenerator; | 22 import 'code_generator.dart' as codegenerator; |
| 24 import 'reify_coercions.dart' | 23 import 'reify_coercions.dart' |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // TODO(leafp) This is kind of a hack, but it works for now. | 87 // TODO(leafp) This is kind of a hack, but it works for now. |
| 89 class FileWriter extends java_core.PrintStringWriter { | 88 class FileWriter extends java_core.PrintStringWriter { |
| 90 final CompilerOptions options; | 89 final CompilerOptions options; |
| 91 String _path; | 90 String _path; |
| 92 FileWriter(this.options, this._path); | 91 FileWriter(this.options, this._path); |
| 93 int indent = 0; | 92 int indent = 0; |
| 94 int withinInterpolationExpression = 0; | 93 int withinInterpolationExpression = 0; |
| 95 bool insideForLoop = false; | 94 bool insideForLoop = false; |
| 96 | 95 |
| 97 void print(x) { | 96 void print(x) { |
| 98 if (!options.cheapTestFormat) { | 97 if (!options.formatOutput) { |
| 99 super.print(x); | 98 super.print(x); |
| 100 return; | 99 return; |
| 101 } | 100 } |
| 102 | 101 |
| 103 switch (x) { | 102 switch (x) { |
| 104 case '{': | 103 case '{': |
| 105 indent++; | 104 indent++; |
| 106 x = '{\n${" " * indent}'; | 105 x = '{\n${" " * indent}'; |
| 107 break; | 106 break; |
| 108 case ';': | 107 case ';': |
| (...skipping 17 matching lines...) Expand all Loading... |
| 126 indent--; | 125 indent--; |
| 127 x = '}\n${" " * indent}'; | 126 x = '}\n${" " * indent}'; |
| 128 } | 127 } |
| 129 break; | 128 break; |
| 130 } | 129 } |
| 131 super.print(x); | 130 super.print(x); |
| 132 } | 131 } |
| 133 | 132 |
| 134 void finalize() { | 133 void finalize() { |
| 135 String s = toString(); | 134 String s = toString(); |
| 136 if (options.formatOutput && !options.cheapTestFormat) { | |
| 137 DartFormatter d = new DartFormatter(); | |
| 138 try { | |
| 139 _log.fine("Formatting file $_path "); | |
| 140 s = d.format(s, uri: _path); | |
| 141 } catch (e) { | |
| 142 _log.severe("Failed to format $_path: " + e.toString()); | |
| 143 } | |
| 144 } | |
| 145 _log.fine("Writing file $_path"); | 135 _log.fine("Writing file $_path"); |
| 146 new File(_path).writeAsStringSync(s); | 136 new File(_path).writeAsStringSync(s); |
| 147 } | 137 } |
| 148 } | 138 } |
| 149 | 139 |
| 150 bool _identifierNeedsQualification(Identifier id, NewTypeIdDesc desc) { | 140 bool _identifierNeedsQualification(Identifier id, NewTypeIdDesc desc) { |
| 151 var library = desc.importedFrom; | 141 var library = desc.importedFrom; |
| 152 if (library == null) return false; | 142 if (library == null) return false; |
| 153 if (library.isDartCore) return false; | 143 if (library.isDartCore) return false; |
| 154 if (desc.fromCurrent) return false; | 144 if (desc.fromCurrent) return false; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { | 447 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { |
| 458 var uri = unit.element.source.uri; | 448 var uri = unit.element.source.uri; |
| 459 _log.fine("Emitting original unit " + uri.toString()); | 449 _log.fine("Emitting original unit " + uri.toString()); |
| 460 FileWriter out = new FileWriter( | 450 FileWriter out = new FileWriter( |
| 461 options, path.join(libraryDir, '${uri.pathSegments.last}')); | 451 options, path.join(libraryDir, '${uri.pathSegments.last}')); |
| 462 var unitGen = new EmptyUnitGenerator(unit, out); | 452 var unitGen = new EmptyUnitGenerator(unit, out); |
| 463 unitGen.generate(); | 453 unitGen.generate(); |
| 464 out.finalize(); | 454 out.finalize(); |
| 465 } | 455 } |
| 466 } | 456 } |
| OLD | NEW |