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

Side by Side Diff: tool/patch_sdk.dart

Issue 959913003: cleanup patch generation to preseve comments and remove @patch (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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/typed_data/typed_data.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 ddc.tool.patch_sdk; 8 library ddc.tool.patch_sdk;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 void _maybePatch(AstNode node) { 166 void _maybePatch(AstNode node) {
167 var externalKeyword = (node as dynamic).externalKeyword; 167 var externalKeyword = (node as dynamic).externalKeyword;
168 if (externalKeyword == null) return; 168 if (externalKeyword == null) return;
169 169
170 var name = _qualifiedName(node); 170 var name = _qualifiedName(node);
171 var patchNode = patches[name]; 171 var patchNode = patches[name];
172 if (patchNode == null) throw 'patch not found for $name: $node'; 172 if (patchNode == null) throw 'patch not found for $name: $node';
173 173
174 var code = patchCode.substring(patchNode.offset, patchNode.end); 174 Annotation patch = patchNode.metadata.lastWhere(_isPatchAnnotation);
175 var code = patchCode.substring(patch.endToken.next.offset, patchNode.end);
175 176
176 // For some node like static fields, the node's offset doesn't include 177 // For some node like static fields, the node's offset doesn't include
177 // the external keyword. 178 // the external keyword. Also starting from the keyword lets us preserve
178 var begin = math.min(node.offset, externalKeyword.offset); 179 // documentation comments.
179 edits.replace(begin, node.end, code); 180 edits.replace(externalKeyword.offset, node.end, code);
180 } 181 }
181 } 182 }
182 183
183 class PatchFinder extends RecursiveAstVisitor { 184 class PatchFinder extends RecursiveAstVisitor {
184 final Map patches = <String, Declaration>{}; 185 final Map patches = <String, Declaration>{};
185 186
186 @override visitFunctionDeclaration(FunctionDeclaration node) { 187 @override visitFunctionDeclaration(FunctionDeclaration node) {
187 _maybeStorePatch(node); 188 _maybeStorePatch(node);
188 return super.visitFunctionDeclaration(node); 189 return super.visitFunctionDeclaration(node);
189 } 190 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 int get length => end - begin; 313 int get length => end - begin;
313 314
314 String toString() => '(Edit @ $begin,$end: "$replace")'; 315 String toString() => '(Edit @ $begin,$end: "$replace")';
315 316
316 int compareTo(_StringEdit other) { 317 int compareTo(_StringEdit other) {
317 int diff = begin - other.begin; 318 int diff = begin - other.begin;
318 if (diff != 0) return diff; 319 if (diff != 0) return diff;
319 return end - other.end; 320 return end - other.end;
320 } 321 }
321 } 322 }
OLDNEW
« no previous file with comments | « test/generated_sdk/lib/typed_data/typed_data.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698