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

Side by Side Diff: pkg/analysis_server/lib/src/services/refactoring/extract_method.dart

Issue 706263003: Issue 20827. Add imports as needed the 'Add type annotation' Quick Assist. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library services.src.refactoring.extract_method; 5 library services.src.refactoring.extract_method;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol_server.dart' hide Element; 9 import 'package:analysis_server/src/protocol_server.dart' hide Element;
10 import 'package:analysis_server/src/services/correction/name_suggestion.dart'; 10 import 'package:analysis_server/src/services/correction/name_suggestion.dart';
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // closure 298 // closure
299 if (_selectionFunctionExpression != null) { 299 if (_selectionFunctionExpression != null) {
300 declarationSource = '${name}${returnExpressionSource}'; 300 declarationSource = '${name}${returnExpressionSource}';
301 if (_selectionFunctionExpression.body is ExpressionFunctionBody) { 301 if (_selectionFunctionExpression.body is ExpressionFunctionBody) {
302 declarationSource += ';'; 302 declarationSource += ';';
303 } 303 }
304 } 304 }
305 // expression 305 // expression
306 if (_selectionExpression != null) { 306 if (_selectionExpression != null) {
307 // add return type 307 // add return type
308 Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
309 // TODO(scheglov) use librariesToImport
308 String returnTypeName = 310 String returnTypeName =
309 utils.getExpressionTypeSource(_selectionExpression); 311 utils.getExpressionTypeSource(_selectionExpression, librariesToImp ort);
310 if (returnTypeName != null && returnTypeName != 'dynamic') { 312 if (returnTypeName != null && returnTypeName != 'dynamic') {
311 annotations += '${returnTypeName} '; 313 annotations += '${returnTypeName} ';
312 } 314 }
313 // just return expression 315 // just return expression
314 declarationSource = 316 declarationSource =
315 '${annotations}${signature} => ${returnExpressionSource};'; 317 '${annotations}${signature} => ${returnExpressionSource};';
316 } 318 }
317 // statements 319 // statements
318 if (_selectionStatements != null) { 320 if (_selectionStatements != null) {
319 if (returnType.isNotEmpty) { 321 if (returnType.isNotEmpty) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 sb.toString().trim())); 613 sb.toString().trim()));
612 } 614 }
613 // done 615 // done
614 return result; 616 return result;
615 } 617 }
616 618
617 void _initializeReturnType() { 619 void _initializeReturnType() {
618 if (_returnType == null) { 620 if (_returnType == null) {
619 returnType = 'void'; 621 returnType = 'void';
620 } else { 622 } else {
621 returnType = utils.getTypeSource(_returnType); 623 Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
624 // TODO(scheglov) use librariesToImport
625 returnType = utils.getTypeSource(_returnType, librariesToImport);
622 } 626 }
623 if (returnType == 'dynamic') { 627 if (returnType == 'dynamic') {
624 returnType = ''; 628 returnType = '';
625 } 629 }
626 } 630 }
627 631
628 /** 632 /**
629 * Checks if the given [VariableElement] is declared in [selectionRange]. 633 * Checks if the given [VariableElement] is declared in [selectionRange].
630 */ 634 */
631 bool _isDeclaredInSelection(VariableElement element) { 635 bool _isDeclaredInSelection(VariableElement element) {
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 } 936 }
933 // prepare normalized node source 937 // prepare normalized node source
934 _SourcePattern nodePattern = ref._getSourcePattern(nodeRange); 938 _SourcePattern nodePattern = ref._getSourcePattern(nodeRange);
935 String nodeSource = _getNormalizedSource(nodePattern.patternSource); 939 String nodeSource = _getNormalizedSource(nodePattern.patternSource);
936 // if matches normalized node source, then add as occurrence 940 // if matches normalized node source, then add as occurrence
937 if (nodeSource == selectionSource) { 941 if (nodeSource == selectionSource) {
938 _Occurrence occurrence = 942 _Occurrence occurrence =
939 new _Occurrence(nodeRange, ref.selectionRange.intersects(nodeRange)); 943 new _Occurrence(nodeRange, ref.selectionRange.intersects(nodeRange));
940 ref._occurrences.add(occurrence); 944 ref._occurrences.add(occurrence);
941 // prepare mapping of parameter names to the occurrence variables 945 // prepare mapping of parameter names to the occurrence variables
942 nodePattern.originalToPatternNames.forEach((String originalName, String pa tternName) { 946 nodePattern.originalToPatternNames.forEach(
947 (String originalName, String patternName) {
943 String selectionName = patternToSelectionName[patternName]; 948 String selectionName = patternToSelectionName[patternName];
944 occurrence._parameterOldToOccurrenceName[selectionName] = originalName; 949 occurrence._parameterOldToOccurrenceName[selectionName] = originalName;
945 }); 950 });
946 // update static 951 // update static
947 if (forceStatic) { 952 if (forceStatic) {
948 ref._staticContext = true; 953 ref._staticContext = true;
949 } 954 }
950 // we have match 955 // we have match
951 return true; 956 return true;
952 } 957 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 return null; 997 return null;
993 } 998 }
994 // if declared outside, add parameter 999 // if declared outside, add parameter
995 if (!ref._isDeclaredInSelection(variableElement)) { 1000 if (!ref._isDeclaredInSelection(variableElement)) {
996 String variableName = variableElement.displayName; 1001 String variableName = variableElement.displayName;
997 // add parameter 1002 // add parameter
998 RefactoringMethodParameter parameter = 1003 RefactoringMethodParameter parameter =
999 ref._parametersMap[variableName]; 1004 ref._parametersMap[variableName];
1000 if (parameter == null) { 1005 if (parameter == null) {
1001 DartType parameterType = node.bestType; 1006 DartType parameterType = node.bestType;
1002 String parameterTypeName = ref.utils.getTypeSource(parameterType); 1007 Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
1008 // TODO(scheglov) use librariesToImport
1009 String parameterTypeName =
1010 ref.utils.getTypeSource(parameterType, librariesToImport);
1003 parameter = new RefactoringMethodParameter( 1011 parameter = new RefactoringMethodParameter(
1004 RefactoringMethodParameterKind.REQUIRED, 1012 RefactoringMethodParameterKind.REQUIRED,
1005 parameterTypeName, 1013 parameterTypeName,
1006 variableName, 1014 variableName,
1007 id: variableName); 1015 id: variableName);
1008 ref._parameters.add(parameter); 1016 ref._parameters.add(parameter);
1009 ref._parametersMap[variableName] = parameter; 1017 ref._parametersMap[variableName] = parameter;
1010 } 1018 }
1011 // add reference to parameter 1019 // add reference to parameter
1012 ref._addParameterReference(variableName, nodeRange); 1020 ref._addParameterReference(variableName, nodeRange);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 1103
1096 /** 1104 /**
1097 * Generalized version of some source, in which references to the specific 1105 * Generalized version of some source, in which references to the specific
1098 * variables are replaced with pattern variables, with back mapping from the 1106 * variables are replaced with pattern variables, with back mapping from the
1099 * pattern to the original variable names. 1107 * pattern to the original variable names.
1100 */ 1108 */
1101 class _SourcePattern { 1109 class _SourcePattern {
1102 String patternSource; 1110 String patternSource;
1103 Map<String, String> originalToPatternNames = {}; 1111 Map<String, String> originalToPatternNames = {};
1104 } 1112 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/util.dart ('k') | pkg/analysis_server/test/mock_sdk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698