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

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

Issue 592123002: Move SourceReference, extract duplicate code. (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
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_class_member; 5 library services.src.refactoring.rename_class_member;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; 9 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind;
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
11 import 'package:analysis_server/src/services/correction/util.dart'; 11 import 'package:analysis_server/src/services/correction/util.dart';
12 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart '; 12 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart ';
13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
14 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da rt';
14 import 'package:analysis_server/src/services/refactoring/rename.dart'; 15 import 'package:analysis_server/src/services/refactoring/rename.dart';
15 import 'package:analysis_server/src/services/search/hierarchy.dart'; 16 import 'package:analysis_server/src/services/search/hierarchy.dart';
16 import 'package:analysis_server/src/services/search/search_engine.dart'; 17 import 'package:analysis_server/src/services/search/search_engine.dart';
17 import 'package:analyzer/src/generated/element.dart'; 18 import 'package:analyzer/src/generated/element.dart';
18 import 'package:analyzer/src/generated/java_core.dart'; 19 import 'package:analyzer/src/generated/java_core.dart';
19 20
20 21
21 /** 22 /**
22 * Checks if creating a method with the given [name] in [classElement] will 23 * Checks if creating a method with the given [name] in [classElement] will
23 * cause any conflicts. 24 * cause any conflicts.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 result.addStatus(validateFieldName(newName)); 79 result.addStatus(validateFieldName(newName));
79 } 80 }
80 } 81 }
81 if (element is MethodElement) { 82 if (element is MethodElement) {
82 result.addStatus(validateMethodName(newName)); 83 result.addStatus(validateMethodName(newName));
83 } 84 }
84 return result; 85 return result;
85 } 86 }
86 87
87 @override 88 @override
88 Future<SourceChange> createChange() { 89 Future fillChange() {
89 SourceChange change = new SourceChange(refactoringName);
90 // update declarations 90 // update declarations
91 for (Element renameElement in _validator.elements) { 91 for (Element renameElement in _validator.elements) {
92 if (renameElement.isSynthetic && renameElement is FieldElement) { 92 if (renameElement.isSynthetic && renameElement is FieldElement) {
93 addDeclarationEdit(change, renameElement.getter); 93 addDeclarationEdit(renameElement.getter);
94 addDeclarationEdit(change, renameElement.setter); 94 addDeclarationEdit(renameElement.setter);
95 } else { 95 } else {
96 addDeclarationEdit(change, renameElement); 96 addDeclarationEdit(renameElement);
97 } 97 }
98 } 98 }
99 // update references 99 // update references
100 List<SourceReference> references = 100 addReferenceEdits(_validator.references);
101 getSourceReferences(_validator.references);
102 for (SourceReference reference in references) {
103 addReferenceEdit(change, reference);
104 }
105 // potential matches 101 // potential matches
106 return searchEngine.searchMemberReferences(oldName).then((nameMatches) { 102 return searchEngine.searchMemberReferences(oldName).then((nameMatches) {
107 List<SourceReference> nameRefs = getSourceReferences(nameMatches); 103 List<SourceReference> nameRefs = getSourceReferences(nameMatches);
108 for (SourceReference reference in nameRefs) { 104 for (SourceReference reference in nameRefs) {
109 // ignore resolved reference, we have already updated it 105 // ignore resolved reference, we have already updated it
110 if (reference.isResolved) { 106 if (reference.isResolved) {
111 continue; 107 continue;
112 } 108 }
113 // check the element being renamed is accessible 109 // check the element being renamed is accessible
114 { 110 {
115 LibraryElement whereLibrary = reference.element.library; 111 LibraryElement whereLibrary = reference.element.library;
116 if (!element.isAccessibleIn(whereLibrary)) { 112 if (!element.isAccessibleIn(whereLibrary)) {
117 continue; 113 continue;
118 } 114 }
119 } 115 }
120 // add edit 116 // add edit
121 SourceEdit edit = 117 reference.addEdit(change, newName, id: _newPotentialId());
122 createReferenceEdit(reference, newName, id: _newPotentialId());
123 change.addElementEdit(reference.element, edit);
124 } 118 }
125 }).then((_) => change); 119 });
126 } 120 }
127 121
128 String _newPotentialId() { 122 String _newPotentialId() {
129 String id = potentialEditIds.length.toString(); 123 String id = potentialEditIds.length.toString();
130 potentialEditIds.add(id); 124 potentialEditIds.add(id);
131 return id; 125 return id;
132 } 126 }
133 } 127 }
134 128
135 129
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 250 }
257 return _prepareElements().then((_) { 251 return _prepareElements().then((_) {
258 return Future.forEach(elements, (Element element) { 252 return Future.forEach(elements, (Element element) {
259 return searchEngine.searchReferences(element).then((references) { 253 return searchEngine.searchReferences(element).then((references) {
260 this.references.addAll(references); 254 this.references.addAll(references);
261 }); 255 });
262 }); 256 });
263 }); 257 });
264 } 258 }
265 } 259 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698