| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
| 3 * | 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * | 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * | 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. | 12 * the License. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 package com.google.dart.engine.services.internal.refactoring; | 15 package com.google.dart.engine.services.internal.refactoring; |
| 16 | 16 |
| 17 import com.google.dart.engine.ast.ASTNode; | 17 import com.google.dart.engine.ast.ASTNode; |
| 18 import com.google.dart.engine.ast.Block; | 18 import com.google.dart.engine.ast.Block; |
| 19 import com.google.dart.engine.ast.CompilationUnit; | 19 import com.google.dart.engine.ast.CompilationUnit; |
| 20 import com.google.dart.engine.ast.Expression; | 20 import com.google.dart.engine.ast.Expression; |
| 21 import com.google.dart.engine.ast.InterpolationExpression; | 21 import com.google.dart.engine.ast.InterpolationExpression; |
| 22 import com.google.dart.engine.ast.SimpleIdentifier; | 22 import com.google.dart.engine.ast.SimpleIdentifier; |
| 23 import com.google.dart.engine.ast.Statement; | 23 import com.google.dart.engine.ast.Statement; |
| 24 import com.google.dart.engine.ast.VariableDeclaration; | 24 import com.google.dart.engine.ast.VariableDeclaration; |
| 25 import com.google.dart.engine.ast.VariableDeclarationList; | 25 import com.google.dart.engine.ast.VariableDeclarationList; |
| 26 import com.google.dart.engine.ast.VariableDeclarationStatement; | 26 import com.google.dart.engine.ast.VariableDeclarationStatement; |
| 27 import com.google.dart.engine.element.Element; |
| 27 import com.google.dart.engine.element.LocalVariableElement; | 28 import com.google.dart.engine.element.LocalVariableElement; |
| 28 import com.google.dart.engine.formatter.edit.Edit; | 29 import com.google.dart.engine.formatter.edit.Edit; |
| 29 import com.google.dart.engine.scanner.TokenType; | 30 import com.google.dart.engine.scanner.TokenType; |
| 30 import com.google.dart.engine.search.MatchKind; | 31 import com.google.dart.engine.search.MatchKind; |
| 31 import com.google.dart.engine.search.SearchMatch; | 32 import com.google.dart.engine.search.SearchMatch; |
| 32 import com.google.dart.engine.services.assist.AssistContext; | 33 import com.google.dart.engine.services.assist.AssistContext; |
| 33 import com.google.dart.engine.services.change.Change; | 34 import com.google.dart.engine.services.change.Change; |
| 34 import com.google.dart.engine.services.change.SourceChange; | 35 import com.google.dart.engine.services.change.SourceChange; |
| 35 import com.google.dart.engine.services.internal.correction.CorrectionUtils; | 36 import com.google.dart.engine.services.internal.correction.CorrectionUtils; |
| 36 import com.google.dart.engine.services.refactoring.InlineLocalRefactoring; | 37 import com.google.dart.engine.services.refactoring.InlineLocalRefactoring; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 pm = checkProgressMonitor(pm); | 74 pm = checkProgressMonitor(pm); |
| 74 pm.beginTask("Checking initial conditions", 5); | 75 pm.beginTask("Checking initial conditions", 5); |
| 75 try { | 76 try { |
| 76 RefactoringStatus result = new RefactoringStatus(); | 77 RefactoringStatus result = new RefactoringStatus(); |
| 77 // prepare variable | 78 // prepare variable |
| 78 variableElement = null; | 79 variableElement = null; |
| 79 { | 80 { |
| 80 ASTNode coveringNode = context.getCoveringNode(); | 81 ASTNode coveringNode = context.getCoveringNode(); |
| 81 if (coveringNode instanceof SimpleIdentifier) { | 82 if (coveringNode instanceof SimpleIdentifier) { |
| 82 SimpleIdentifier coveringIdentifier = (SimpleIdentifier) coveringNode; | 83 SimpleIdentifier coveringIdentifier = (SimpleIdentifier) coveringNode; |
| 83 if (coveringIdentifier.getElement() instanceof LocalVariableElement) { | 84 Element element = coveringIdentifier.getElement(); |
| 84 variableElement = (LocalVariableElement) coveringIdentifier.getEleme
nt(); | 85 if (element instanceof LocalVariableElement) { |
| 86 variableElement = (LocalVariableElement) element; |
| 85 variableNode = utils.findNode( | 87 variableNode = utils.findNode( |
| 86 variableElement.getNameOffset(), | 88 variableElement.getNameOffset(), |
| 87 VariableDeclaration.class); | 89 VariableDeclaration.class); |
| 88 } | 90 } |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 if (variableNode == null) { | 93 if (variableNode == null) { |
| 92 return RefactoringStatus.createFatalErrorStatus("Local variable declarat
ion or reference must be selected to activate this refactoring."); | 94 return RefactoringStatus.createFatalErrorStatus("Local variable declarat
ion or reference must be selected to activate this refactoring."); |
| 93 } | 95 } |
| 94 pm.worked(1); | 96 pm.worked(1); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 private boolean isIdentifierInStringInterpolation(int offset) { | 207 private boolean isIdentifierInStringInterpolation(int offset) { |
| 206 ASTNode node = utils.findNode(offset, ASTNode.class); | 208 ASTNode node = utils.findNode(offset, ASTNode.class); |
| 207 ASTNode parent = node.getParent(); | 209 ASTNode parent = node.getParent(); |
| 208 if (parent instanceof InterpolationExpression) { | 210 if (parent instanceof InterpolationExpression) { |
| 209 InterpolationExpression element = (InterpolationExpression) parent; | 211 InterpolationExpression element = (InterpolationExpression) parent; |
| 210 return element.getBeginToken().getType() == TokenType.STRING_INTERPOLATION
_IDENTIFIER; | 212 return element.getBeginToken().getType() == TokenType.STRING_INTERPOLATION
_IDENTIFIER; |
| 211 } | 213 } |
| 212 return false; | 214 return false; |
| 213 } | 215 } |
| 214 } | 216 } |
| OLD | NEW |