OLD | NEW |
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.inline_method; | 5 library services.src.refactoring.inline_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/source_range.dart'; | 10 import 'package:analysis_server/src/services/correction/source_range.dart'; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 /** | 44 /** |
45 * Returns the source which should replace given invocation with given | 45 * Returns the source which should replace given invocation with given |
46 * arguments. | 46 * arguments. |
47 */ | 47 */ |
48 String _getMethodSourceForInvocation(RefactoringStatus status, _SourcePart part, | 48 String _getMethodSourceForInvocation(RefactoringStatus status, _SourcePart part, |
49 CorrectionUtils utils, AstNode contextNode, Expression targetExpression, | 49 CorrectionUtils utils, AstNode contextNode, Expression targetExpression, |
50 List<Expression> arguments) { | 50 List<Expression> arguments) { |
51 // prepare edits to replace parameters with arguments | 51 // prepare edits to replace parameters with arguments |
52 List<SourceEdit> edits = <SourceEdit>[]; | 52 List<SourceEdit> edits = <SourceEdit>[]; |
53 part._parameters.forEach( | 53 part._parameters.forEach((ParameterElement parameter, |
54 (ParameterElement parameter, List<_ParameterOccurrence> occurrences) { | 54 List<_ParameterOccurrence> occurrences) { |
55 // prepare argument | 55 // prepare argument |
56 Expression argument = null; | 56 Expression argument = null; |
57 for (Expression arg in arguments) { | 57 for (Expression arg in arguments) { |
58 if (arg.bestParameterElement == parameter) { | 58 if (arg.bestParameterElement == parameter) { |
59 argument = arg; | 59 argument = arg; |
60 break; | 60 break; |
61 } | 61 } |
62 } | 62 } |
63 if (argument is NamedExpression) { | 63 if (argument is NamedExpression) { |
64 argument = (argument as NamedExpression).expression; | 64 argument = (argument as NamedExpression).expression; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 if (element.isSynthetic) { | 337 if (element.isSynthetic) { |
338 return fatalStatus; | 338 return fatalStatus; |
339 } | 339 } |
340 _methodElement = element as ExecutableElement; | 340 _methodElement = element as ExecutableElement; |
341 _isAccessor = element is PropertyAccessorElement; | 341 _isAccessor = element is PropertyAccessorElement; |
342 _methodUnit = element.unit; | 342 _methodUnit = element.unit; |
343 _methodUtils = new CorrectionUtils(_methodUnit); | 343 _methodUtils = new CorrectionUtils(_methodUnit); |
344 // class member | 344 // class member |
345 bool isClassMember = element.enclosingElement is ClassElement; | 345 bool isClassMember = element.enclosingElement is ClassElement; |
346 if (element is MethodElement || _isAccessor && isClassMember) { | 346 if (element is MethodElement || _isAccessor && isClassMember) { |
347 MethodDeclaration methodDeclaration = element.node; | 347 MethodDeclaration methodDeclaration = element.computeNode(); |
348 _methodNode = methodDeclaration; | 348 _methodNode = methodDeclaration; |
349 _methodParameters = methodDeclaration.parameters; | 349 _methodParameters = methodDeclaration.parameters; |
350 _methodBody = methodDeclaration.body; | 350 _methodBody = methodDeclaration.body; |
351 // prepare mode | 351 // prepare mode |
352 isDeclaration = node == methodDeclaration.name; | 352 isDeclaration = node == methodDeclaration.name; |
353 deleteSource = isDeclaration; | 353 deleteSource = isDeclaration; |
354 inlineAll = deleteSource; | 354 inlineAll = deleteSource; |
355 return new RefactoringStatus(); | 355 return new RefactoringStatus(); |
356 } | 356 } |
357 // unit member | 357 // unit member |
358 bool isUnitMember = element.enclosingElement is CompilationUnitElement; | 358 bool isUnitMember = element.enclosingElement is CompilationUnitElement; |
359 if (element is FunctionElement || _isAccessor && isUnitMember) { | 359 if (element is FunctionElement || _isAccessor && isUnitMember) { |
360 FunctionDeclaration functionDeclaration = element.node; | 360 FunctionDeclaration functionDeclaration = element.computeNode(); |
361 _methodNode = functionDeclaration; | 361 _methodNode = functionDeclaration; |
362 _methodParameters = functionDeclaration.functionExpression.parameters; | 362 _methodParameters = functionDeclaration.functionExpression.parameters; |
363 _methodBody = functionDeclaration.functionExpression.body; | 363 _methodBody = functionDeclaration.functionExpression.body; |
364 // prepare mode | 364 // prepare mode |
365 isDeclaration = node == functionDeclaration.name; | 365 isDeclaration = node == functionDeclaration.name; |
366 deleteSource = isDeclaration; | 366 deleteSource = isDeclaration; |
367 inlineAll = deleteSource; | 367 inlineAll = deleteSource; |
368 return new RefactoringStatus(); | 368 return new RefactoringStatus(); |
369 } | 369 } |
370 // OK | 370 // OK |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 } | 809 } |
810 | 810 |
811 void _addVariable(SimpleIdentifier node) { | 811 void _addVariable(SimpleIdentifier node) { |
812 VariableElement variableElement = getLocalVariableElement(node); | 812 VariableElement variableElement = getLocalVariableElement(node); |
813 if (variableElement != null) { | 813 if (variableElement != null) { |
814 SourceRange nodeRange = rangeNode(node); | 814 SourceRange nodeRange = rangeNode(node); |
815 result.addVariable(variableElement, nodeRange); | 815 result.addVariable(variableElement, nodeRange); |
816 } | 816 } |
817 } | 817 } |
818 } | 818 } |
OLD | NEW |