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

Unified Diff: pkg/analysis_server/lib/src/services/refactoring/extract_method.dart

Issue 971203002: Don't allow to extract a closure as a getter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/extract_method_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
index 361d537c14e27bc73630659971c4b66f02ba8b7d..5126105cadde10631b06d882d69c1f75d9ae2080 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
@@ -71,6 +71,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
String returnType;
String name;
bool extractAll = true;
+ bool canCreateGetter = false;
bool createGetter = false;
final List<String> names = <String>[];
final List<int> offsets = <int>[];
@@ -100,18 +101,29 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
utils = new CorrectionUtils(unit);
}
- bool get canCreateGetter {
+ /**
+ * Initializes [canCreateGetter] flag.
+ */
+ bool _computeCanCreateGetter() {
+ // is a function expression
+ if (_selectionFunctionExpression != null) {
+ return false;
+ }
+ // has parameters
if (!parameters.isEmpty) {
return false;
}
+ // is assignment
if (_selectionExpression != null) {
if (_selectionExpression is AssignmentExpression) {
return false;
}
}
+ // doesn't return a value
if (_selectionStatements != null) {
return returnType != 'void';
}
+ // OK
return true;
}
@@ -188,10 +200,12 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
// prepare parts
result.addStatus(_initializeParameters());
_initializeReturnType();
- _initializeGetter();
// occurrences
_initializeOccurrences();
_prepareOffsetsLengths();
+ // getter
+ canCreateGetter = _computeCanCreateGetter();
+ _initializeCreateGetter();
// names
_prepareExcludedNames();
_prepareNames();
@@ -511,7 +525,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl
/**
* Initializes [createGetter] flag.
*/
- void _initializeGetter() {
+ void _initializeCreateGetter() {
createGetter = false;
// maybe we cannot at all
if (!canCreateGetter) {
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/extract_method_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698