Skip to content

Commit

Permalink
[Migrate] ast.dart (extentions)
Browse files Browse the repository at this point in the history
Change-Id: Ia824f614e450c56b98fd5f38f1dec17cb421a3f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402905
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
  • Loading branch information
bwilkerson authored and Commit Queue committed Jan 4, 2025
1 parent 076b05f commit 2ad4452
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
1 change: 0 additions & 1 deletion pkg/analyzer/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 5 additions & 21 deletions pkg/analyzer/lib/src/utilities/extensions/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) {
Expand Down Expand Up @@ -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/',
Expand Down

0 comments on commit 2ad4452

Please sign in to comment.