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

Unified Diff: pkg/analysis_server/lib/src/services/refactoring/inline_method.dart

Issue 694373002: Support for inlining methods when some arguments are missing. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/inline_method_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/refactoring/inline_method.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart b/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart
index c6c680e3f24f484ef680405c096ec4824e4a2ab1..96dbb0340185de48fe1295d4211dd0c53d43a222 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/inline_method.dart
@@ -19,6 +19,7 @@ import 'package:analysis_server/src/services/search/search_engine.dart';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/src/generated/utilities_dart.dart';
/**
@@ -46,8 +47,9 @@ SourceRange _getLocalsConflictingRange(AstNode node) {
* Returns the source which should replace given invocation with given
* arguments.
*/
-String _getMethodSourceForInvocation(_SourcePart part, CorrectionUtils utils,
- AstNode contextNode, Expression targetExpression, List<Expression> arguments) {
+String _getMethodSourceForInvocation(RefactoringStatus status, _SourcePart part,
+ CorrectionUtils utils, AstNode contextNode, Expression targetExpression,
+ List<Expression> arguments) {
// prepare edits to replace parameters with arguments
List<SourceEdit> edits = <SourceEdit>[];
part._parameters.forEach(
@@ -63,15 +65,34 @@ String _getMethodSourceForInvocation(_SourcePart part, CorrectionUtils utils,
if (argument is NamedExpression) {
argument = (argument as NamedExpression).expression;
}
- int argumentPrecedence = getExpressionPrecedence(argument);
- String argumentSource = utils.getNodeText(argument);
+ // prepare argument properties
+ int argumentPrecedence;
+ String argumentSource;
+ if (argument != null) {
+ argumentPrecedence = getExpressionPrecedence(argument);
+ argumentSource = utils.getNodeText(argument);
+ } else {
+ // report about a missing required parameter
+ if (parameter.parameterKind == ParameterKind.REQUIRED) {
+ status.addError(
+ 'No argument for the parameter "${parameter.name}".',
+ newLocation_fromNode(contextNode));
+ return;
+ }
+ // an optional parameter
+ argumentPrecedence = -1000;
+ argumentSource = parameter.defaultValueCode;
+ if (argumentSource == null) {
+ argumentSource = 'null';
+ }
+ }
// replace all occurrences of this parameter
for (_ParameterOccurrence occurrence in occurrences) {
SourceRange range = occurrence.range;
// prepare argument source to apply at this occurrence
String occurrenceArgumentSource;
if (argumentPrecedence < occurrence.parentPrecedence) {
- occurrenceArgumentSource = "(${argumentSource})";
+ occurrenceArgumentSource = "($argumentSource)";
} else {
occurrenceArgumentSource = argumentSource;
}
@@ -488,6 +509,7 @@ class _ReferenceProcessor {
if (ref._methodStatementsPart != null) {
// prepare statements source for invocation
String source = _getMethodSourceForInvocation(
+ status,
ref._methodStatementsPart,
_refUtils,
usage,
@@ -506,6 +528,7 @@ class _ReferenceProcessor {
if (ref._methodExpressionPart != null) {
// prepare expression source for invocation
String source = _getMethodSourceForInvocation(
+ status,
ref._methodExpressionPart,
_refUtils,
usage,
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/inline_method_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698