Skip to content

Commit 00a3cdf

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Remove FragmentDeclaration, add 'declaredFragment' to Declaration.
Change-Id: I33398358d1241114b04995767d63188bb314fd6a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394565 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 82afcb4 commit 00a3cdf

File tree

7 files changed

+41
-52
lines changed

7 files changed

+41
-52
lines changed

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_augmentation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:analysis_server/src/lsp/constants.dart';
77
import 'package:analysis_server/src/lsp/error_or.dart';
88
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
99
import 'package:analysis_server/src/lsp/mapping.dart';
10-
import 'package:analyzer/src/dart/ast/ast.dart';
10+
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
1111
import 'package:analyzer/src/utilities/extensions/ast.dart';
1212

1313
class AugmentationHandler
@@ -44,7 +44,7 @@ class AugmentationHandler
4444
var node =
4545
unit.unit
4646
.nodeCovering(offset: offset)
47-
?.thisOrAncestorOfType<FragmentDeclaration>();
47+
?.thisOrAncestorOfType<ast.Declaration>();
4848

4949
var location = fragmentToLocation(
5050
uriConverter,

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_augmented.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:analysis_server/src/lsp/constants.dart';
77
import 'package:analysis_server/src/lsp/error_or.dart';
88
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
99
import 'package:analysis_server/src/lsp/mapping.dart';
10-
import 'package:analyzer/src/dart/ast/ast.dart';
10+
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
1111
import 'package:analyzer/src/utilities/extensions/ast.dart';
1212

1313
class AugmentedHandler
@@ -44,7 +44,7 @@ class AugmentedHandler
4444
var node =
4545
unit.unit
4646
.nodeCovering(offset: offset)
47-
?.thisOrAncestorOfType<FragmentDeclaration>();
47+
?.thisOrAncestorOfType<ast.Declaration>();
4848

4949
var location = fragmentToLocation(
5050
uriConverter,

pkg/analysis_server/lib/src/services/correction/dart/remove_unused.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RemoveUnusedElement extends _RemoveUnused {
3838
}
3939

4040
Element2? element;
41-
if (node is FragmentDeclaration) {
41+
if (node is Declaration) {
4242
element = node.declaredFragment?.element;
4343
}
4444
if (element == null) {

pkg/analysis_server/lib/src/services/correction/dart/rename_method_parameter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class RenameMethodParameter extends ResolvedCorrectionProducer {
4545
if (methodParameters == null) return;
4646

4747
Fragment? declaredFragment;
48-
if (method.parent case FragmentDeclaration declaration) {
48+
if (method.parent case Declaration declaration) {
4949
declaredFragment = declaration.declaredFragment;
5050
}
5151

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,8 +2684,7 @@ class ChildEntity {
26842684
/// classModifiers ::= 'sealed'
26852685
/// | 'abstract'? ('base' | 'interface' | 'final')?
26862686
/// | 'abstract'? 'base'? 'mixin'
2687-
abstract final class ClassDeclaration
2688-
implements NamedCompilationUnitMember, FragmentDeclaration {
2687+
abstract final class ClassDeclaration implements NamedCompilationUnitMember {
26892688
/// The `abstract` keyword, or `null` if the keyword was absent.
26902689
Token? get abstractKeyword;
26912690

@@ -2921,7 +2920,7 @@ sealed class ClassMemberImpl extends DeclarationImpl implements ClassMember {
29212920
///
29222921
/// mixinApplication ::=
29232922
/// [NamedType] [WithClause] [ImplementsClause]? ';'
2924-
abstract final class ClassTypeAlias implements TypeAlias, FragmentDeclaration {
2923+
abstract final class ClassTypeAlias implements TypeAlias {
29252924
/// The token for the `abstract` keyword, or `null` if this isn't defining an
29262925
/// abstract class.
29272926
Token? get abstractKeyword;
@@ -4062,8 +4061,7 @@ final class ConstantPatternImpl extends DartPatternImpl
40624061
///
40634062
/// initializerList ::=
40644063
/// ':' [ConstructorInitializer] (',' [ConstructorInitializer])*
4065-
abstract final class ConstructorDeclaration
4066-
implements ClassMember, FragmentDeclaration {
4064+
abstract final class ConstructorDeclaration implements ClassMember {
40674065
/// The `augment` keyword, or `null` if the keyword was absent.
40684066
Token? get augmentKeyword;
40694067

@@ -4797,6 +4795,12 @@ abstract final class Declaration implements AnnotatedNode {
47974795
/// node corresponds to a list of declarations or if the AST structure hasn't
47984796
/// been resolved.
47994797
Element? get declaredElement;
4798+
4799+
/// The fragment declared by this declaration.
4800+
///
4801+
/// Returns `null` if the AST structure hasn't been resolved.
4802+
@experimental
4803+
Fragment? get declaredFragment;
48004804
}
48014805

48024806
sealed class DeclarationImpl extends AnnotatedNodeImpl implements Declaration {
@@ -4859,6 +4863,9 @@ final class DeclaredIdentifierImpl extends DeclarationImpl
48594863
@override
48604864
LocalVariableElementImpl? declaredElement;
48614865

4866+
@override
4867+
LocalVariableElementImpl? declaredFragment;
4868+
48624869
/// Initializes a newly created formal parameter.
48634870
///
48644871
/// Either or both of the [comment] and [metadata] can be `null` if the
@@ -5539,7 +5546,7 @@ final class EnumConstantArgumentsImpl extends AstNodeImpl
55395546
}
55405547

55415548
/// The declaration of an enum constant.
5542-
abstract final class EnumConstantDeclaration implements FragmentDeclaration {
5549+
abstract final class EnumConstantDeclaration implements Declaration {
55435550
/// The explicit arguments (there are always implicit `index` and `name`
55445551
/// leading arguments) to the invoked constructor, or `null` if this constant
55455552
/// doesn't provide any explicit arguments.
@@ -5641,8 +5648,7 @@ final class EnumConstantDeclarationImpl extends DeclarationImpl
56415648
/// metadata 'enum' name [TypeParameterList]?
56425649
/// [WithClause]? [ImplementsClause]? '{' [SimpleIdentifier]
56435650
/// (',' [SimpleIdentifier])* (';' [ClassMember]+)? '}'
5644-
abstract final class EnumDeclaration
5645-
implements NamedCompilationUnitMember, FragmentDeclaration {
5651+
abstract final class EnumDeclaration implements NamedCompilationUnitMember {
56465652
/// The `augment` keyword, or `null` if the keyword was absent.
56475653
@experimental
56485654
Token? get augmentKeyword;
@@ -6364,8 +6370,7 @@ final class ExtendsClauseImpl extends AstNodeImpl implements ExtendsClause {
63646370
/// 'extension' [SimpleIdentifier]? [TypeParameterList]?
63656371
/// 'on' [TypeAnnotation] [ShowClause]? [HideClause]?
63666372
/// '{' [ClassMember]* '}'
6367-
abstract final class ExtensionDeclaration
6368-
implements CompilationUnitMember, FragmentDeclaration {
6373+
abstract final class ExtensionDeclaration implements CompilationUnitMember {
63696374
/// The `augment` keyword, or `null` if the keyword was absent.
63706375
@experimental
63716376
Token? get augmentKeyword;
@@ -6694,7 +6699,7 @@ final class ExtensionOverrideImpl extends ExpressionImpl
66946699
/// '}'
66956700
@experimental
66966701
abstract final class ExtensionTypeDeclaration
6697-
implements NamedCompilationUnitMember, FragmentDeclaration {
6702+
implements NamedCompilationUnitMember {
66986703
/// The `augment` keyword, or `null` if the keyword was absent.
66996704
@experimental
67006705
Token? get augmentKeyword;
@@ -6923,6 +6928,9 @@ final class FieldDeclarationImpl extends ClassMemberImpl
69236928
@override
69246929
Element? get declaredElement => null;
69256930

6931+
@override
6932+
Fragment? get declaredFragment => null;
6933+
69266934
@override
69276935
Token get endToken => semicolon;
69286936

@@ -8073,18 +8081,6 @@ final class ForStatementImpl extends StatementImpl
80738081
}
80748082
}
80758083

8076-
/// A declaration of a fragment of an element.
8077-
@experimental
8078-
abstract final class FragmentDeclaration implements Declaration {
8079-
// TODO(pq): move `declaredFragment` into `Declaration` and remove this class.
8080-
8081-
/// The fragment declared by this declaration.
8082-
///
8083-
/// Returns `null` if the AST structure hasn't been resolved.
8084-
@experimental
8085-
Fragment? get declaredFragment;
8086-
}
8087-
80888084
/// A node representing the body of a function or method.
80898085
///
80908086
/// functionBody ::=
@@ -8203,8 +8199,7 @@ sealed class FunctionBodyImpl extends AstNodeImpl implements FunctionBody {
82038199
// augmented and declarations that can't be augmented. This results in getters
82048200
// that are only sometimes applicable. Consider changing the class hierarchy so
82058201
// that these two kinds of variables can be distinguished.
8206-
abstract final class FunctionDeclaration
8207-
implements NamedCompilationUnitMember, FragmentDeclaration {
8202+
abstract final class FunctionDeclaration implements NamedCompilationUnitMember {
82088203
/// The `augment` keyword, or `null` if there is no `augment` keyword.
82098204
@experimental
82108205
Token? get augmentKeyword;
@@ -8742,8 +8737,7 @@ final class FunctionReferenceImpl extends CommentReferableExpressionImpl
87428737
///
87438738
/// functionPrefix ::=
87448739
/// [TypeAnnotation]? [SimpleIdentifier]
8745-
abstract final class FunctionTypeAlias
8746-
implements TypeAlias, FragmentDeclaration {
8740+
abstract final class FunctionTypeAlias implements TypeAlias {
87478741
@override
87488742
TypeAliasElement? get declaredElement;
87498743

@@ -9104,8 +9098,7 @@ final class GenericFunctionTypeImpl extends TypeAnnotationImpl
91049098
/// functionTypeAlias ::=
91059099
/// 'typedef' [SimpleIdentifier] [TypeParameterList]? =
91069100
/// [FunctionType] ';'
9107-
abstract final class GenericTypeAlias
9108-
implements TypeAlias, FragmentDeclaration {
9101+
abstract final class GenericTypeAlias implements TypeAlias {
91099102
/// The equal sign separating the name being defined from the function type.
91109103
Token get equals;
91119104

@@ -11798,8 +11791,7 @@ final class MapPatternImpl extends DartPatternImpl implements MapPattern {
1179811791
/// Prior to the 'extension-methods' experiment, these nodes were always
1179911792
/// children of a class declaration. When the experiment is enabled, these nodes
1180011793
/// can also be children of an extension declaration.
11801-
abstract final class MethodDeclaration
11802-
implements ClassMember, FragmentDeclaration {
11794+
abstract final class MethodDeclaration implements ClassMember {
1180311795
/// The token for the `augment` keyword.
1180411796
Token? get augmentKeyword;
1180511797

@@ -12195,8 +12187,7 @@ abstract final class MethodReferenceExpression implements Expression {
1219512187
/// mixinDeclaration ::=
1219612188
/// 'base'? 'mixin' name [TypeParameterList]?
1219712189
/// [OnClause]? [ImplementsClause]? '{' [ClassMember]* '}'
12198-
abstract final class MixinDeclaration
12199-
implements NamedCompilationUnitMember, FragmentDeclaration {
12190+
abstract final class MixinDeclaration implements NamedCompilationUnitMember {
1220012191
/// The `augment` keyword, or `null` if the keyword was absent.
1220112192
Token? get augmentKeyword;
1220212193

@@ -17652,6 +17643,9 @@ final class TopLevelVariableDeclarationImpl extends CompilationUnitMemberImpl
1765217643
@override
1765317644
Element? get declaredElement => null;
1765417645

17646+
@override
17647+
Fragment? get declaredFragment => null;
17648+
1765517649
@override
1765617650
Token get endToken => semicolon;
1765717651

@@ -18052,7 +18046,7 @@ final class TypeLiteralImpl extends CommentReferableExpressionImpl
1805218046
///
1805318047
/// typeParameter ::=
1805418048
/// name ('extends' [TypeAnnotation])?
18055-
abstract final class TypeParameter implements Declaration, FragmentDeclaration {
18049+
abstract final class TypeParameter implements Declaration {
1805618050
/// The upper bound for legal arguments, or `null` if there's no explicit
1805718051
/// upper bound.
1805818052
TypeAnnotation? get bound;
@@ -18302,8 +18296,7 @@ class UriValidationCode {
1830218296
// augmented and declarations that can't be augmented. This results in getters
1830318297
// that are only sometimes applicable. Consider changing the class hierarchy so
1830418298
// that these two kinds of variables can be distinguished.
18305-
abstract final class VariableDeclaration
18306-
implements Declaration, FragmentDeclaration {
18299+
abstract final class VariableDeclaration implements Declaration {
1830718300
/// The element declared by this declaration.
1830818301
///
1830918302
/// Returns `null` if the AST structure hasn't been resolved or if this node

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class _Visitor extends SimpleAstVisitor<void> {
8383
if (returnType is InterfaceType &&
8484
returnType.element3 ==
8585
// ignore: cast_nullable_to_non_nullable
86-
(parent as FragmentDeclaration).declaredFragment?.element) {
86+
(parent as Declaration).declaredFragment?.element) {
8787
} else {
8888
return;
8989
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ class _DeclarationGatherer {
5353
if (declaration is TopLevelVariableDeclaration) {
5454
declarations.addAll(declaration.variables.variables);
5555
} else {
56-
if (declaration is! FragmentDeclaration) continue;
5756
declarations.add(declaration);
58-
var declaredElement =
59-
(declaration as FragmentDeclaration).declaredFragment?.element;
57+
var declaredElement = declaration.declaredFragment?.element;
6058
if (declaredElement == null || declaredElement.isPrivate) {
6159
continue;
6260
}
@@ -142,7 +140,7 @@ class _DeclarationGatherer {
142140
/// "References" are most often [SimpleIdentifier]s, but can also be other
143141
/// nodes which refer to a declaration.
144142
class _ReferenceVisitor extends RecursiveAstVisitor<void> {
145-
Map<Element2, FragmentDeclaration> declarationMap;
143+
Map<Element2, Declaration> declarationMap;
146144

147145
Set<Declaration> declarations = {};
148146

@@ -463,10 +461,9 @@ class _Visitor extends SimpleAstVisitor<void> {
463461
if (entryPoints.isEmpty) return;
464462

465463
// Map each top-level and static element to its declaration.
466-
var declarationByElement = <Element2, FragmentDeclaration>{};
464+
var declarationByElement = <Element2, Declaration>{};
467465
for (var declaration in declarations) {
468-
var element =
469-
(declaration as FragmentDeclaration).declaredFragment?.element;
466+
var element = declaration.declaredFragment?.element;
470467
if (element != null) {
471468
declarationByElement[element] = declaration;
472469
if (element is TopLevelVariableElement2) {
@@ -516,8 +513,7 @@ class _Visitor extends SimpleAstVisitor<void> {
516513
var unitDeclarations = unitDeclarationGatherer.declarations;
517514
var unusedDeclarations = unitDeclarations.difference(usedMembers);
518515
var unusedMembers = unusedDeclarations.where((declaration) {
519-
var element =
520-
(declaration as FragmentDeclaration).declaredFragment?.element;
516+
var element = declaration.declaredFragment?.element;
521517
return element != null &&
522518
element.isPublic &&
523519
!element.hasVisibleForTesting;

0 commit comments

Comments
 (0)