Skip to content

Commit

Permalink
[element model] migrate scope_util_test
Browse files Browse the repository at this point in the history
Bug: https://github.com/dart-lang/linter/issues/5099
Change-Id: I3a1a0229b59a7b9f83011d0acd6fd6d56415c5ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394840
Auto-Submit: Phil Quitslund <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
pq authored and Commit Queue committed Nov 13, 2024
1 parent e3987ed commit 7784976
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
2 changes: 0 additions & 2 deletions pkg/linter/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ lib/src/rules/use_build_context_synchronously.dart
lib/src/rules/use_late_for_private_fields_and_variables.dart
lib/src/util/dart_type_utilities.dart
lib/src/util/flutter_utils.dart
lib/src/util/leak_detector_visitor.dart
lib/src/util/scope.dart
test/rules/use_build_context_synchronously_test.dart
test/scope_util_test.dart
42 changes: 20 additions & 22 deletions pkg/linter/test/scope_util_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/test_utilities/find_element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/src/test_utilities/find_element2.dart';
import 'package:analyzer/src/test_utilities/find_node.dart';
import 'package:linter/src/util/scope.dart';
Expand All @@ -25,18 +24,15 @@ main() {

@reflectiveTest
class ResolveNameInScopeTest extends PubPackageResolutionTest {
late FindElement findElement;

late FindElement2 findElement2;
late FindElement2 findElement;

late FindNode findNode;

@override
Future<ResolvedUnitResult> resolveFile(String path) async {
var result = await super.resolveFile(path);

findElement = FindElement(result.unit);
findElement2 = FindElement2(result.unit);
findElement = FindElement2(result.unit);
findNode = FindNode(result.content, result.unit);
return result;
}
Expand All @@ -55,7 +51,7 @@ class B extends A {
}
}
''');
_checkGetterDifferent(findElement.setter('foo'));
_checkGetterDifferent(findElement.setter('foo='));
}

test_class_getter_different_importScope() async {
Expand Down Expand Up @@ -628,7 +624,7 @@ class A {
}
}
''');
_checkSetterRequested(findElement.setter('foo'));
_checkSetterRequested(findElement.setter('foo='));
}

test_class_setter_requested_thisClass_topLevelFunction() async {
Expand All @@ -643,7 +639,7 @@ class A {
void foo() {}
''');
_checkSetterRequested(findElement.setter('foo'));
_checkSetterRequested(findElement.setter('foo='));
}

test_class_typeParameter_inConstructor() async {
Expand Down Expand Up @@ -779,8 +775,8 @@ void foo<T>(int T) {}
void foo(void Function<T>(String T) b) {}
''');
var node = findNode.simpleFormalParameter('T)');
var T = findNode.typeParameter('T>').declaredElement!;
_resultRequested(node, 'T', false, T);
var T = findNode.typeParameter('T>').declaredFragment?.element;
_resultRequested(node, 'T', false, T!);
}

test_genericTypeAlias_typeParameter() async {
Expand Down Expand Up @@ -837,7 +833,7 @@ mixin A<T> {
_resultRequested(node, 'T', false, findElement.typeParameter('T'));
}

void _checkGetterDifferent(Element expected) {
void _checkGetterDifferent(Element2 expected) {
var node = findNode.this_('this.foo;');
_resultDifferent(node, 'foo', false, expected);
}
Expand All @@ -847,12 +843,12 @@ mixin A<T> {
_resultNone(node, 'foo', false);
}

void _checkGetterRequested(Element expected) {
void _checkGetterRequested(Element2 expected) {
var node = findNode.this_('this.foo;');
_resultRequested(node, 'foo', false, expected);
}

void _checkMethodDifferent(Element expected) {
void _checkMethodDifferent(Element2 expected) {
var node = findNode.this_('this.foo()');
_resultDifferent(node, 'foo', false, expected);
}
Expand All @@ -862,7 +858,7 @@ mixin A<T> {
_resultNone(node, 'foo', false);
}

void _checkMethodRequested(Element expected) {
void _checkMethodRequested(Element2 expected) {
var node = findNode.this_('this.foo()');
_resultRequested(node, 'foo', false, expected);
}
Expand All @@ -871,7 +867,7 @@ mixin A<T> {
_checkMethodRequested(findElement.localVar('foo'));
}

void _checkSetterDifferent(Element expected) {
void _checkSetterDifferent(Element2 expected) {
var node = findNode.this_('this.foo = 0;');
_resultDifferent(node, 'foo', true, expected);
}
Expand All @@ -881,14 +877,15 @@ mixin A<T> {
_resultNone(node, 'foo', true);
}

void _checkSetterRequested(Element expected) {
void _checkSetterRequested(Element2 expected) {
var node = findNode.this_('this.foo = 0;');
_resultRequested(node, 'foo', true, expected);
}

void _resultDifferent(AstNode node, String id, bool setter, Element element) {
void _resultDifferent(
AstNode node, String id, bool setter, Element2 element) {
var result = resolveNameInScope(id, node, shouldResolveSetter: setter);
if (!result.isDifferentName || result.element != element) {
if (!result.isDifferentName || result.element2 != element) {
fail('Expected different $element, actual: $result');
}
}
Expand All @@ -900,9 +897,10 @@ mixin A<T> {
}
}

void _resultRequested(AstNode node, String id, bool setter, Element element) {
void _resultRequested(
AstNode node, String id, bool setter, Element2 element) {
var result = resolveNameInScope(id, node, shouldResolveSetter: setter);
if (!result.isRequestedName || result.element != element) {
if (!result.isRequestedName || result.element2 != element) {
fail('Expected requested $element, actual: $result');
}
}
Expand Down

0 comments on commit 7784976

Please sign in to comment.