From 2ad44521dc99c2dfa924c3a7867e8baad6e78359 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Sat, 4 Jan 2025 07:24:29 -0800 Subject: [PATCH] [Migrate] ast.dart (extentions) Change-Id: Ia824f614e450c56b98fd5f38f1dec17cb421a3f3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402905 Reviewed-by: Konstantin Shcheglov Commit-Queue: Brian Wilkerson --- pkg/analyzer/analyzer_use_new_elements.txt | 1 - .../lib/src/utilities/extensions/ast.dart | 26 ++++--------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/pkg/analyzer/analyzer_use_new_elements.txt b/pkg/analyzer/analyzer_use_new_elements.txt index ccf5f25aaa33..364fc916d6b3 100644 --- a/pkg/analyzer/analyzer_use_new_elements.txt +++ b/pkg/analyzer/analyzer_use_new_elements.txt @@ -143,7 +143,6 @@ lib/src/summary2/variance_builder.dart lib/src/test_utilities/find_element.dart lib/src/test_utilities/find_node.dart lib/src/test_utilities/mock_sdk_elements.dart -lib/src/utilities/extensions/ast.dart lib/src/utilities/extensions/element.dart lib/src/utilities/extensions/flutter.dart lib/src/utilities/extensions/library_element.dart diff --git a/pkg/analyzer/lib/src/utilities/extensions/ast.dart b/pkg/analyzer/lib/src/utilities/extensions/ast.dart index ebb8eece9daf..f8fd39fce832 100644 --- a/pkg/analyzer/lib/src/utilities/extensions/ast.dart +++ b/pkg/analyzer/lib/src/utilities/extensions/ast.dart @@ -4,7 +4,6 @@ import 'package:analyzer/dart/ast/ast.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/src/dart/element/element.dart'; @@ -27,22 +26,6 @@ extension AstNodeExtension on AstNode { return result; } - /// The [ExecutableElement] of the enclosing executable [AstNode]. - ExecutableElement? get enclosingExecutableElement { - for (var node in withParents) { - if (node is FunctionDeclaration) { - return node.declaredElement; - } - if (node is ConstructorDeclaration) { - return node.declaredElement; - } - if (node is MethodDeclaration) { - return node.declaredElement; - } - } - return null; - } - /// The [ExecutableElement2] of the enclosing executable [AstNode]. ExecutableElement2? get enclosingExecutableElement2 { for (var node in withParents) { @@ -176,10 +159,11 @@ extension AstNodeNullableExtension on AstNode? { extension CompilationUnitExtension on CompilationUnit { /// Whether this [CompilationUnit] is found in a "test" directory. bool get inTestDir { - var declaredElement = this.declaredElement; - if (declaredElement == null) return false; - var pathContext = declaredElement.session.resourceProvider.pathContext; - var path = declaredElement.source.fullName; + var declaredFragment = this.declaredFragment; + if (declaredFragment == null) return false; + var pathContext = + declaredFragment.element.session.resourceProvider.pathContext; + var path = declaredFragment.source.fullName; return switch (pathContext.separator) { '/' => const [ '/test/',