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

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

Issue 567083002: Issue 20358. Don't report referenced names of named parameters in named expressions as possible sha… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_local_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (unit == null) { 96 if (unit == null) {
97 return; 97 return;
98 } 98 }
99 // check for conflicts in the unit 99 // check for conflicts in the unit
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<Object> { 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 110
111 _ConflictValidatorVisitor(this.refactoring, this.result, this.elementRange); 111 _ConflictValidatorVisitor(this.refactoring, this.result, this.elementRange);
112 112
113 @override 113 @override
114 Object visitSimpleIdentifier(SimpleIdentifier node) { 114 visitSimpleIdentifier(SimpleIdentifier node) {
115 Element nodeElement = node.bestElement; 115 Element nodeElement = node.bestElement;
116 String newName = refactoring.newName; 116 String newName = refactoring.newName;
117 if (nodeElement != null && nodeElement.name == newName) { 117 if (nodeElement != null && nodeElement.name == newName) {
118 // duplicate declaration 118 // duplicate declaration
119 if (haveIntersectingRanges(refactoring.element, nodeElement)) { 119 if (haveIntersectingRanges(refactoring.element, nodeElement)) {
120 String nodeKind = nodeElement.kind.displayName; 120 String nodeKind = nodeElement.kind.displayName;
121 String message = "Duplicate ${nodeKind} '$newName'."; 121 String message = "Duplicate ${nodeKind} '$newName'.";
122 result.addError(message, new Location.fromElement(nodeElement)); 122 result.addError(message, new Location.fromElement(nodeElement));
123 return null; 123 return;
124 } 124 }
125 // shadowing referenced element 125 // shadowing referenced element
126 if (elementRange.contains(node.offset) && !node.isQualified) { 126 if (elementRange.contains(node.offset) &&
127 !node.isQualified &&
128 !_isNamedExpressionName(node)) {
127 nodeElement = getSyntheticAccessorVariable(nodeElement); 129 nodeElement = getSyntheticAccessorVariable(nodeElement);
128 String nodeKind = nodeElement.kind.displayName; 130 String nodeKind = nodeElement.kind.displayName;
129 String nodeName = getElementQualifiedName(nodeElement); 131 String nodeName = getElementQualifiedName(nodeElement);
130 String nameElementSourceName = nodeElement.source.shortName; 132 String nameElementSourceName = nodeElement.source.shortName;
131 String refKind = refactoring.element.kind.displayName; 133 String refKind = refactoring.element.kind.displayName;
132 String message = 134 String message =
133 'Usage of $nodeKind "$nodeName" declared in ' 135 'Usage of $nodeKind "$nodeName" declared in '
134 '"$nameElementSourceName" will be shadowed by renamed $refKind.' ; 136 '"$nameElementSourceName" will be shadowed by renamed $refKind.' ;
135 result.addError(message, new Location.fromNode(node)); 137 result.addError(message, new Location.fromNode(node));
136 } 138 }
137 } 139 }
138 return null; 140 }
141
142 static bool _isNamedExpressionName(SimpleIdentifier node) {
143 return node.parent is Label && node.parent.parent is NamedExpression;
139 } 144 }
140 } 145 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_local_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698