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

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

Issue 2669353002: Stop using Element.computeNode() in refactorings and fixes. (Closed)
Patch Set: documentation comments Created 3 years, 10 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.refactoring; 5 library services.refactoring;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart' 9 import 'package:analysis_server/plugin/protocol/protocol.dart'
10 show RefactoringMethodParameter, SourceChange; 10 show RefactoringMethodParameter, SourceChange;
11 import 'package:analysis_server/src/services/correction/status.dart'; 11 import 'package:analysis_server/src/services/correction/status.dart';
12 import 'package:analysis_server/src/services/refactoring/convert_getter_to_metho d.dart'; 12 import 'package:analysis_server/src/services/refactoring/convert_getter_to_metho d.dart';
13 import 'package:analysis_server/src/services/refactoring/convert_method_to_gette r.dart'; 13 import 'package:analysis_server/src/services/refactoring/convert_method_to_gette r.dart';
14 import 'package:analysis_server/src/services/refactoring/extract_local.dart'; 14 import 'package:analysis_server/src/services/refactoring/extract_local.dart';
15 import 'package:analysis_server/src/services/refactoring/extract_method.dart'; 15 import 'package:analysis_server/src/services/refactoring/extract_method.dart';
16 import 'package:analysis_server/src/services/refactoring/inline_local.dart'; 16 import 'package:analysis_server/src/services/refactoring/inline_local.dart';
17 import 'package:analysis_server/src/services/refactoring/inline_method.dart'; 17 import 'package:analysis_server/src/services/refactoring/inline_method.dart';
18 import 'package:analysis_server/src/services/refactoring/move_file.dart'; 18 import 'package:analysis_server/src/services/refactoring/move_file.dart';
19 import 'package:analysis_server/src/services/refactoring/rename_class_member.dar t'; 19 import 'package:analysis_server/src/services/refactoring/rename_class_member.dar t';
20 import 'package:analysis_server/src/services/refactoring/rename_constructor.dart '; 20 import 'package:analysis_server/src/services/refactoring/rename_constructor.dart ';
21 import 'package:analysis_server/src/services/refactoring/rename_import.dart'; 21 import 'package:analysis_server/src/services/refactoring/rename_import.dart';
22 import 'package:analysis_server/src/services/refactoring/rename_label.dart'; 22 import 'package:analysis_server/src/services/refactoring/rename_label.dart';
23 import 'package:analysis_server/src/services/refactoring/rename_library.dart'; 23 import 'package:analysis_server/src/services/refactoring/rename_library.dart';
24 import 'package:analysis_server/src/services/refactoring/rename_local.dart'; 24 import 'package:analysis_server/src/services/refactoring/rename_local.dart';
25 import 'package:analysis_server/src/services/refactoring/rename_unit_member.dart '; 25 import 'package:analysis_server/src/services/refactoring/rename_unit_member.dart ';
26 import 'package:analysis_server/src/services/search/search_engine.dart'; 26 import 'package:analysis_server/src/services/search/search_engine.dart';
27 import 'package:analyzer/dart/ast/ast.dart'; 27 import 'package:analyzer/dart/ast/ast.dart';
28 import 'package:analyzer/dart/element/element.dart'; 28 import 'package:analyzer/dart/element/element.dart';
29 import 'package:analyzer/file_system/file_system.dart'; 29 import 'package:analyzer/file_system/file_system.dart';
30 import 'package:analyzer/src/dart/element/ast_provider.dart';
30 import 'package:analyzer/src/generated/engine.dart'; 31 import 'package:analyzer/src/generated/engine.dart';
31 import 'package:analyzer/src/generated/source.dart'; 32 import 'package:analyzer/src/generated/source.dart';
32 33
33 /** 34 /**
34 * Completes with the resolved [CompilationUnit] that contains the [element].
35 */
36 typedef Future<CompilationUnit> GetResolvedUnit(Element element);
37
38 /**
39 * [Refactoring] to convert getters into normal [MethodDeclaration]s. 35 * [Refactoring] to convert getters into normal [MethodDeclaration]s.
40 */ 36 */
41 abstract class ConvertGetterToMethodRefactoring implements Refactoring { 37 abstract class ConvertGetterToMethodRefactoring implements Refactoring {
42 /** 38 /**
43 * Returns a new [ConvertMethodToGetterRefactoring] instance for converting 39 * Returns a new [ConvertMethodToGetterRefactoring] instance for converting
44 * [element] and all the corresponding hierarchy elements. 40 * [element] and all the corresponding hierarchy elements.
45 */ 41 */
46 factory ConvertGetterToMethodRefactoring( 42 factory ConvertGetterToMethodRefactoring(SearchEngine searchEngine,
47 SearchEngine searchEngine, PropertyAccessorElement element) { 43 AstProvider astProvider, PropertyAccessorElement element) {
48 return new ConvertGetterToMethodRefactoringImpl(searchEngine, element); 44 return new ConvertGetterToMethodRefactoringImpl(
45 searchEngine, astProvider, element);
49 } 46 }
50 } 47 }
51 48
52 /** 49 /**
53 * [Refactoring] to convert normal [MethodDeclaration]s into getters. 50 * [Refactoring] to convert normal [MethodDeclaration]s into getters.
54 */ 51 */
55 abstract class ConvertMethodToGetterRefactoring implements Refactoring { 52 abstract class ConvertMethodToGetterRefactoring implements Refactoring {
56 /** 53 /**
57 * Returns a new [ConvertMethodToGetterRefactoring] instance for converting 54 * Returns a new [ConvertMethodToGetterRefactoring] instance for converting
58 * [element] and all the corresponding hierarchy elements. 55 * [element] and all the corresponding hierarchy elements.
59 */ 56 */
60 factory ConvertMethodToGetterRefactoring(SearchEngine searchEngine, 57 factory ConvertMethodToGetterRefactoring(SearchEngine searchEngine,
61 GetResolvedUnit getResolvedUnit, ExecutableElement element) { 58 AstProvider astProvider, ExecutableElement element) {
62 return new ConvertMethodToGetterRefactoringImpl( 59 return new ConvertMethodToGetterRefactoringImpl(
63 searchEngine, getResolvedUnit, element); 60 searchEngine, astProvider, element);
64 } 61 }
65 } 62 }
66 63
67 /** 64 /**
68 * [Refactoring] to extract an expression into a local variable declaration. 65 * [Refactoring] to extract an expression into a local variable declaration.
69 */ 66 */
70 abstract class ExtractLocalRefactoring implements Refactoring { 67 abstract class ExtractLocalRefactoring implements Refactoring {
71 /** 68 /**
72 * Returns a new [ExtractLocalRefactoring] instance. 69 * Returns a new [ExtractLocalRefactoring] instance.
73 */ 70 */
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 RefactoringStatus checkName(); 221 RefactoringStatus checkName();
225 } 222 }
226 223
227 /** 224 /**
228 * [Refactoring] to inline a local [VariableElement]. 225 * [Refactoring] to inline a local [VariableElement].
229 */ 226 */
230 abstract class InlineLocalRefactoring implements Refactoring { 227 abstract class InlineLocalRefactoring implements Refactoring {
231 /** 228 /**
232 * Returns a new [InlineLocalRefactoring] instance. 229 * Returns a new [InlineLocalRefactoring] instance.
233 */ 230 */
234 factory InlineLocalRefactoring( 231 factory InlineLocalRefactoring(SearchEngine searchEngine,
235 SearchEngine searchEngine, CompilationUnit unit, int offset) { 232 AstProvider astProvider, CompilationUnit unit, int offset) {
236 return new InlineLocalRefactoringImpl(searchEngine, unit, offset); 233 return new InlineLocalRefactoringImpl(
234 searchEngine, astProvider, unit, offset);
237 } 235 }
238 236
239 /** 237 /**
240 * Returns the number of references to the [VariableElement]. 238 * Returns the number of references to the [VariableElement].
241 */ 239 */
242 int get referenceCount; 240 int get referenceCount;
243 241
244 /** 242 /**
245 * Returns the name of the variable being inlined. 243 * Returns the name of the variable being inlined.
246 */ 244 */
247 String get variableName; 245 String get variableName;
248 } 246 }
249 247
250 /** 248 /**
251 * [Refactoring] to inline an [ExecutableElement]. 249 * [Refactoring] to inline an [ExecutableElement].
252 */ 250 */
253 abstract class InlineMethodRefactoring implements Refactoring { 251 abstract class InlineMethodRefactoring implements Refactoring {
254 /** 252 /**
255 * Returns a new [InlineMethodRefactoring] instance. 253 * Returns a new [InlineMethodRefactoring] instance.
256 */ 254 */
257 factory InlineMethodRefactoring(SearchEngine searchEngine, 255 factory InlineMethodRefactoring(SearchEngine searchEngine,
258 GetResolvedUnit getResolvedUnit, CompilationUnit unit, int offset) { 256 AstProvider astProvider, CompilationUnit unit, int offset) {
259 return new InlineMethodRefactoringImpl( 257 return new InlineMethodRefactoringImpl(
260 searchEngine, getResolvedUnit, unit, offset); 258 searchEngine, astProvider, unit, offset);
261 } 259 }
262 260
263 /** 261 /**
264 * The name of the class enclosing the method being inlined. 262 * The name of the class enclosing the method being inlined.
265 * If not a class member is being inlined, then `null`. 263 * If not a class member is being inlined, then `null`.
266 */ 264 */
267 String get className; 265 String get className;
268 266
269 /** 267 /**
270 * True if the method being inlined should be removed. 268 * True if the method being inlined should be removed.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 365
368 /** 366 /**
369 * Abstract [Refactoring] for renaming some [Element]. 367 * Abstract [Refactoring] for renaming some [Element].
370 */ 368 */
371 abstract class RenameRefactoring implements Refactoring { 369 abstract class RenameRefactoring implements Refactoring {
372 /** 370 /**
373 * Returns a new [RenameRefactoring] instance for renaming [element], 371 * Returns a new [RenameRefactoring] instance for renaming [element],
374 * maybe `null` if there is no support for renaming [Element]s of the given 372 * maybe `null` if there is no support for renaming [Element]s of the given
375 * type. 373 * type.
376 */ 374 */
377 factory RenameRefactoring(SearchEngine searchEngine, Element element) { 375 factory RenameRefactoring(
376 SearchEngine searchEngine, AstProvider astProvider, Element element) {
378 if (element == null) { 377 if (element == null) {
379 return null; 378 return null;
380 } 379 }
381 if (element is PropertyAccessorElement) { 380 if (element is PropertyAccessorElement) {
382 element = (element as PropertyAccessorElement).variable; 381 element = (element as PropertyAccessorElement).variable;
383 } 382 }
384 if (element.enclosingElement is CompilationUnitElement) { 383 if (element.enclosingElement is CompilationUnitElement) {
385 return new RenameUnitMemberRefactoringImpl(searchEngine, element); 384 return new RenameUnitMemberRefactoringImpl(searchEngine, element);
386 } 385 }
387 if (element is ConstructorElement) { 386 if (element is ConstructorElement) {
388 return new RenameConstructorRefactoringImpl(searchEngine, element); 387 return new RenameConstructorRefactoringImpl(
388 searchEngine, astProvider, element);
389 } 389 }
390 if (element is ImportElement) { 390 if (element is ImportElement) {
391 return new RenameImportRefactoringImpl(searchEngine, element); 391 return new RenameImportRefactoringImpl(searchEngine, element);
392 } 392 }
393 if (element is LabelElement) { 393 if (element is LabelElement) {
394 return new RenameLabelRefactoringImpl(searchEngine, element); 394 return new RenameLabelRefactoringImpl(searchEngine, element);
395 } 395 }
396 if (element is LibraryElement) { 396 if (element is LibraryElement) {
397 return new RenameLibraryRefactoringImpl(searchEngine, element); 397 return new RenameLibraryRefactoringImpl(searchEngine, element);
398 } 398 }
(...skipping 26 matching lines...) Expand all
425 * Validates that the [newName] is a valid identifier and is appropriate for 425 * Validates that the [newName] is a valid identifier and is appropriate for
426 * the type of the [Element] being renamed. 426 * the type of the [Element] being renamed.
427 * 427 *
428 * It does not perform all the checks (such as checking for conflicts with any 428 * It does not perform all the checks (such as checking for conflicts with any
429 * existing names in any of the scopes containing the current name), as many 429 * existing names in any of the scopes containing the current name), as many
430 * of these checkes require search engine. Use [checkFinalConditions] for this 430 * of these checkes require search engine. Use [checkFinalConditions] for this
431 * level of checking. 431 * level of checking.
432 */ 432 */
433 RefactoringStatus checkNewName(); 433 RefactoringStatus checkNewName();
434 } 434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698