| 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_local; | 5 library services.src.refactoring.inline_local; |
| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 StringInterpolation target = parent.parent; | 138 StringInterpolation target = parent.parent; |
| 139 if (initializer is SingleStringLiteral && | 139 if (initializer is SingleStringLiteral && |
| 140 !initializer.isRaw && | 140 !initializer.isRaw && |
| 141 initializer.isSingleQuoted == target.isSingleQuoted && | 141 initializer.isSingleQuoted == target.isSingleQuoted && |
| 142 (!initializer.isMultiline || target.isMultiline)) { | 142 (!initializer.isMultiline || target.isMultiline)) { |
| 143 range = rangeNode(parent); | 143 range = rangeNode(parent); |
| 144 // unwrap the literal being inlined | 144 // unwrap the literal being inlined |
| 145 int initOffset = initializer.contentsOffset; | 145 int initOffset = initializer.contentsOffset; |
| 146 int initLength = initializer.contentsEnd - initOffset; | 146 int initLength = initializer.contentsEnd - initOffset; |
| 147 codeForReference = utils.getText(initOffset, initLength); | 147 codeForReference = utils.getText(initOffset, initLength); |
| 148 // drop leading multiline EOL | |
| 149 if (initializer.isMultiline) { | |
| 150 if (codeForReference.startsWith('\n')) { | |
| 151 codeForReference = codeForReference.substring(1); | |
| 152 } else if (codeForReference.startsWith('\r\n')) { | |
| 153 codeForReference = codeForReference.substring(2); | |
| 154 } | |
| 155 } | |
| 156 } else if (_shouldBeExpressionInterpolation(parent, initializer)) { | 148 } else if (_shouldBeExpressionInterpolation(parent, initializer)) { |
| 157 codeForReference = '{$initializerCode}'; | 149 codeForReference = '{$initializerCode}'; |
| 158 } else { | 150 } else { |
| 159 codeForReference = initializerCode; | 151 codeForReference = initializerCode; |
| 160 } | 152 } |
| 161 } else if (_shouldUseParenthesis(initializer, node)) { | 153 } else if (_shouldUseParenthesis(initializer, node)) { |
| 162 codeForReference = '($initializerCode)'; | 154 codeForReference = '($initializerCode)'; |
| 163 } else { | 155 } else { |
| 164 codeForReference = initializerCode; | 156 codeForReference = initializerCode; |
| 165 } | 157 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 if (initializerOperator == TokenType.MINUS || | 202 if (initializerOperator == TokenType.MINUS || |
| 211 initializerOperator == TokenType.MINUS_MINUS) { | 203 initializerOperator == TokenType.MINUS_MINUS) { |
| 212 return true; | 204 return true; |
| 213 } | 205 } |
| 214 } | 206 } |
| 215 } | 207 } |
| 216 // no () is needed | 208 // no () is needed |
| 217 return false; | 209 return false; |
| 218 } | 210 } |
| 219 } | 211 } |
| OLD | NEW |