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

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

Issue 2930793002: Finish refactoring FixProcessor to use ChangeBuilder (Closed)
Patch Set: Created 3 years, 6 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
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';
11 import 'package:analyzer/src/dart/analysis/driver.dart'; 11 import 'package:analyzer/src/dart/analysis/driver.dart';
12 import 'package:analyzer/src/dart/ast/utilities.dart'; 12 import 'package:analyzer/src/dart/ast/utilities.dart';
13 import 'package:analyzer/src/dart/element/type.dart';
13 import 'package:analyzer/src/generated/resolver.dart'; 14 import 'package:analyzer/src/generated/resolver.dart';
14 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
15 import 'package:analyzer/src/generated/utilities_dart.dart'; 16 import 'package:analyzer/src/generated/utilities_dart.dart';
16 import 'package:analyzer_plugin/protocol/protocol_common.dart' 17 import 'package:analyzer_plugin/protocol/protocol_common.dart'
17 hide Element, ElementKind; 18 hide Element, ElementKind;
18 import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core .dart'; 19 import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core .dart';
19 import 'package:analyzer_plugin/src/utilities/string_utilities.dart'; 20 import 'package:analyzer_plugin/src/utilities/string_utilities.dart';
20 import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar t'; 21 import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar t';
21 import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dar t'; 22 import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dar t';
22 import 'package:analyzer_plugin/utilities/range_factory.dart'; 23 import 'package:analyzer_plugin/utilities/range_factory.dart';
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 write(prefix); 366 write(prefix);
366 writeln('}'); 367 writeln('}');
367 } 368 }
368 } 369 }
369 370
370 @override 371 @override
371 void writeParameterMatchingArgument( 372 void writeParameterMatchingArgument(
372 Expression argument, int index, Set<String> usedNames) { 373 Expression argument, int index, Set<String> usedNames) {
373 // append type name 374 // append type name
374 DartType type = argument.bestType; 375 DartType type = argument.bestType;
376 if (type == null || type.isBottom || type.isDartCoreNull) {
377 type = DynamicTypeImpl.instance;
378 }
375 if (writeType(type, addSupertypeProposals: true, groupName: 'TYPE$index')) { 379 if (writeType(type, addSupertypeProposals: true, groupName: 'TYPE$index')) {
376 write(' '); 380 write(' ');
377 } 381 }
378 // append parameter name 382 // append parameter name
379 if (argument is NamedExpression) { 383 if (argument is NamedExpression) {
380 write(argument.name.label.name); 384 write(argument.name.label.name);
381 } else { 385 } else {
382 List<String> suggestions = 386 List<String> suggestions =
383 _getParameterNameSuggestions(usedNames, type, argument, index); 387 _getParameterNameSuggestions(usedNames, type, argument, index);
384 String favorite = suggestions[0]; 388 String favorite = suggestions[0];
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 result.add(name); 590 result.add(name);
587 break; 591 break;
588 } 592 }
589 // next character 593 // next character
590 c = c + 1; 594 c = c + 1;
591 } 595 }
592 } 596 }
593 597
594 void _addSuperTypeProposals( 598 void _addSuperTypeProposals(
595 LinkedEditBuilder builder, DartType type, Set<DartType> alreadyAdded) { 599 LinkedEditBuilder builder, DartType type, Set<DartType> alreadyAdded) {
596 if (type != null && 600 if (type is InterfaceType && alreadyAdded.add(type)) {
597 type.element is ClassElement && 601 builder.addSuggestion(LinkedEditSuggestionKind.TYPE, type.displayName);
598 alreadyAdded.add(type)) { 602 _addSuperTypeProposals(builder, type.superclass, alreadyAdded);
599 ClassElement element = type.element as ClassElement; 603 for (InterfaceType interfaceType in type.interfaces) {
600 builder.addSuggestion(LinkedEditSuggestionKind.TYPE, element.name);
601 _addSuperTypeProposals(builder, element.supertype, alreadyAdded);
602 for (InterfaceType interfaceType in element.interfaces) {
603 _addSuperTypeProposals(builder, interfaceType, alreadyAdded); 604 _addSuperTypeProposals(builder, interfaceType, alreadyAdded);
604 } 605 }
605 } 606 }
606 } 607 }
607 608
608 String _getBaseNameFromExpression(Expression expression) { 609 String _getBaseNameFromExpression(Expression expression) {
609 String name = null; 610 String name = null;
610 // e as Type 611 // e as Type
611 if (expression is AsExpression) { 612 if (expression is AsExpression) {
612 AsExpression asExpression = expression as AsExpression; 613 AsExpression asExpression = expression as AsExpression;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 methodBeingCopied: methodBeingCopied); 790 methodBeingCopied: methodBeingCopied);
790 if (typeSource.isNotEmpty) { 791 if (typeSource.isNotEmpty) {
791 return '$typeSource $name'; 792 return '$typeSource $name';
792 } 793 }
793 return name; 794 return name;
794 } 795 }
795 796
796 /** 797 /**
797 * Returns the source to reference [type] in this [CompilationUnit]. 798 * Returns the source to reference [type] in this [CompilationUnit].
798 * 799 *
799 * Fills [librariesToImport] with [LibraryElement]s whose elements are 800 * Causes any libraries whose elements are used by the generated source, to be
800 * used by the generated source, but not imported. 801 * imported.
801 */ 802 */
802 String _getTypeSource(DartType type, ClassElement enclosingClass, 803 String _getTypeSource(DartType type, ClassElement enclosingClass,
803 ExecutableElement enclosingExecutable, 804 ExecutableElement enclosingExecutable,
804 {ExecutableElement methodBeingCopied, StringBuffer parametersBuffer}) { 805 {ExecutableElement methodBeingCopied, StringBuffer parametersBuffer}) {
805 StringBuffer buffer = new StringBuffer(); 806 StringBuffer buffer = new StringBuffer();
806 // type parameter 807 // type parameter
807 if (!_isTypeVisible(type, enclosingClass, enclosingExecutable, 808 if (!_isTypeVisible(type, enclosingClass, enclosingExecutable,
808 methodBeingCopied: methodBeingCopied)) { 809 methodBeingCopied: methodBeingCopied)) {
809 return 'dynamic'; 810 return 'dynamic';
810 } 811 }
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 } 1342 }
1342 } 1343 }
1343 1344
1344 class _InsertionDescription { 1345 class _InsertionDescription {
1345 final int offset; 1346 final int offset;
1346 final bool insertEmptyLineBefore; 1347 final bool insertEmptyLineBefore;
1347 final bool insertEmptyLineAfter; 1348 final bool insertEmptyLineAfter;
1348 _InsertionDescription( 1349 _InsertionDescription(
1349 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter); 1350 this.offset, this.insertEmptyLineBefore, this.insertEmptyLineAfter);
1350 } 1351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698