Elements. Remove FragmentDeclaration, add 'declaredFragment' to Declaration.
Change-Id: I33398358d1241114b04995767d63188bb314fd6a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394565 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
Commit Queue
parent
82afcb4edd
commit
00a3cdff40
@@ -7,7 +7,7 @@ import 'package:analysis_server/src/lsp/constants.dart';
|
||||
import 'package:analysis_server/src/lsp/error_or.dart';
|
||||
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
|
||||
import 'package:analysis_server/src/lsp/mapping.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
|
||||
import 'package:analyzer/src/utilities/extensions/ast.dart';
|
||||
|
||||
class AugmentationHandler
|
||||
@@ -44,7 +44,7 @@ class AugmentationHandler
|
||||
var node =
|
||||
unit.unit
|
||||
.nodeCovering(offset: offset)
|
||||
?.thisOrAncestorOfType<FragmentDeclaration>();
|
||||
?.thisOrAncestorOfType<ast.Declaration>();
|
||||
|
||||
var location = fragmentToLocation(
|
||||
uriConverter,
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'package:analysis_server/src/lsp/constants.dart';
|
||||
import 'package:analysis_server/src/lsp/error_or.dart';
|
||||
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
|
||||
import 'package:analysis_server/src/lsp/mapping.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
|
||||
import 'package:analyzer/src/utilities/extensions/ast.dart';
|
||||
|
||||
class AugmentedHandler
|
||||
@@ -44,7 +44,7 @@ class AugmentedHandler
|
||||
var node =
|
||||
unit.unit
|
||||
.nodeCovering(offset: offset)
|
||||
?.thisOrAncestorOfType<FragmentDeclaration>();
|
||||
?.thisOrAncestorOfType<ast.Declaration>();
|
||||
|
||||
var location = fragmentToLocation(
|
||||
uriConverter,
|
||||
|
||||
@@ -38,7 +38,7 @@ class RemoveUnusedElement extends _RemoveUnused {
|
||||
}
|
||||
|
||||
Element2? element;
|
||||
if (node is FragmentDeclaration) {
|
||||
if (node is Declaration) {
|
||||
element = node.declaredFragment?.element;
|
||||
}
|
||||
if (element == null) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class RenameMethodParameter extends ResolvedCorrectionProducer {
|
||||
if (methodParameters == null) return;
|
||||
|
||||
Fragment? declaredFragment;
|
||||
if (method.parent case FragmentDeclaration declaration) {
|
||||
if (method.parent case Declaration declaration) {
|
||||
declaredFragment = declaration.declaredFragment;
|
||||
}
|
||||
|
||||
|
||||
@@ -2684,8 +2684,7 @@ class ChildEntity {
|
||||
/// classModifiers ::= 'sealed'
|
||||
/// | 'abstract'? ('base' | 'interface' | 'final')?
|
||||
/// | 'abstract'? 'base'? 'mixin'
|
||||
abstract final class ClassDeclaration
|
||||
implements NamedCompilationUnitMember, FragmentDeclaration {
|
||||
abstract final class ClassDeclaration implements NamedCompilationUnitMember {
|
||||
/// The `abstract` keyword, or `null` if the keyword was absent.
|
||||
Token? get abstractKeyword;
|
||||
|
||||
@@ -2921,7 +2920,7 @@ sealed class ClassMemberImpl extends DeclarationImpl implements ClassMember {
|
||||
///
|
||||
/// mixinApplication ::=
|
||||
/// [NamedType] [WithClause] [ImplementsClause]? ';'
|
||||
abstract final class ClassTypeAlias implements TypeAlias, FragmentDeclaration {
|
||||
abstract final class ClassTypeAlias implements TypeAlias {
|
||||
/// The token for the `abstract` keyword, or `null` if this isn't defining an
|
||||
/// abstract class.
|
||||
Token? get abstractKeyword;
|
||||
@@ -4062,8 +4061,7 @@ final class ConstantPatternImpl extends DartPatternImpl
|
||||
///
|
||||
/// initializerList ::=
|
||||
/// ':' [ConstructorInitializer] (',' [ConstructorInitializer])*
|
||||
abstract final class ConstructorDeclaration
|
||||
implements ClassMember, FragmentDeclaration {
|
||||
abstract final class ConstructorDeclaration implements ClassMember {
|
||||
/// The `augment` keyword, or `null` if the keyword was absent.
|
||||
Token? get augmentKeyword;
|
||||
|
||||
@@ -4797,6 +4795,12 @@ abstract final class Declaration implements AnnotatedNode {
|
||||
/// node corresponds to a list of declarations or if the AST structure hasn't
|
||||
/// been resolved.
|
||||
Element? get declaredElement;
|
||||
|
||||
/// The fragment declared by this declaration.
|
||||
///
|
||||
/// Returns `null` if the AST structure hasn't been resolved.
|
||||
@experimental
|
||||
Fragment? get declaredFragment;
|
||||
}
|
||||
|
||||
sealed class DeclarationImpl extends AnnotatedNodeImpl implements Declaration {
|
||||
@@ -4859,6 +4863,9 @@ final class DeclaredIdentifierImpl extends DeclarationImpl
|
||||
@override
|
||||
LocalVariableElementImpl? declaredElement;
|
||||
|
||||
@override
|
||||
LocalVariableElementImpl? declaredFragment;
|
||||
|
||||
/// Initializes a newly created formal parameter.
|
||||
///
|
||||
/// Either or both of the [comment] and [metadata] can be `null` if the
|
||||
@@ -5539,7 +5546,7 @@ final class EnumConstantArgumentsImpl extends AstNodeImpl
|
||||
}
|
||||
|
||||
/// The declaration of an enum constant.
|
||||
abstract final class EnumConstantDeclaration implements FragmentDeclaration {
|
||||
abstract final class EnumConstantDeclaration implements Declaration {
|
||||
/// The explicit arguments (there are always implicit `index` and `name`
|
||||
/// leading arguments) to the invoked constructor, or `null` if this constant
|
||||
/// doesn't provide any explicit arguments.
|
||||
@@ -5641,8 +5648,7 @@ final class EnumConstantDeclarationImpl extends DeclarationImpl
|
||||
/// metadata 'enum' name [TypeParameterList]?
|
||||
/// [WithClause]? [ImplementsClause]? '{' [SimpleIdentifier]
|
||||
/// (',' [SimpleIdentifier])* (';' [ClassMember]+)? '}'
|
||||
abstract final class EnumDeclaration
|
||||
implements NamedCompilationUnitMember, FragmentDeclaration {
|
||||
abstract final class EnumDeclaration implements NamedCompilationUnitMember {
|
||||
/// The `augment` keyword, or `null` if the keyword was absent.
|
||||
@experimental
|
||||
Token? get augmentKeyword;
|
||||
@@ -6364,8 +6370,7 @@ final class ExtendsClauseImpl extends AstNodeImpl implements ExtendsClause {
|
||||
/// 'extension' [SimpleIdentifier]? [TypeParameterList]?
|
||||
/// 'on' [TypeAnnotation] [ShowClause]? [HideClause]?
|
||||
/// '{' [ClassMember]* '}'
|
||||
abstract final class ExtensionDeclaration
|
||||
implements CompilationUnitMember, FragmentDeclaration {
|
||||
abstract final class ExtensionDeclaration implements CompilationUnitMember {
|
||||
/// The `augment` keyword, or `null` if the keyword was absent.
|
||||
@experimental
|
||||
Token? get augmentKeyword;
|
||||
@@ -6694,7 +6699,7 @@ final class ExtensionOverrideImpl extends ExpressionImpl
|
||||
/// '}'
|
||||
@experimental
|
||||
abstract final class ExtensionTypeDeclaration
|
||||
implements NamedCompilationUnitMember, FragmentDeclaration {
|
||||
implements NamedCompilationUnitMember {
|
||||
/// The `augment` keyword, or `null` if the keyword was absent.
|
||||
@experimental
|
||||
Token? get augmentKeyword;
|
||||
@@ -6923,6 +6928,9 @@ final class FieldDeclarationImpl extends ClassMemberImpl
|
||||
@override
|
||||
Element? get declaredElement => null;
|
||||
|
||||
@override
|
||||
Fragment? get declaredFragment => null;
|
||||
|
||||
@override
|
||||
Token get endToken => semicolon;
|
||||
|
||||
@@ -8073,18 +8081,6 @@ final class ForStatementImpl extends StatementImpl
|
||||
}
|
||||
}
|
||||
|
||||
/// A declaration of a fragment of an element.
|
||||
@experimental
|
||||
abstract final class FragmentDeclaration implements Declaration {
|
||||
// TODO(pq): move `declaredFragment` into `Declaration` and remove this class.
|
||||
|
||||
/// The fragment declared by this declaration.
|
||||
///
|
||||
/// Returns `null` if the AST structure hasn't been resolved.
|
||||
@experimental
|
||||
Fragment? get declaredFragment;
|
||||
}
|
||||
|
||||
/// A node representing the body of a function or method.
|
||||
///
|
||||
/// functionBody ::=
|
||||
@@ -8203,8 +8199,7 @@ sealed class FunctionBodyImpl extends AstNodeImpl implements FunctionBody {
|
||||
// augmented and declarations that can't be augmented. This results in getters
|
||||
// that are only sometimes applicable. Consider changing the class hierarchy so
|
||||
// that these two kinds of variables can be distinguished.
|
||||
abstract final class FunctionDeclaration
|
||||
implements NamedCompilationUnitMember, FragmentDeclaration {
|
||||
abstract final class FunctionDeclaration implements NamedCompilationUnitMember {
|
||||
/// The `augment` keyword, or `null` if there is no `augment` keyword.
|
||||
@experimental
|
||||
Token? get augmentKeyword;
|
||||
@@ -8742,8 +8737,7 @@ final class FunctionReferenceImpl extends CommentReferableExpressionImpl
|
||||
///
|
||||
/// functionPrefix ::=
|
||||
/// [TypeAnnotation]? [SimpleIdentifier]
|
||||
abstract final class FunctionTypeAlias
|
||||
implements TypeAlias, FragmentDeclaration {
|
||||
abstract final class FunctionTypeAlias implements TypeAlias {
|
||||
@override
|
||||
TypeAliasElement? get declaredElement;
|
||||
|
||||
@@ -9104,8 +9098,7 @@ final class GenericFunctionTypeImpl extends TypeAnnotationImpl
|
||||
/// functionTypeAlias ::=
|
||||
/// 'typedef' [SimpleIdentifier] [TypeParameterList]? =
|
||||
/// [FunctionType] ';'
|
||||
abstract final class GenericTypeAlias
|
||||
implements TypeAlias, FragmentDeclaration {
|
||||
abstract final class GenericTypeAlias implements TypeAlias {
|
||||
/// The equal sign separating the name being defined from the function type.
|
||||
Token get equals;
|
||||
|
||||
@@ -11798,8 +11791,7 @@ final class MapPatternImpl extends DartPatternImpl implements MapPattern {
|
||||
/// Prior to the 'extension-methods' experiment, these nodes were always
|
||||
/// children of a class declaration. When the experiment is enabled, these nodes
|
||||
/// can also be children of an extension declaration.
|
||||
abstract final class MethodDeclaration
|
||||
implements ClassMember, FragmentDeclaration {
|
||||
abstract final class MethodDeclaration implements ClassMember {
|
||||
/// The token for the `augment` keyword.
|
||||
Token? get augmentKeyword;
|
||||
|
||||
@@ -12195,8 +12187,7 @@ abstract final class MethodReferenceExpression implements Expression {
|
||||
/// mixinDeclaration ::=
|
||||
/// 'base'? 'mixin' name [TypeParameterList]?
|
||||
/// [OnClause]? [ImplementsClause]? '{' [ClassMember]* '}'
|
||||
abstract final class MixinDeclaration
|
||||
implements NamedCompilationUnitMember, FragmentDeclaration {
|
||||
abstract final class MixinDeclaration implements NamedCompilationUnitMember {
|
||||
/// The `augment` keyword, or `null` if the keyword was absent.
|
||||
Token? get augmentKeyword;
|
||||
|
||||
@@ -17652,6 +17643,9 @@ final class TopLevelVariableDeclarationImpl extends CompilationUnitMemberImpl
|
||||
@override
|
||||
Element? get declaredElement => null;
|
||||
|
||||
@override
|
||||
Fragment? get declaredFragment => null;
|
||||
|
||||
@override
|
||||
Token get endToken => semicolon;
|
||||
|
||||
@@ -18052,7 +18046,7 @@ final class TypeLiteralImpl extends CommentReferableExpressionImpl
|
||||
///
|
||||
/// typeParameter ::=
|
||||
/// name ('extends' [TypeAnnotation])?
|
||||
abstract final class TypeParameter implements Declaration, FragmentDeclaration {
|
||||
abstract final class TypeParameter implements Declaration {
|
||||
/// The upper bound for legal arguments, or `null` if there's no explicit
|
||||
/// upper bound.
|
||||
TypeAnnotation? get bound;
|
||||
@@ -18302,8 +18296,7 @@ class UriValidationCode {
|
||||
// augmented and declarations that can't be augmented. This results in getters
|
||||
// that are only sometimes applicable. Consider changing the class hierarchy so
|
||||
// that these two kinds of variables can be distinguished.
|
||||
abstract final class VariableDeclaration
|
||||
implements Declaration, FragmentDeclaration {
|
||||
abstract final class VariableDeclaration implements Declaration {
|
||||
/// The element declared by this declaration.
|
||||
///
|
||||
/// Returns `null` if the AST structure hasn't been resolved or if this node
|
||||
|
||||
@@ -83,7 +83,7 @@ class _Visitor extends SimpleAstVisitor<void> {
|
||||
if (returnType is InterfaceType &&
|
||||
returnType.element3 ==
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
(parent as FragmentDeclaration).declaredFragment?.element) {
|
||||
(parent as Declaration).declaredFragment?.element) {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,10 +53,8 @@ class _DeclarationGatherer {
|
||||
if (declaration is TopLevelVariableDeclaration) {
|
||||
declarations.addAll(declaration.variables.variables);
|
||||
} else {
|
||||
if (declaration is! FragmentDeclaration) continue;
|
||||
declarations.add(declaration);
|
||||
var declaredElement =
|
||||
(declaration as FragmentDeclaration).declaredFragment?.element;
|
||||
var declaredElement = declaration.declaredFragment?.element;
|
||||
if (declaredElement == null || declaredElement.isPrivate) {
|
||||
continue;
|
||||
}
|
||||
@@ -142,7 +140,7 @@ class _DeclarationGatherer {
|
||||
/// "References" are most often [SimpleIdentifier]s, but can also be other
|
||||
/// nodes which refer to a declaration.
|
||||
class _ReferenceVisitor extends RecursiveAstVisitor<void> {
|
||||
Map<Element2, FragmentDeclaration> declarationMap;
|
||||
Map<Element2, Declaration> declarationMap;
|
||||
|
||||
Set<Declaration> declarations = {};
|
||||
|
||||
@@ -463,10 +461,9 @@ class _Visitor extends SimpleAstVisitor<void> {
|
||||
if (entryPoints.isEmpty) return;
|
||||
|
||||
// Map each top-level and static element to its declaration.
|
||||
var declarationByElement = <Element2, FragmentDeclaration>{};
|
||||
var declarationByElement = <Element2, Declaration>{};
|
||||
for (var declaration in declarations) {
|
||||
var element =
|
||||
(declaration as FragmentDeclaration).declaredFragment?.element;
|
||||
var element = declaration.declaredFragment?.element;
|
||||
if (element != null) {
|
||||
declarationByElement[element] = declaration;
|
||||
if (element is TopLevelVariableElement2) {
|
||||
@@ -516,8 +513,7 @@ class _Visitor extends SimpleAstVisitor<void> {
|
||||
var unitDeclarations = unitDeclarationGatherer.declarations;
|
||||
var unusedDeclarations = unitDeclarations.difference(usedMembers);
|
||||
var unusedMembers = unusedDeclarations.where((declaration) {
|
||||
var element =
|
||||
(declaration as FragmentDeclaration).declaredFragment?.element;
|
||||
var element = declaration.declaredFragment?.element;
|
||||
return element != null &&
|
||||
element.isPublic &&
|
||||
!element.hasVisibleForTesting;
|
||||
|
||||
Reference in New Issue
Block a user