OLD | NEW |
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.move_file; | 5 library services.src.refactoring.move_file; |
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/status.dart'; | 10 import 'package:analysis_server/src/services/correction/status.dart'; |
11 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 11 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
12 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; | 12 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; |
13 import 'package:analysis_server/src/services/search/search_engine.dart'; | 13 import 'package:analysis_server/src/services/search/search_engine.dart'; |
14 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
17 import 'package:path/path.dart' as pathos; | 17 import 'package:path/path.dart' as pathos; |
18 | 18 |
19 | |
20 /** | 19 /** |
21 * [ExtractLocalRefactoring] implementation. | 20 * [ExtractLocalRefactoring] implementation. |
22 */ | 21 */ |
23 class MoveFileRefactoringImpl extends RefactoringImpl implements | 22 class MoveFileRefactoringImpl extends RefactoringImpl |
24 MoveFileRefactoring { | 23 implements MoveFileRefactoring { |
25 final pathos.Context pathContext; | 24 final pathos.Context pathContext; |
26 final SearchEngine searchEngine; | 25 final SearchEngine searchEngine; |
27 final AnalysisContext context; | 26 final AnalysisContext context; |
28 final Source source; | 27 final Source source; |
29 | 28 |
30 String oldFile; | 29 String oldFile; |
31 String newFile; | 30 String newFile; |
32 | 31 |
33 SourceChange change; | 32 SourceChange change; |
34 LibraryElement library; | 33 LibraryElement library; |
35 String oldLibraryDir; | 34 String oldLibraryDir; |
36 String newLibraryDir; | 35 String newLibraryDir; |
37 | 36 |
38 MoveFileRefactoringImpl(this.pathContext, this.searchEngine, this.context, | 37 MoveFileRefactoringImpl( |
39 this.source) { | 38 this.pathContext, this.searchEngine, this.context, this.source) { |
40 oldFile = source.fullName; | 39 oldFile = source.fullName; |
41 } | 40 } |
42 | 41 |
43 @override | 42 @override |
44 String get refactoringName => 'Move File'; | 43 String get refactoringName => 'Move File'; |
45 | 44 |
46 @override | 45 @override |
47 Future<RefactoringStatus> checkFinalConditions() { | 46 Future<RefactoringStatus> checkFinalConditions() { |
48 RefactoringStatus result = new RefactoringStatus(); | 47 RefactoringStatus result = new RefactoringStatus(); |
49 return new Future.value(result); | 48 return new Future.value(result); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 139 |
141 void _updateUriReference(UriReferencedElement element) { | 140 void _updateUriReference(UriReferencedElement element) { |
142 if (!element.isSynthetic) { | 141 if (!element.isSynthetic) { |
143 String elementUri = element.uri; | 142 String elementUri = element.uri; |
144 if (_isRelativeUri(elementUri)) { | 143 if (_isRelativeUri(elementUri)) { |
145 String elementPath = pathContext.join(oldLibraryDir, elementUri); | 144 String elementPath = pathContext.join(oldLibraryDir, elementUri); |
146 String newUri = _getRelativeUri(elementPath, newLibraryDir); | 145 String newUri = _getRelativeUri(elementPath, newLibraryDir); |
147 int uriOffset = element.uriOffset; | 146 int uriOffset = element.uriOffset; |
148 int uriLength = element.uriEnd - uriOffset; | 147 int uriLength = element.uriEnd - uriOffset; |
149 doSourceChange_addElementEdit( | 148 doSourceChange_addElementEdit( |
150 change, | 149 change, library, new SourceEdit(uriOffset, uriLength, "'$newUri'")); |
151 library, | |
152 new SourceEdit(uriOffset, uriLength, "'$newUri'")); | |
153 } | 150 } |
154 } | 151 } |
155 } | 152 } |
156 | 153 |
157 void _updateUriReferences(List<UriReferencedElement> elements) { | 154 void _updateUriReferences(List<UriReferencedElement> elements) { |
158 for (UriReferencedElement element in elements) { | 155 for (UriReferencedElement element in elements) { |
159 _updateUriReference(element); | 156 _updateUriReference(element); |
160 } | 157 } |
161 } | 158 } |
162 } | 159 } |
OLD | NEW |