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

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

Issue 576703004: Send final problems even if 'validateOnly'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Request expensive validation in 'checkFinalConditions'. Created 6 years, 3 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 | Annotate | Revision Log
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.rename_local; 5 library services.src.refactoring.rename_local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' hide Element; 9 import 'package:analysis_server/src/protocol.dart' hide Element;
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 SourceRange elementRange = element.visibleRange; 100 SourceRange elementRange = element.visibleRange;
101 unit.accept(new _ConflictValidatorVisitor(this, result, elementRange)); 101 unit.accept(new _ConflictValidatorVisitor(this, result, elementRange));
102 } 102 }
103 } 103 }
104 104
105 105
106 class _ConflictValidatorVisitor extends RecursiveAstVisitor { 106 class _ConflictValidatorVisitor extends RecursiveAstVisitor {
107 final RenameLocalRefactoringImpl refactoring; 107 final RenameLocalRefactoringImpl refactoring;
108 final RefactoringStatus result; 108 final RefactoringStatus result;
109 final SourceRange elementRange; 109 final SourceRange elementRange;
110 final Set<Element> conflictingLocals = new Set<Element>();
110 111
111 _ConflictValidatorVisitor(this.refactoring, this.result, this.elementRange); 112 _ConflictValidatorVisitor(this.refactoring, this.result, this.elementRange);
112 113
113 @override 114 @override
114 visitSimpleIdentifier(SimpleIdentifier node) { 115 visitSimpleIdentifier(SimpleIdentifier node) {
115 Element nodeElement = node.bestElement; 116 Element nodeElement = node.bestElement;
116 String newName = refactoring.newName; 117 String newName = refactoring.newName;
117 if (nodeElement != null && nodeElement.name == newName) { 118 if (nodeElement != null && nodeElement.name == newName) {
118 // duplicate declaration 119 // duplicate declaration
119 if (haveIntersectingRanges(refactoring.element, nodeElement)) { 120 if (node.inDeclarationContext() &&
121 haveIntersectingRanges(refactoring.element, nodeElement)) {
122 conflictingLocals.add(nodeElement);
120 String nodeKind = nodeElement.kind.displayName; 123 String nodeKind = nodeElement.kind.displayName;
121 String message = "Duplicate ${nodeKind} '$newName'."; 124 String message = "Duplicate ${nodeKind} '$newName'.";
122 result.addError(message, new Location.fromElement(nodeElement)); 125 result.addError(message, new Location.fromElement(nodeElement));
123 return; 126 return;
124 } 127 }
128 if (conflictingLocals.contains(nodeElement)) {
129 return;
130 }
125 // shadowing referenced element 131 // shadowing referenced element
126 if (elementRange.contains(node.offset) && 132 if (elementRange.contains(node.offset) &&
127 !node.isQualified && 133 !node.isQualified &&
128 !_isNamedExpressionName(node)) { 134 !_isNamedExpressionName(node)) {
129 nodeElement = getSyntheticAccessorVariable(nodeElement); 135 nodeElement = getSyntheticAccessorVariable(nodeElement);
130 String nodeKind = nodeElement.kind.displayName; 136 String nodeKind = nodeElement.kind.displayName;
131 String nodeName = getElementQualifiedName(nodeElement); 137 String nodeName = getElementQualifiedName(nodeElement);
132 String nameElementSourceName = nodeElement.source.shortName; 138 String nameElementSourceName = nodeElement.source.shortName;
133 String refKind = refactoring.element.kind.displayName; 139 String refKind = refactoring.element.kind.displayName;
134 String message = 140 String message =
135 'Usage of $nodeKind "$nodeName" declared in ' 141 'Usage of $nodeKind "$nodeName" declared in '
136 '"$nameElementSourceName" will be shadowed by renamed $refKind.' ; 142 '"$nameElementSourceName" will be shadowed by renamed $refKind.' ;
137 result.addError(message, new Location.fromNode(node)); 143 result.addError(message, new Location.fromNode(node));
138 } 144 }
139 } 145 }
140 } 146 }
141 147
142 static bool _isNamedExpressionName(SimpleIdentifier node) { 148 static bool _isNamedExpressionName(SimpleIdentifier node) {
143 return node.parent is Label && node.parent.parent is NamedExpression; 149 return node.parent is Label && node.parent.parent is NamedExpression;
144 } 150 }
145 } 151 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/edit/edit_domain.dart ('k') | pkg/analysis_server/test/edit/refactoring_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698