Skip to content

Commit

Permalink
Elements. Migrate test/support/abstract_context.dart
Browse files Browse the repository at this point in the history
Change-Id: I75004a7f979315b838d2699a0dcdd8df13b2864d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403702
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Jan 8, 2025
1 parent f3e68f2 commit 8121b02
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 50 deletions.
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 @@ -15,7 +15,5 @@ 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/support/abstract_context.dart
test/support/abstract_single_unit.dart
test/utilities/analyzer_converter_test.dart
test/utilities/range_factory_test.dart
34 changes: 0 additions & 34 deletions pkg/analyzer_plugin/test/support/abstract_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/visitor.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
Expand All @@ -20,24 +18,6 @@ import 'package:analyzer_utilities/test/mock_packages/mock_packages.dart';
import 'package:linter/src/rules.dart';
import 'package:meta/meta.dart';

/// Finds an [Element] with the given [name].
Element? findChildElement(Element root, String name, [ElementKind? kind]) {
Element? result;
root.accept(_ElementVisitorFunctionWrapper((Element element) {
if (element.name != name) {
return;
}
if (kind != null && element.kind != kind) {
return;
}
result = element;
}));
return result;
}

/// A function to be called for every [Element].
typedef _ElementVisitorFunction = void Function(Element element);

class AbstractContextTest with MockPackagesMixin, ResourceProviderMixin {
final ByteStore _byteStore = MemoryByteStore();

Expand Down Expand Up @@ -200,17 +180,3 @@ class AbstractContextTest with MockPackagesMixin, ResourceProviderMixin {
);
}
}

/// Wraps the given [_ElementVisitorFunction] into an instance of
/// [engine.GeneralizingElementVisitor].
class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor {
final _ElementVisitorFunction function;

_ElementVisitorFunctionWrapper(this.function);

@override
void visitElement(Element element) {
function(element);
super.visitElement(element);
}
}
17 changes: 3 additions & 14 deletions pkg/analyzer_plugin/test/support/abstract_single_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/ast/element_locator.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/test_utilities/find_element.dart';
import 'package:analyzer/src/test_utilities/find_element2.dart';
import 'package:analyzer/src/test_utilities/find_node.dart';
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:test/test.dart';

import 'abstract_context.dart';
Expand Down Expand Up @@ -62,25 +61,15 @@ class AbstractSingleUnitTest extends AbstractContextTest {
return findNodeAtOffset(offset, predicate);
}

Element? findNodeElementAtString(
Element2? findNodeElementAtString(
String search, [
bool Function(AstNode)? predicate,
]) {
var node = findNodeAtString(search, predicate);
if (node == null) {
return null;
}

switch (node) {
case ExportDirective():
return node.element;
case ImportDirective():
return node.element;
case PartOfDirective():
return node.element;
default:
return ElementLocator.locate2(node).asElement;
}
return ElementLocator.locate2(node);
}

int findOffset(String search) {
Expand Down

0 comments on commit 8121b02

Please sign in to comment.