| 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.extract_local; | 5 library services.src.refactoring.extract_local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 10 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 String prefix = utils.getNodePrefix(target); | 143 String prefix = utils.getNodePrefix(target); |
| 144 SourceEdit edit = | 144 SourceEdit edit = |
| 145 new SourceEdit(target.offset, 0, declarationSource + eol + prefix); | 145 new SourceEdit(target.offset, 0, declarationSource + eol + prefix); |
| 146 doSourceChange_addElementEdit(change, unitElement, edit); | 146 doSourceChange_addElementEdit(change, unitElement, edit); |
| 147 } else if (target is ExpressionFunctionBody) { | 147 } else if (target is ExpressionFunctionBody) { |
| 148 String prefix = utils.getNodePrefix(target.parent); | 148 String prefix = utils.getNodePrefix(target.parent); |
| 149 String indent = utils.getIndent(1); | 149 String indent = utils.getIndent(1); |
| 150 String declStatement = prefix + indent + declarationSource + eol; | 150 String declStatement = prefix + indent + declarationSource + eol; |
| 151 String exprStatement = prefix + indent + 'return '; | 151 String exprStatement = prefix + indent + 'return '; |
| 152 Expression expr = target.expression; | 152 Expression expr = target.expression; |
| 153 doSourceChange_addElementEdit(change, unitElement, new SourceEdit( | 153 doSourceChange_addElementEdit( |
| 154 target.offset, expr.offset - target.offset, | 154 change, |
| 155 '{' + eol + declStatement + exprStatement)); | 155 unitElement, |
| 156 new SourceEdit(target.offset, expr.offset - target.offset, |
| 157 '{' + eol + declStatement + exprStatement)); |
| 156 doSourceChange_addElementEdit(change, unitElement, | 158 doSourceChange_addElementEdit(change, unitElement, |
| 157 new SourceEdit(expr.end, 0, ';' + eol + prefix + '}')); | 159 new SourceEdit(expr.end, 0, ';' + eol + prefix + '}')); |
| 158 } | 160 } |
| 159 } | 161 } |
| 160 // prepare replacement | 162 // prepare replacement |
| 161 String occurrenceReplacement = name; | 163 String occurrenceReplacement = name; |
| 162 if (stringLiteralPart != null) { | 164 if (stringLiteralPart != null) { |
| 163 occurrenceReplacement = "\${$name}"; | 165 occurrenceReplacement = "\${$name}"; |
| 164 } | 166 } |
| 165 // replace occurrences with variable reference | 167 // replace occurrences with variable reference |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 return false; | 373 return false; |
| 372 } | 374 } |
| 373 | 375 |
| 374 void _prepareNames() { | 376 void _prepareNames() { |
| 375 names.clear(); | 377 names.clear(); |
| 376 if (stringLiteralPart != null) { | 378 if (stringLiteralPart != null) { |
| 377 names.addAll(getVariableNameSuggestionsForText( | 379 names.addAll(getVariableNameSuggestionsForText( |
| 378 stringLiteralPart, excludedVariableNames)); | 380 stringLiteralPart, excludedVariableNames)); |
| 379 } else if (singleExpression != null) { | 381 } else if (singleExpression != null) { |
| 380 names.addAll(getVariableNameSuggestionsForExpression( | 382 names.addAll(getVariableNameSuggestionsForExpression( |
| 381 singleExpression.staticType, singleExpression, | 383 singleExpression.staticType, |
| 384 singleExpression, |
| 382 excludedVariableNames)); | 385 excludedVariableNames)); |
| 383 } | 386 } |
| 384 } | 387 } |
| 385 | 388 |
| 386 /** | 389 /** |
| 387 * Prepares all occurrences of the source which matches given selection, | 390 * Prepares all occurrences of the source which matches given selection, |
| 388 * sorted by offsets. | 391 * sorted by offsets. |
| 389 */ | 392 */ |
| 390 void _prepareOccurrences() { | 393 void _prepareOccurrences() { |
| 391 occurrences.clear(); | 394 occurrences.clear(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 | 600 |
| 598 _TokenLocalElementVisitor(this.map); | 601 _TokenLocalElementVisitor(this.map); |
| 599 | 602 |
| 600 visitSimpleIdentifier(SimpleIdentifier node) { | 603 visitSimpleIdentifier(SimpleIdentifier node) { |
| 601 Element element = node.staticElement; | 604 Element element = node.staticElement; |
| 602 if (element is LocalVariableElement) { | 605 if (element is LocalVariableElement) { |
| 603 map[node.token] = element; | 606 map[node.token] = element; |
| 604 } | 607 } |
| 605 } | 608 } |
| 606 } | 609 } |
| OLD | NEW |