Skip to content

Commit

Permalink
Elements. Migrate lib/utilities/range_factory.dart
Browse files Browse the repository at this point in the history
Change-Id: I218603ef0f3a9eae8bde3889cb22fa7f59000e38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403623
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Jan 8, 2025
1 parent 8121b02 commit 8785c4e
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ class RenameProcessor {
this.newName,
);

/// Add the edit that updates the [element] declaration.
void addDeclarationEdit(Element? element) {
if (element != null && workspace.containsElement(element)) {
var edit = newSourceEdit_range(range.elementName(element), newName);
doSourceChange_addElementEdit(change, element, edit);
}
}

/// Add the edit that updates the [element] declaration.
void addDeclarationEdit2(Element2? element) {
if (element == null) {
Expand Down Expand Up @@ -72,14 +64,6 @@ class RenameProcessor {
}
}

/// Update the [element] declaration and reference to it.
Future<void> renameElement(Element element) {
addDeclarationEdit(element);
return workspace.searchEngine
.searchReferences(element.asElement2!)
.then(addReferenceEdits);
}

/// Update the [element] declaration and references to it.
Future<void> renameElement2(Element2 element) async {
addDeclarationEdit2(element);
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer_plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.13.0-dev
- Remove `elementName()` from `RangeFactory`. Use `fragmentName()` instead.

## 0.12.0
- Breaking changes to `DartFileEditBuilder`: `convertFunctionFromSyncToAsync`
and `replaceTypeWithFuture`.
Expand Down
2 changes: 0 additions & 2 deletions pkg/analyzer_plugin/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ lib/utilities/change_builder/change_builder_dart.dart
lib/utilities/completion/inherited_reference_contributor.dart
lib/utilities/completion/suggestion_builder.dart
lib/utilities/completion/type_member_contributor.dart
lib/utilities/range_factory.dart
test/src/utilities/change_builder/change_builder_dart_test.dart
test/src/utilities/completion/completion_target_test.dart
test/src/utilities/visitors/local_declaration_visitor_test.dart
test/utilities/analyzer_converter_test.dart
test/utilities/range_factory_test.dart
6 changes: 0 additions & 6 deletions pkg/analyzer_plugin/lib/utilities/range_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/syntactic_entity.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/source_range.dart';
Expand Down Expand Up @@ -96,11 +95,6 @@ class RangeFactory {
return startOffsetEndOffset(startOffset, endOffset);
}

/// Return a source range that covers the name of the given [element].
SourceRange elementName(Element element) {
return SourceRange(element.nameOffset, element.nameLength);
}

/// Return a source range that starts at the end of [leftEntity] and ends at
/// the end of [rightEntity].
SourceRange endEnd(SyntacticEntity leftEntity, SyntacticEntity rightEntity) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: analyzer_plugin
description: A framework and support code for building plugins for the analysis server.
version: 0.12.0
version: 0.13.0-dev
repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer_plugin

environment:
Expand Down
6 changes: 0 additions & 6 deletions pkg/analyzer_plugin/test/utilities/range_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,6 @@ class B {}
''');
}

Future<void> test_elementName() async {
await resolveTestCode('class ABC {}');
var element = findElement.class_('ABC');
expect(range.elementName(element), SourceRange(6, 3));
}

Future<void> test_endEnd() async {
await resolveTestCode('main() {}');
var mainFunction = testUnit.declarations[0] as FunctionDeclaration;
Expand Down

0 comments on commit 8785c4e

Please sign in to comment.