Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ce29699

Browse files
author
Dart CI
committed
Version 2.16.0-131.0.dev
Merge commit '7b7079f519beae71b20098f6ad01e90a21edf99d' into 'dev'
2 parents 35f00ea + 7b7079f commit ce29699

20 files changed

+285
-38
lines changed

pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_descriptor.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ import 'package:analyzer/dart/ast/ast.dart';
77
import 'package:analyzer/dart/element/element.dart' show ClassElement;
88
import 'package:analyzer/dart/element/type.dart';
99

10-
/// The path to an element.
10+
/// A description of an element.
1111
class ElementDescriptor {
1212
/// The URIs of the library in which the element is defined.
1313
final List<Uri> libraryUris;
1414

1515
/// The kind of element that was changed.
1616
final ElementKind kind;
1717

18+
/// A flag indicating whether the element is a static member of a container
19+
/// such as a class, enum, mixin, or extension.
20+
///
21+
/// The flag should be `false` for top-level declarations. The implication is
22+
/// that the flag will only be true if the list of [components] has more than
23+
/// one element.
24+
final bool isStatic;
25+
1826
/// The components that uniquely identify the element within its library. The
1927
/// components are ordered from the most local to the most global.
2028
final List<String> components;
@@ -26,6 +34,7 @@ class ElementDescriptor {
2634
ElementDescriptor(
2735
{required this.libraryUris,
2836
required this.kind,
37+
required this.isStatic,
2938
required this.components});
3039

3140
/// Return `true` if the described element is a constructor.

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ class TransformSetErrorCode extends ErrorCode {
153153
static const TransformSetErrorCode unsupportedKey = TransformSetErrorCode(
154154
'unsupported_key', "The key '{0}' isn't supported.");
155155

156+
/**
157+
* No parameters.
158+
*/
159+
static const TransformSetErrorCode unsupportedStatic = TransformSetErrorCode(
160+
'unsupported_static',
161+
"The key 'static' is only supported for elements in a class, enum, "
162+
"extension, or mixin.");
163+
156164
/**
157165
* No parameters.
158166
*/

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_parser.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class TransformSetParser {
7171
static const String _oneOfKey = 'oneOf';
7272
static const String _requiredIfKey = 'requiredIf';
7373
static const String _setterKey = 'setter';
74+
static const String _staticKey = 'static';
7475
static const String _styleKey = 'style';
7576
static const String _titleKey = 'title';
7677
static const String _transformsKey = 'transforms';
@@ -662,6 +663,8 @@ class TransformSetParser {
662663
return null;
663664
}
664665
var components = [elementName];
666+
var isStatic = false;
667+
var staticNode = node.valueAt(_staticKey);
665668
if (_containerKeyMap.containsKey(elementKey)) {
666669
var validContainerKeys = _containerKeyMap[elementKey]!;
667670
var containerKey =
@@ -684,6 +687,20 @@ class TransformSetParser {
684687
} else {
685688
components.add(containerName);
686689
}
690+
if (staticNode != null) {
691+
var staticValue = _translateBool(
692+
staticNode, ErrorContext(key: _staticKey, parentNode: node));
693+
if (staticValue != null) {
694+
if (components.length == 1) {
695+
_reportError(TransformSetErrorCode.unsupportedStatic,
696+
node.getKey(_staticKey)!);
697+
}
698+
isStatic = staticValue;
699+
}
700+
}
701+
} else if (staticNode != null) {
702+
_reportError(
703+
TransformSetErrorCode.unsupportedStatic, node.getKey(_staticKey)!);
687704
}
688705
if (uris == null) {
689706
// The error has already been reported.
@@ -698,6 +715,7 @@ class TransformSetParser {
698715
return ElementDescriptor(
699716
libraryUris: uris,
700717
kind: ElementKindUtilities.fromName(elementKey)!,
718+
isStatic: isStatic,
701719
components: components);
702720
} else if (node == null) {
703721
return _reportMissingKey(context);

pkg/analysis_server/test/src/services/correction/fix/data_driven/add_type_parameter_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,17 @@ abstract class _AddTypeParameterChange extends DataDrivenFixProcessorTest {
477477
/// Return the kind of element whose parameters are being modified.
478478
String get _kind;
479479

480-
Transform _add(int index, {List<String>? components, String? extendedType}) =>
480+
Transform _add(int index,
481+
{List<String>? components,
482+
String? extendedType,
483+
bool isStatic = false}) =>
481484
Transform(
482485
title: 'title',
483486
date: DateTime.now(),
484487
element: ElementDescriptor(
485488
libraryUris: [Uri.parse(importUri)],
486489
kind: ElementKindUtilities.fromName(_kind)!,
490+
isStatic: isStatic,
487491
components: components ?? ['m', 'C']),
488492
bulkApply: false,
489493
changesSelector: UnconditionalChangesSelector([

pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'undefined_variable_test.dart' as undefined_variable;
2323
import 'unexpected_token_test.dart' as unexpected_token;
2424
import 'unknown_accessor_test.dart' as unknown_accessor;
2525
import 'unsupported_key_test.dart' as unsupported_key;
26+
import 'unsupported_static_test.dart' as unsupported_static;
2627
import 'unsupported_uri_change_test.dart' as unsupported_uri_change;
2728
import 'unsupported_version_test.dart' as unsupported_version;
2829
import 'wrong_token_test.dart' as wrong_token;
@@ -49,6 +50,7 @@ void main() {
4950
unexpected_token.main();
5051
unknown_accessor.main();
5152
unsupported_key.main();
53+
unsupported_static.main();
5254
unsupported_uri_change.main();
5355
unsupported_version.main();
5456
wrong_token.main();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../transform_set_parser_test_support.dart';
9+
10+
void main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(UnsupportedStaticTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class UnsupportedStaticTest extends AbstractTransformSetParserTest {
18+
void test_class() {
19+
assertErrors('''
20+
version: 1
21+
transforms:
22+
- title: ''
23+
date: 2021-11-22
24+
element:
25+
uris: ['test.dart']
26+
class: 'C'
27+
static: true
28+
changes: []
29+
''', [
30+
error(TransformSetErrorCode.unsupportedStatic, 108, 6),
31+
]);
32+
}
33+
34+
void test_getter_inClass() {
35+
assertNoErrors('''
36+
version: 1
37+
transforms:
38+
- title: ''
39+
date: 2021-11-22
40+
element:
41+
uris: ['test.dart']
42+
getter: 'm'
43+
inClass: 'C'
44+
static: true
45+
changes: []
46+
''');
47+
}
48+
49+
void test_getter_topLevel() {
50+
assertErrors('''
51+
version: 1
52+
transforms:
53+
- title: ''
54+
date: 2021-11-22
55+
element:
56+
uris: ['test.dart']
57+
getter: 'g'
58+
static: true
59+
changes: []
60+
''', [
61+
error(TransformSetErrorCode.unsupportedStatic, 109, 6),
62+
]);
63+
}
64+
}

pkg/analysis_server/test/src/services/correction/fix/data_driven/modify_parameters_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,15 @@ abstract class _ModifyParameters extends DataDrivenFixProcessorTest {
10061006
String get _kind;
10071007

10081008
Transform _modify(List<String> originalComponents,
1009-
List<ParameterModification> modifications, {String? newName}) =>
1009+
List<ParameterModification> modifications,
1010+
{String? newName, bool isStatic = false}) =>
10101011
Transform(
10111012
title: 'title',
10121013
date: DateTime.now(),
10131014
element: ElementDescriptor(
10141015
libraryUris: [Uri.parse(importUri)],
10151016
kind: ElementKindUtilities.fromName(_kind)!,
1017+
isStatic: isStatic,
10161018
components: originalComponents),
10171019
bulkApply: false,
10181020
changesSelector: UnconditionalChangesSelector([

pkg/analysis_server/test/src/services/correction/fix/data_driven/rename_parameter_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,15 @@ abstract class _AbstractRenameParameterInTest
328328
/// Return the kind of element containing the parameter being renamed.
329329
String get _kind;
330330

331-
Transform _rename(List<String> components, String oldName, String newName) =>
331+
Transform _rename(List<String> components, String oldName, String newName,
332+
{bool isStatic = false}) =>
332333
Transform(
333334
title: 'title',
334335
date: DateTime.now(),
335336
element: ElementDescriptor(
336337
libraryUris: [Uri.parse(importUri)],
337338
kind: ElementKindUtilities.fromName(_kind)!,
339+
isStatic: isStatic,
338340
components: components),
339341
bulkApply: false,
340342
changesSelector: UnconditionalChangesSelector([

pkg/analysis_server/test/src/services/correction/fix/data_driven/rename_test.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,15 +1533,18 @@ abstract class _AbstractRenameTest extends DataDrivenFixProcessorTest {
15331533
/// Return the kind of element being renamed.
15341534
String get _kind;
15351535

1536-
Transform _rename(List<String> components, String newName) => Transform(
1537-
title: 'title',
1538-
date: DateTime.now(),
1539-
element: ElementDescriptor(
1540-
libraryUris: [Uri.parse(importUri)],
1541-
kind: ElementKindUtilities.fromName(_kind)!,
1542-
components: components),
1543-
bulkApply: false,
1544-
changesSelector: UnconditionalChangesSelector([
1545-
Rename(newName: newName),
1546-
]));
1536+
Transform _rename(List<String> components, String newName,
1537+
{bool isStatic = false}) =>
1538+
Transform(
1539+
title: 'title',
1540+
date: DateTime.now(),
1541+
element: ElementDescriptor(
1542+
libraryUris: [Uri.parse(importUri)],
1543+
kind: ElementKindUtilities.fromName(_kind)!,
1544+
isStatic: isStatic,
1545+
components: components),
1546+
bulkApply: false,
1547+
changesSelector: UnconditionalChangesSelector([
1548+
Rename(newName: newName),
1549+
]));
15471550
}

pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,12 +838,19 @@ var x = $prefixReference${newElement.reference}$invocation;
838838
}
839839

840840
Transform _replacedBy(ElementKind oldKind, List<String> oldComponents,
841-
ElementKind newKind, List<String> newComponents) {
841+
ElementKind newKind, List<String> newComponents,
842+
{bool isStatic = false}) {
842843
var uris = [Uri.parse(importUri)];
843844
var oldElement = ElementDescriptor(
844-
libraryUris: uris, kind: oldKind, components: oldComponents);
845+
libraryUris: uris,
846+
kind: oldKind,
847+
isStatic: isStatic,
848+
components: oldComponents);
845849
var newElement2 = ElementDescriptor(
846-
libraryUris: uris, kind: newKind, components: newComponents);
850+
libraryUris: uris,
851+
kind: newKind,
852+
isStatic: isStatic,
853+
components: newComponents);
847854
return Transform(
848855
title: 'title',
849856
date: DateTime.now(),

0 commit comments

Comments
 (0)