Skip to content

Commit 867391e

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate prefer_const_constructors
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I1298112a1b565724b651fe107e4f573fe2f795e4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389404 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent d27e144 commit 867391e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
lib/src/analyzer.dart
2+
lib/src/lint_codes.dart
3+
lib/src/lint_codes.g.dart
24
lib/src/lint_names.dart
3-
lib/src/linter_lint_codes.dart
5+
lib/src/lint_names.g.dart
46
lib/src/rules.dart
57
lib/src/rules/always_declare_return_types.dart
68
lib/src/rules/always_put_control_body_on_new_line.dart
@@ -98,6 +100,7 @@ lib/src/rules/prefer_asserts_with_message.dart
98100
lib/src/rules/prefer_bool_in_asserts.dart
99101
lib/src/rules/prefer_collection_literals.dart
100102
lib/src/rules/prefer_conditional_assignment.dart
103+
lib/src/rules/prefer_const_constructors.dart
101104
lib/src/rules/prefer_const_declarations.dart
102105
lib/src/rules/prefer_const_literals_to_create_immutables.dart
103106
lib/src/rules/prefer_contains.dart
@@ -153,6 +156,7 @@ lib/src/rules/unnecessary_library_name.dart
153156
lib/src/rules/unnecessary_new.dart
154157
lib/src/rules/unnecessary_null_aware_assignments.dart
155158
lib/src/rules/unnecessary_null_in_if_null_operators.dart
159+
lib/src/rules/unnecessary_nullable_for_final_variable_declarations.dart
156160
lib/src/rules/unnecessary_parenthesis.dart
157161
lib/src/rules/unnecessary_raw_strings.dart
158162
lib/src/rules/unnecessary_statements.dart
@@ -431,7 +435,7 @@ test/validate_incompatible_rules_test.dart
431435
test/validate_no_rule_description_references_test.dart
432436
test/validate_rule_description_format_test.dart
433437
test/verify_checks_test.dart
434-
test/verify_generated_codes_test.dart
438+
test/verify_generated_files_test.dart
435439
test/verify_reflective_test_suites_test.dart
436440
test_data/rules/no_default_cases.dart
437441
test_data/rules/overridden_fields.dart
@@ -447,14 +451,14 @@ test_data/rules/unmocked/unsafe_html.dart
447451
test_data/rules/unnecessary_lambdas.dart
448452
test_data/rules/unnecessary_parenthesis.dart
449453
test_data/rules/void_checks.dart
454+
tool/benchmark.dart
450455
tool/changelog.dart
451456
tool/checks/check_all_yaml.dart
452457
tool/checks/check_messages_yaml.dart
453458
tool/checks/driver.dart
454459
tool/checks/rules/no_solo_tests.dart
455460
tool/checks/rules/no_trailing_spaces.dart
456-
tool/cli.dart
457-
tool/codes/generate.dart
461+
tool/generate_lints.dart
458462
tool/labeler/issue_config.dart
459463
tool/labeler/pr_config.dart
460464
tool/legacy_test_move.dart

pkg/linter/lib/src/rules/prefer_const_constructors.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7-
import 'package:analyzer/dart/element/element.dart';
7+
import 'package:analyzer/dart/element/element2.dart';
88
import 'package:analyzer/dart/element/type.dart';
99
import 'package:analyzer/src/lint/linter.dart'; // ignore: implementation_imports
1010

@@ -41,24 +41,25 @@ class _Visitor extends SimpleAstVisitor<void> {
4141
if (node.isConst) return;
4242
if (node.constructorName.type.isDeferred) return;
4343

44-
var element = node.constructorName.staticElement;
44+
var element = node.constructorName.element;
4545
if (element == null) return;
4646
if (!element.isConst) return;
4747

4848
// Handled by an analyzer warning.
4949
if (element.hasLiteral) return;
5050

51-
var enclosingElement = element.enclosingElement3;
52-
if (enclosingElement is ClassElement && enclosingElement.isDartCoreObject) {
51+
var enclosingElement = element.enclosingElement2;
52+
if (enclosingElement is ClassElement2 &&
53+
enclosingElement.isDartCoreObject) {
5354
// Skip lint for `new Object()`, because it can be used for ID creation.
5455
return;
5556
}
5657

57-
if (enclosingElement.typeParameters.isNotEmpty &&
58+
if (enclosingElement.typeParameters2.isNotEmpty &&
5859
node.constructorName.type.typeArguments == null) {
5960
var approximateContextType = node.approximateContextType;
6061
var contextTypeAsInstanceOfEnclosing =
61-
approximateContextType?.asInstanceOf(enclosingElement);
62+
approximateContextType?.asInstanceOf2(enclosingElement);
6263
if (contextTypeAsInstanceOfEnclosing != null) {
6364
if (contextTypeAsInstanceOfEnclosing.typeArguments
6465
.any((e) => e is TypeParameterType)) {

0 commit comments

Comments
 (0)