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

Side by Side Diff: pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart

Issue 2967683002: Clean up some code in plugins (Closed)
Patch Set: Created 3 years, 5 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 | « pkg/analyzer_plugin/lib/src/protocol/protocol_internal.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 // 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:async'; 5 import 'dart:async';
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // parameters + body 350 // parameters + body
351 if (isGetter) { 351 if (isGetter) {
352 writeln(' => null;'); 352 writeln(' => null;');
353 } else { 353 } else {
354 List<ParameterElement> parameters = member.parameters; 354 List<ParameterElement> parameters = member.parameters;
355 writeParameters(parameters, methodBeingCopied: member); 355 writeParameters(parameters, methodBeingCopied: member);
356 writeln(' {'); 356 writeln(' {');
357 // TO-DO 357 // TO-DO
358 write(prefix2); 358 write(prefix2);
359 writeln('// TODO: implement ${member.displayName}'); 359 writeln('// TODO: implement ${member.displayName}');
360 // REVIEW: Added return statement.
361 if (shouldReturn) { 360 if (shouldReturn) {
362 write(prefix2); 361 write(prefix2);
363 writeln('return null;'); 362 writeln('return null;');
364 } 363 }
365 // close method 364 // close method
366 write(prefix); 365 write(prefix);
367 writeln('}'); 366 writeln('}');
368 } 367 }
369 } 368 }
370 369
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 * The compilation unit to which the code will be added. 970 * The compilation unit to which the code will be added.
972 */ 971 */
973 CompilationUnit unit; 972 CompilationUnit unit;
974 973
975 /** 974 /**
976 * A set containing the sources of the libraries that need to be imported in 975 * A set containing the sources of the libraries that need to be imported in
977 * order to make visible the names used in generated code. 976 * order to make visible the names used in generated code.
978 */ 977 */
979 Set<Source> librariesToImport = new Set<Source>(); 978 Set<Source> librariesToImport = new Set<Source>();
980 979
981 // /**
982 // * The content of the file being edited.
983 // */
984 // String _content;
985
986 /** 980 /**
987 * Initialize a newly created builder to build a source file edit within the 981 * Initialize a newly created builder to build a source file edit within the
988 * change being built by the given [changeBuilder]. The file being edited has 982 * change being built by the given [changeBuilder]. The file being edited has
989 * the given [source] and [timeStamp], and the given fully resolved [unit]. 983 * the given [source] and [timeStamp], and the given fully resolved [unit].
990 */ 984 */
991 DartFileEditBuilderImpl(DartChangeBuilderImpl changeBuilder, String path, 985 DartFileEditBuilderImpl(DartChangeBuilderImpl changeBuilder, String path,
992 int timeStamp, this.unit) 986 int timeStamp, this.unit)
993 : super(changeBuilder, path, timeStamp); 987 : super(changeBuilder, path, timeStamp);
994 988
995 @override 989 @override
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 int nextLineOffset = lineInfo.getOffsetOfLine(currentLine + 1); 1260 int nextLineOffset = lineInfo.getOffsetOfLine(currentLine + 1);
1267 String insertLine = source.substring(offset, nextLineOffset); 1261 String insertLine = source.substring(offset, nextLineOffset);
1268 if (!insertLine.trim().isEmpty) { 1262 if (!insertLine.trim().isEmpty) {
1269 insertEmptyLineAfter = true; 1263 insertEmptyLineAfter = true;
1270 } 1264 }
1271 } 1265 }
1272 return new _InsertionDescription( 1266 return new _InsertionDescription(
1273 offset, insertEmptyLineBefore, insertEmptyLineAfter); 1267 offset, insertEmptyLineBefore, insertEmptyLineAfter);
1274 } 1268 }
1275 1269
1276 // /**
1277 // * Return the content of the file being edited.
1278 // */
1279 // String getContent() {
1280 // if (_content == null) {
1281 // CompilationUnitElement unitElement = unit.element;
1282 // AnalysisContext context = unitElement.context;
1283 // if (context == null) {
1284 // throw new CancelCorrectionException();
1285 // }
1286 // _content = context.getContents(unitElement.source).data;
1287 // }
1288 // return _content;
1289 // }
1290
1291 /** 1270 /**
1292 * Computes the best URI to import [what] into [from]. 1271 * Computes the best URI to import [what] into [from].
1293 */ 1272 */
1294 String _getLibrarySourceUri(LibraryElement from, Source what) { 1273 String _getLibrarySourceUri(LibraryElement from, Source what) {
1295 String whatPath = what.fullName; 1274 String whatPath = what.fullName;
1296 // check if an absolute URI (such as 'dart:' or 'package:') 1275 // check if an absolute URI (such as 'dart:' or 'package:')
1297 Uri whatUri = what.uri; 1276 Uri whatUri = what.uri;
1298 String whatUriScheme = whatUri.scheme; 1277 String whatUriScheme = whatUri.scheme;
1299 if (whatUriScheme != '' && whatUriScheme != 'file') { 1278 if (whatUriScheme != '' && whatUriScheme != 'file') {
1300 return whatUri.toString(); 1279 return whatUri.toString();
1301 } 1280 }
1302 // compute a relative URI 1281 // compute a relative URI
1303 String fromFolder = path.dirname(from.source.fullName); 1282 String fromFolder = path.dirname(from.source.fullName);
1304 String relativeFile = path.relative(whatPath, from: fromFolder); 1283 String relativeFile = path.relative(whatPath, from: fromFolder);
1305 return path.split(relativeFile).join('/'); 1284 return path.split(relativeFile).join('/');
1306 } 1285 }
1307 1286
1308 /** 1287 /**
1309 * Returns the text of the given range in the unit. 1288 * Returns the text of the given range in the unit.
1310 */ 1289 */
1311 String _getText(String content, int offset, int length) { 1290 String _getText(String content, int offset, int length) {
1312 return content.substring(offset, offset + length); 1291 return content.substring(offset, offset + length);
1313 } 1292 }
1314 1293
1315 // /**
1316 // * Returns the text of the given [AstNode] in the unit.
1317 // */
1318 // String _getNodeText(AstNode node) {
1319 // return _getText(node.offset, node.length);
1320 // }
1321 //
1322 // /**
1323 // * Returns the text of the given range in the unit.
1324 // */
1325 // String _getText(int offset, int length) {
1326 // return getContent().substring(offset, offset + length);
1327 // }
1328
1329 /** 1294 /**
1330 * Create an edit to replace the return type of the innermost function 1295 * Create an edit to replace the return type of the innermost function
1331 * containing the given [node] with the type `Future`. The [typeProvider] is 1296 * containing the given [node] with the type `Future`. The [typeProvider] is
1332 * used to check the current return type, because if it is already `Future` no 1297 * used to check the current return type, because if it is already `Future` no
1333 * edit will be added. 1298 * edit will be added.
1334 */ 1299 */
1335 void _replaceReturnTypeWithFuture(AstNode node, TypeProvider typeProvider) { 1300 void _replaceReturnTypeWithFuture(AstNode node, TypeProvider typeProvider) {
1336 while (node != null) { 1301 while (node != null) {
1337 node = node.parent; 1302 node = node.parent;
1338 if (node is FunctionDeclaration) { 1303 if (node is FunctionDeclaration) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 } 1366 }
1402 } 1367 }
1403 1368
1404 class _InsertionDescription { 1369 class _InsertionDescription {
1405 final int offset; 1370 final int offset;
1406 final bool insertEmptyLineBefore; 1371 final bool insertEmptyLineBefore;
1407 final bool insertEmptyLineAfter; 1372 final bool insertEmptyLineAfter;
1408 _InsertionDescription( 1373 _InsertionDescription(
1409 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter); 1374 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter);
1410 } 1375 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/lib/src/protocol/protocol_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698