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

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

Issue 498763003: Initial 'Extract Method' refactoring implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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.refactoring; 5 library services.refactoring;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol2.dart' show SourceChange; 9 import 'package:analysis_server/src/protocol2.dart' show
10 RefactoringMethodParameter, SourceChange;
10 import 'package:analysis_server/src/services/correction/status.dart'; 11 import 'package:analysis_server/src/services/correction/status.dart';
11 import 'package:analysis_server/src/services/refactoring/extract_local.dart'; 12 import 'package:analysis_server/src/services/refactoring/extract_local.dart';
13 import 'package:analysis_server/src/services/refactoring/extract_method.dart';
12 import 'package:analysis_server/src/services/refactoring/rename_class_member.dar t'; 14 import 'package:analysis_server/src/services/refactoring/rename_class_member.dar t';
13 import 'package:analysis_server/src/services/refactoring/rename_constructor.dart '; 15 import 'package:analysis_server/src/services/refactoring/rename_constructor.dart ';
14 import 'package:analysis_server/src/services/refactoring/rename_import.dart'; 16 import 'package:analysis_server/src/services/refactoring/rename_import.dart';
15 import 'package:analysis_server/src/services/refactoring/rename_library.dart'; 17 import 'package:analysis_server/src/services/refactoring/rename_library.dart';
16 import 'package:analysis_server/src/services/refactoring/rename_local.dart'; 18 import 'package:analysis_server/src/services/refactoring/rename_local.dart';
17 import 'package:analysis_server/src/services/refactoring/rename_unit_member.dart '; 19 import 'package:analysis_server/src/services/refactoring/rename_unit_member.dart ';
18 import 'package:analysis_server/src/services/search/search_engine.dart'; 20 import 'package:analysis_server/src/services/search/search_engine.dart';
19 import 'package:analyzer/src/generated/ast.dart'; 21 import 'package:analyzer/src/generated/ast.dart';
20 import 'package:analyzer/src/generated/element.dart'; 22 import 'package:analyzer/src/generated/element.dart';
21 23
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 * It does not perform all the checks (such as checking for conflicts with any 78 * It does not perform all the checks (such as checking for conflicts with any
77 * existing names in any of the scopes containing the current name), as many 79 * existing names in any of the scopes containing the current name), as many
78 * of these checkes require search engine. Use [checkFinalConditions] for this 80 * of these checkes require search engine. Use [checkFinalConditions] for this
79 * level of checking. 81 * level of checking.
80 */ 82 */
81 RefactoringStatus checkName(); 83 RefactoringStatus checkName();
82 } 84 }
83 85
84 86
85 /** 87 /**
88 * [Refactoring] to extract an [Expression] or [Statement]s into a new method.
89 */
90 abstract class ExtractMethodRefactoring implements Refactoring {
91 /**
92 * Returns a new [ExtractMethodRefactoring] instance.
93 */
94 factory ExtractMethodRefactoring(SearchEngine searchEngine,
95 CompilationUnit unit, int selectionOffset, int selectionLength) {
96 return new ExtractMethodRefactoringImpl(
97 searchEngine,
98 unit,
99 selectionOffset,
100 selectionLength);
101 }
102
103 /**
104 * True if a getter could be created rather than a method.
105 */
106 bool get canCreateGetter;
107
108 /**
109 * True if a getter should be created rather than a method.
110 */
111 void set createGetter(bool createGetter);
112
113 /**
114 * True if all occurrences of the expression or statements should be replaced
115 * by an invocation of the method. The expression or statements used to
116 * initiate the refactoring will always be replaced.
117 */
118 void set extractAll(bool extractAll);
119
120 /**
121 * The lengths of the expressions or statements that would be replaced by an
122 * invocation of the method. The lengths correspond to the offsets.
123 * In other words, for a given expression (or block of statements), if the
124 * offset of that expression is offsets[i], then the length of that expression
125 * is lengths[i].
126 */
127 List<int> get lengths;
128
129 /**
130 * The name that the method should be given.
131 */
132 void set name(String name);
133
134 /**
135 * The proposed names for the method.
136 *
137 * The first proposal should be used as the "best guess" (if it exists).
138 */
139 List<String> get names;
140
141 /**
142 * The offsets of the expressions or statements that would be replaced by an
143 * invocation of the method.
144 */
145 List<int> get offsets;
146
147 /**
148 * The proposed parameters for the method.
149 */
150 List<RefactoringMethodParameter> get parameters;
151
152 /**
153 * The parameters that should be defined for the method.
154 */
155 void set parameters(List<RefactoringMethodParameter> parameters);
156
157 /**
158 * The proposed return type for the method.
159 */
160 String get returnType;
161
162 /**
163 * The return type that should be defined for the method.
164 */
165 void set returnType(String returnType);
166
167 /**
168 * Validates that the [name] is a valid identifier and is appropriate for a
169 * method.
170 *
171 * It does not perform all the checks (such as checking for conflicts with any
172 * existing names in any of the scopes containing the current name), as many
173 * of these checkes require search engine. Use [checkFinalConditions] for this
174 * level of checking.
175 */
176 RefactoringStatus checkName();
177 }
178
179
180 /**
86 * Abstract interface for all refactorings. 181 * Abstract interface for all refactorings.
87 */ 182 */
88 abstract class Refactoring { 183 abstract class Refactoring {
89 /** 184 /**
90 * The ids of source edits that are not known to be valid. 185 * The ids of source edits that are not known to be valid.
91 * 186 *
92 * An edit is not known to be valid if there was insufficient type information 187 * An edit is not known to be valid if there was insufficient type information
93 * for the server to be able to determine whether or not the code needs to be 188 * for the server to be able to determine whether or not the code needs to be
94 * modified, such as when a member is being renamed and there is a reference 189 * modified, such as when a member is being renamed and there is a reference
95 * to a member from an unknown type. This field will be omitted if the change 190 * to a member from an unknown type. This field will be omitted if the change
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 * Validates that the [newName] is a valid identifier and is appropriate for 278 * Validates that the [newName] is a valid identifier and is appropriate for
184 * the type of the [Element] being renamed. 279 * the type of the [Element] being renamed.
185 * 280 *
186 * It does not perform all the checks (such as checking for conflicts with any 281 * It does not perform all the checks (such as checking for conflicts with any
187 * existing names in any of the scopes containing the current name), as many 282 * existing names in any of the scopes containing the current name), as many
188 * of these checkes require search engine. Use [checkFinalConditions] for this 283 * of these checkes require search engine. Use [checkFinalConditions] for this
189 * level of checking. 284 * level of checking.
190 */ 285 */
191 RefactoringStatus checkNewName(); 286 RefactoringStatus checkNewName();
192 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698