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

Side by Side Diff: pkg/analysis_server/lib/src/services/refactoring/inline_local.dart

Issue 1159563004: Rename Element.node (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 months 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 unified diff | Download patch
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 @override 67 @override
68 Future<RefactoringStatus> checkInitialConditions() async { 68 Future<RefactoringStatus> checkInitialConditions() async {
69 RefactoringStatus result = new RefactoringStatus(); 69 RefactoringStatus result = new RefactoringStatus();
70 // prepare variable 70 // prepare variable
71 { 71 {
72 AstNode offsetNode = new NodeLocator(offset).searchWithin(unit); 72 AstNode offsetNode = new NodeLocator(offset).searchWithin(unit);
73 if (offsetNode is SimpleIdentifier) { 73 if (offsetNode is SimpleIdentifier) {
74 Element element = offsetNode.staticElement; 74 Element element = offsetNode.staticElement;
75 if (element is LocalVariableElement) { 75 if (element is LocalVariableElement) {
76 _variableElement = element; 76 _variableElement = element;
77 _variableNode = element.node; 77 _variableNode = element.computeNode();
78 } 78 }
79 } 79 }
80 } 80 }
81 // validate node declaration 81 // validate node declaration
82 if (!_isVariableDeclaredInStatement()) { 82 if (!_isVariableDeclaredInStatement()) {
83 result = new RefactoringStatus.fatal( 83 result = new RefactoringStatus.fatal(
84 'Local variable declaration or reference must be selected ' 84 'Local variable declaration or reference must be selected '
85 'to activate this refactoring.'); 85 'to activate this refactoring.');
86 return new Future.value(result); 86 return new Future.value(result);
87 } 87 }
88 // should have initializer at declaration 88 // should have initializer at declaration
89 if (_variableNode.initializer == null) { 89 if (_variableNode.initializer == null) {
90 String message = format( 90 String message = format(
91 "Local variable '{0}' is not initialized at declaration.", 91 "Local variable '{0}' is not initialized at declaration.",
92 _variableElement.displayName); 92 _variableElement.displayName);
93 result = new RefactoringStatus.fatal( 93 result = new RefactoringStatus.fatal(
94 message, newLocation_fromNode(_variableNode)); 94 message, newLocation_fromNode(_variableNode));
95 return new Future.value(result); 95 return new Future.value(result);
96 } 96 }
97 // prepare references 97 // prepare references
98 _references = await searchEngine.searchReferences(_variableElement); 98 _references = await searchEngine.searchReferences(_variableElement);
99 // should not have assignments 99 // should not have assignments
100 for (SearchMatch reference in _references) { 100 for (SearchMatch reference in _references) {
101 if (reference.kind != MatchKind.READ) { 101 if (reference.kind != MatchKind.READ) {
102 String message = format( 102 String message = format(
103 "Local variable '{0}' is assigned more than once.", [ 103 "Local variable '{0}' is assigned more than once.",
104 _variableElement.displayName 104 [_variableElement.displayName]);
105 ]);
106 return new RefactoringStatus.fatal( 105 return new RefactoringStatus.fatal(
107 message, newLocation_fromMatch(reference)); 106 message, newLocation_fromMatch(reference));
108 } 107 }
109 } 108 }
110 // done 109 // done
111 return result; 110 return result;
112 } 111 }
113 112
114 @override 113 @override
115 Future<SourceChange> createChange() { 114 Future<SourceChange> createChange() {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (initializerOperator == TokenType.MINUS || 201 if (initializerOperator == TokenType.MINUS ||
203 initializerOperator == TokenType.MINUS_MINUS) { 202 initializerOperator == TokenType.MINUS_MINUS) {
204 return true; 203 return true;
205 } 204 }
206 } 205 }
207 } 206 }
208 // no () is needed 207 // no () is needed
209 return false; 208 return false;
210 } 209 }
211 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698