From 82592f2ab4749f538b38461e33bbd3ffb9e157ff Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 23 Oct 2024 04:28:19 +0000 Subject: [PATCH] Elements. Inline _buildClass()/_buildMixin() and reuse _EnclosingContext. Change-Id: I974849fb401630c54d9962b2c9dd7f633992d624 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391542 Reviewed-by: Samuel Rawlins Commit-Queue: Konstantin Shcheglov --- .../lib/src/summary2/element_builder.dart | 78 +++++-------------- 1 file changed, 21 insertions(+), 57 deletions(-) diff --git a/pkg/analyzer/lib/src/summary2/element_builder.dart b/pkg/analyzer/lib/src/summary2/element_builder.dart index 70c3bdb49e76..65e9a28975da 100644 --- a/pkg/analyzer/lib/src/summary2/element_builder.dart +++ b/pkg/analyzer/lib/src/summary2/element_builder.dart @@ -124,19 +124,21 @@ class ElementBuilder extends ThrowingAstVisitor { _libraryBuilder.declare(name, reference); } - var holder = _EnclosingContext(reference, element); + var holder = _EnclosingContext(reference, element, + constFieldsForFinalInstance: true); _withEnclosing(holder, () { - var typeParameters = node.typeParameters; - if (typeParameters != null) { - typeParameters.accept(this); - element.typeParameters = holder.typeParameters; - } + node.typeParameters?.accept(this); + _visitPropertyFirst(node.members); }); + element.typeParameters = holder.typeParameters; + element.accessors = holder.propertyAccessors; + element.constructors = holder.constructors; + element.fields = holder.fields; + element.methods = holder.methods; node.extendsClause?.accept(this); node.withClause?.accept(this); node.implementsClause?.accept(this); - _buildClass(node); _libraryBuilder.updateAugmentationTarget(name, element); @@ -512,23 +514,13 @@ class ElementBuilder extends ThrowingAstVisitor { var holder = _EnclosingContext(reference, element); _withEnclosing(holder, () { - var typeParameters = node.typeParameters; - if (typeParameters != null) { - typeParameters.accept(this); - element.typeParameters = holder.typeParameters; - } + node.typeParameters?.accept(this); + _visitPropertyFirst(node.members); }); - - // TODO(scheglov): don't create a duplicate - { - var holder = _EnclosingContext(reference, element); - _withEnclosing(holder, () { - _visitPropertyFirst(node.members); - }); - element.accessors = holder.propertyAccessors; - element.fields = holder.fields; - element.methods = holder.methods; - } + element.typeParameters = holder.typeParameters; + element.accessors = holder.propertyAccessors; + element.fields = holder.fields; + element.methods = holder.methods; node.onClause?.accept(this); @@ -1111,16 +1103,16 @@ class ElementBuilder extends ThrowingAstVisitor { var holder = _EnclosingContext(reference, element); _withEnclosing(holder, () { - var typeParameters = node.typeParameters; - if (typeParameters != null) { - typeParameters.accept(this); - element.typeParameters = holder.typeParameters; - } + node.typeParameters?.accept(this); + _visitPropertyFirst(node.members); }); + element.typeParameters = holder.typeParameters; + element.accessors = holder.propertyAccessors; + element.fields = holder.fields; + element.methods = holder.methods; node.onClause?.accept(this); node.implementsClause?.accept(this); - _buildMixin(node); _libraryBuilder.updateAugmentationTarget(name, element); @@ -1387,21 +1379,6 @@ class ElementBuilder extends ThrowingAstVisitor { return _buildAnnotationsWithUnit(_unitElement, nodeList); } - void _buildClass(ClassDeclaration node) { - var element = node.declaredElement as ClassElementImpl; - // TODO(scheglov): don't create a duplicate - var holder = _EnclosingContext(element.reference!, element, - constFieldsForFinalInstance: true); - _withEnclosing(holder, () { - _visitPropertyFirst(node.members); - }); - - element.accessors = holder.propertyAccessors; - element.constructors = holder.constructors; - element.fields = holder.fields; - element.methods = holder.methods; - } - void _buildExecutableElementChildren({ required Reference reference, required ExecutableElementImpl element, @@ -1436,19 +1413,6 @@ class ElementBuilder extends ThrowingAstVisitor { ); } - void _buildMixin(MixinDeclaration node) { - var element = node.declaredElement as MixinElementImpl; - // TODO(scheglov): don't create a duplicate - var holder = _EnclosingContext(element.reference!, element); - _withEnclosing(holder, () { - _visitPropertyFirst(node.members); - }); - - element.accessors = holder.propertyAccessors; - element.fields = holder.fields; - element.methods = holder.methods; - } - void _buildSyntheticVariable({ required String name, required PropertyAccessorElementImpl accessorElement,