Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tool/patch_sdk.dart

Issue 1104753002: patch_sdk: fix part/import order (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/generated_sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 /// Command line tool to merge the SDK libraries and our patch files. 6 /// Command line tool to merge the SDK libraries and our patch files.
7 /// This is currently designed as an offline tool, but we could automate it. 7 /// This is currently designed as an offline tool, but we could automate it.
8 library dev_compiler.tool.patch_sdk; 8 library dev_compiler.tool.patch_sdk;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 bool _isLibrary = true; // until proven otherwise. 153 bool _isLibrary = true; // until proven otherwise.
154 154
155 PatchApplier(this.edits, this.patch); 155 PatchApplier(this.edits, this.patch);
156 156
157 @override visitCompilationUnit(CompilationUnit node) { 157 @override visitCompilationUnit(CompilationUnit node) {
158 super.visitCompilationUnit(node); 158 super.visitCompilationUnit(node);
159 if (_isLibrary) _mergeUnpatched(node); 159 if (_isLibrary) _mergeUnpatched(node);
160 } 160 }
161 161
162 void _merge(AstNode node, int pos) {
163 var code = patch.contents.substring(node.offset, node.end);
164 edits.insert(pos, '\n' + code);
165 }
166
162 /// Merges directives and declarations that are not `@patch` into the library. 167 /// Merges directives and declarations that are not `@patch` into the library.
163 void _mergeUnpatched(CompilationUnit unit) { 168 void _mergeUnpatched(CompilationUnit unit) {
164 // Merge directives from the patch 169
170 // Merge imports from the patch
165 // TODO(jmesserly): remove duplicate imports 171 // TODO(jmesserly): remove duplicate imports
166 var directivePos = unit.directives.last.end; 172
167 for (var directive in patch.unit.directives) { 173 int partPos = unit.directives.last.end;
Leaf 2015/04/23 21:32:55 I think directives can be null if there are no dir
Jennifer Messerly 2015/04/23 21:44:28 maybe, yeah. That can only happen for "scripts" th
168 var code = patch.contents.substring(directive.offset, directive.end); 174 var lastImport = unit.directives.lastWhere((d) => d is ImportDirective,
169 edits.insert(directivePos, '\n' + code); 175 orElse: () => null);
176 int importPos = lastImport != null ? lastImport.end : partPos;
Leaf 2015/04/23 21:32:55 Doesn't this still put the new imports after the p
Jennifer Messerly 2015/04/23 21:44:28 Good catch! I'll have it go after the library dire
177
178 for (var d in patch.unit.directives.where((d) => d is ImportDirective)) {
179 _merge(d, importPos);
180 }
181 for (var d in patch.unit.directives.where((d) => d is PartDirective)) {
182 _merge(d, partPos);
170 } 183 }
171 184
172 // Merge declarations from the patch 185 // Merge declarations from the patch
173 var declarationPos = edits.original.length; 186 int declPos = edits.original.length;
174 for (var declaration in patch.mergeDeclarations) { 187 for (var d in patch.mergeDeclarations) {
175 var code = patch.contents.substring(declaration.offset, declaration.end); 188 _merge(d, declPos);
176 edits.insert(declarationPos, '\n' + code);
177 } 189 }
178 } 190 }
179 191
180 @override visitPartOfDirective(PartOfDirective node) { 192 @override visitPartOfDirective(PartOfDirective node) {
181 _isLibrary = false; 193 _isLibrary = false;
182 } 194 }
183 195
184 @override visitFunctionDeclaration(FunctionDeclaration node) { 196 @override visitFunctionDeclaration(FunctionDeclaration node) {
185 _maybePatch(node); 197 _maybePatch(node);
186 } 198 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (diff != 0) return diff; 389 if (diff != 0) return diff;
378 return end - other.end; 390 return end - other.end;
379 } 391 }
380 } 392 }
381 393
382 List<SdkLibrary> _getSdkLibraries(String contents) { 394 List<SdkLibrary> _getSdkLibraries(String contents) {
383 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true); 395 var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(true);
384 parseCompilationUnit(contents).accept(libraryBuilder); 396 parseCompilationUnit(contents).accept(libraryBuilder);
385 return libraryBuilder.librariesMap.sdkLibraries; 397 return libraryBuilder.librariesMap.sdkLibraries;
386 } 398 }
OLDNEW
« no previous file with comments | « test/generated_sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698