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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/generated_sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/patch_sdk.dart
diff --git a/tool/patch_sdk.dart b/tool/patch_sdk.dart
index d3c507b58f3b09472060c722c6579fd1e73ed4b4..3a2262fa56a6c249dc9fe3b0fde09e7d9ac6499d 100755
--- a/tool/patch_sdk.dart
+++ b/tool/patch_sdk.dart
@@ -159,21 +159,33 @@ class PatchApplier extends GeneralizingAstVisitor {
if (_isLibrary) _mergeUnpatched(node);
}
+ void _merge(AstNode node, int pos) {
+ var code = patch.contents.substring(node.offset, node.end);
+ edits.insert(pos, '\n' + code);
+ }
+
/// Merges directives and declarations that are not `@patch` into the library.
void _mergeUnpatched(CompilationUnit unit) {
- // Merge directives from the patch
+
+ // Merge imports from the patch
// TODO(jmesserly): remove duplicate imports
- var directivePos = unit.directives.last.end;
- for (var directive in patch.unit.directives) {
- var code = patch.contents.substring(directive.offset, directive.end);
- edits.insert(directivePos, '\n' + code);
+
+ 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
+ var lastImport = unit.directives.lastWhere((d) => d is ImportDirective,
+ orElse: () => null);
+ 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
+
+ for (var d in patch.unit.directives.where((d) => d is ImportDirective)) {
+ _merge(d, importPos);
+ }
+ for (var d in patch.unit.directives.where((d) => d is PartDirective)) {
+ _merge(d, partPos);
}
// Merge declarations from the patch
- var declarationPos = edits.original.length;
- for (var declaration in patch.mergeDeclarations) {
- var code = patch.contents.substring(declaration.offset, declaration.end);
- edits.insert(declarationPos, '\n' + code);
+ int declPos = edits.original.length;
+ for (var d in patch.mergeDeclarations) {
+ _merge(d, declPos);
}
}
« 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