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

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

Issue 832343004: Issue 21959. Check that type of parameters in 'Extract Method' occurrences are exactly the same. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 79dad5975f6f39f32742992a0383d8ae01cbb2b5..963a6f4e4a391b8fa349d235fa9b5d67fdee3a92 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_method.dart
@@ -503,8 +503,8 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
List<SourceEdit> replaceEdits = <SourceEdit>[];
unit.accept(new _GetSourcePatternVisitor(range, pattern, replaceEdits));
replaceEdits = replaceEdits.reversed.toList();
- pattern.patternSource =
- SourceEdit.applySequence(originalSource, replaceEdits);
+ String source = SourceEdit.applySequence(originalSource, replaceEdits);
+ pattern.normalizedSource = _getNormalizedSource(source);
return pattern;
}
@@ -545,8 +545,6 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
_occurrences.clear();
// prepare selection
_SourcePattern selectionPattern = _getSourcePattern(selectionRange);
- String selectionSource =
- _getNormalizedSource(selectionPattern.patternSource);
Map<String, String> patternToSelectionName =
_inverseMap(selectionPattern.originalToPatternNames);
// prepare an enclosing parent - class or unit
@@ -555,7 +553,7 @@ class ExtractMethodRefactoringImpl extends RefactoringImpl implements
enclosingMemberParent.accept(
new _InitializeOccurrencesVisitor(
this,
- selectionSource,
+ selectionPattern,
patternToSelectionName));
}
@@ -841,6 +839,7 @@ class _GetSourcePatternVisitor extends GeneralizingAstVisitor {
String originalName = variableElement.displayName;
String patternName = pattern.originalToPatternNames[originalName];
if (patternName == null) {
+ pattern.parameterTypes.add(variableElement.type);
patternName = '__refVar${pattern.originalToPatternNames.length}';
pattern.originalToPatternNames[originalName] = patternName;
}
@@ -868,12 +867,12 @@ class _HasMethodInvocationVisitor extends RecursiveAstVisitor {
class _InitializeOccurrencesVisitor extends GeneralizingAstVisitor<Object> {
final ExtractMethodRefactoringImpl ref;
- final String selectionSource;
+ final _SourcePattern selectionPattern;
final Map<String, String> patternToSelectionName;
bool forceStatic = false;
- _InitializeOccurrencesVisitor(this.ref, this.selectionSource,
+ _InitializeOccurrencesVisitor(this.ref, this.selectionPattern,
this.patternToSelectionName);
@override
@@ -931,11 +930,10 @@ class _InitializeOccurrencesVisitor extends GeneralizingAstVisitor<Object> {
if (!ref._isExtractable(nodeRange)) {
return false;
}
- // prepare normalized node source
+ // prepare node source
_SourcePattern nodePattern = ref._getSourcePattern(nodeRange);
- String nodeSource = _getNormalizedSource(nodePattern.patternSource);
// if matches normalized node source, then add as occurrence
- if (nodeSource == selectionSource) {
+ if (selectionPattern.isCompatible(nodePattern)) {
_Occurrence occurrence =
new _Occurrence(nodeRange, ref.selectionRange.intersects(nodeRange));
ref._occurrences.add(occurrence);
@@ -1137,6 +1135,22 @@ class _ReturnTypeComputer extends RecursiveAstVisitor {
* pattern to the original variable names.
*/
class _SourcePattern {
- String patternSource;
+ final List<DartType> parameterTypes = <DartType>[];
+ String normalizedSource;
Map<String, String> originalToPatternNames = {};
+
+ bool isCompatible(_SourcePattern other) {
+ if (other.normalizedSource != normalizedSource) {
+ return false;
+ }
+ if (other.parameterTypes.length != parameterTypes.length) {
+ return false;
+ }
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (other.parameterTypes[i] != parameterTypes[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
}
« 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