| 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.extract_local; | 5 library services.src.refactoring.extract_local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 10 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 void _invalidSelection(String message, Location location) { | 506 void _invalidSelection(String message, Location location) { |
| 507 status.addFatalError(message, location); | 507 status.addFatalError(message, location); |
| 508 reset(); | 508 reset(); |
| 509 } | 509 } |
| 510 | 510 |
| 511 bool _isFirstSelectedNode(AstNode node) => node == firstSelectedNode; | 511 bool _isFirstSelectedNode(AstNode node) => node == firstSelectedNode; |
| 512 } | 512 } |
| 513 | 513 |
| 514 | 514 |
| 515 class _HasStatementVisitor extends GeneralizingAstVisitor { | 515 class _HasStatementVisitor extends GeneralizingAstVisitor { |
| 516 final List<bool> result; | 516 bool result = false; |
| 517 | 517 |
| 518 _HasStatementVisitor(this.result); | 518 _HasStatementVisitor(); |
| 519 | 519 |
| 520 @override | 520 @override |
| 521 visitStatement(Statement node) { | 521 visitStatement(Statement node) { |
| 522 result[0] = true; | 522 result = true; |
| 523 } | 523 } |
| 524 } | 524 } |
| 525 | 525 |
| 526 | 526 |
| 527 class _OccurrencesVisitor extends GeneralizingAstVisitor<Object> { | 527 class _OccurrencesVisitor extends GeneralizingAstVisitor<Object> { |
| 528 final ExtractLocalRefactoringImpl ref; | 528 final ExtractLocalRefactoringImpl ref; |
| 529 final List<SourceRange> occurrences; | 529 final List<SourceRange> occurrences; |
| 530 final String selectionSource; | 530 final String selectionSource; |
| 531 | 531 |
| 532 _OccurrencesVisitor(this.ref, this.occurrences, this.selectionSource); | 532 _OccurrencesVisitor(this.ref, this.occurrences, this.selectionSource); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 572 |
| 573 void _addOccurrence(SourceRange range) { | 573 void _addOccurrence(SourceRange range) { |
| 574 if (range.intersects(ref.selectionRange)) { | 574 if (range.intersects(ref.selectionRange)) { |
| 575 occurrences.add(ref.selectionRange); | 575 occurrences.add(ref.selectionRange); |
| 576 } else { | 576 } else { |
| 577 occurrences.add(range); | 577 occurrences.add(range); |
| 578 } | 578 } |
| 579 } | 579 } |
| 580 | 580 |
| 581 bool _hasStatements(AstNode root) { | 581 bool _hasStatements(AstNode root) { |
| 582 List<bool> result = [false]; | 582 _HasStatementVisitor visitor = new _HasStatementVisitor(); |
| 583 root.accept(new _HasStatementVisitor(result)); | 583 root.accept(visitor); |
| 584 return result[0]; | 584 return visitor.result; |
| 585 } | 585 } |
| 586 | 586 |
| 587 void _tryToFindOccurrence(Expression node) { | 587 void _tryToFindOccurrence(Expression node) { |
| 588 String nodeSource = ref.utils.getNodeText(node); | 588 String nodeSource = ref.utils.getNodeText(node); |
| 589 List<Token> nodeTokens = TokenUtils.getTokens(nodeSource); | 589 List<Token> nodeTokens = TokenUtils.getTokens(nodeSource); |
| 590 nodeSource = ref._encodeExpressionTokens(node, nodeTokens); | 590 nodeSource = ref._encodeExpressionTokens(node, nodeTokens); |
| 591 if (nodeSource == selectionSource) { | 591 if (nodeSource == selectionSource) { |
| 592 SourceRange occuRange = rangeNode(node); | 592 SourceRange occuRange = rangeNode(node); |
| 593 _addOccurrence(occuRange); | 593 _addOccurrence(occuRange); |
| 594 } | 594 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 630 |
| 631 _TokenLocalElementVisitor(this.map); | 631 _TokenLocalElementVisitor(this.map); |
| 632 | 632 |
| 633 visitSimpleIdentifier(SimpleIdentifier node) { | 633 visitSimpleIdentifier(SimpleIdentifier node) { |
| 634 Element element = node.staticElement; | 634 Element element = node.staticElement; |
| 635 if (element is LocalVariableElement) { | 635 if (element is LocalVariableElement) { |
| 636 map[node.token] = element; | 636 map[node.token] = element; |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 } | 639 } |
| OLD | NEW |