Skip to content

Commit

Permalink
Version 3.5.0-99.0.dev
Browse files Browse the repository at this point in the history
Merge a96841e into dev
  • Loading branch information
Dart CI committed Apr 25, 2024
2 parents 4ec0cf1 + a96841e commit 386cac0
Show file tree
Hide file tree
Showing 10 changed files with 2,232 additions and 90 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 358;
static const int DATA_VERSION = 359;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
9 changes: 1 addition & 8 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3078,17 +3078,11 @@ class ExtensionTypeElementImpl extends InterfaceElementImpl

@override
ConstructorElementImpl get primaryConstructor {
if (isAugmentationChainStart) {
return augmentedInternal.primaryConstructor;
}
return augmented.primaryConstructor;
}

@override
FieldElementImpl get representation {
if (isAugmentationChainStart) {
return augmentedInternal.representation;
}
return augmented.representation;
}

Expand Down Expand Up @@ -5892,7 +5886,6 @@ class NotAugmentedExtensionTypeElementImpl
var augmented = AugmentedExtensionTypeElementImpl(declaration);
augmented.primaryConstructor = primaryConstructor;
augmented.representation = representation;
augmented.typeErasure = typeErasure;
declaration.augmentedInternal = augmented;
return augmented;
}
Expand Down Expand Up @@ -7361,7 +7354,7 @@ abstract class VariableElementImpl extends ElementImpl
String get name => super.name!;

@override
DartType get type => _type ?? InvalidTypeImpl.instance;
DartType get type => _type!;

set type(DartType type) {
_type = type;
Expand Down
22 changes: 22 additions & 0 deletions pkg/analyzer/lib/src/summary2/augmentation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ class AugmentedExtensionDeclarationBuilder
}
}

class AugmentedExtensionTypeDeclarationBuilder
extends AugmentedInstanceDeclarationBuilder {
final ExtensionTypeElementImpl declaration;

AugmentedExtensionTypeDeclarationBuilder({
required this.declaration,
}) {
addFields(declaration.fields);
addConstructors(declaration.constructors);
addAccessors(declaration.accessors);
addMethods(declaration.methods);
}

void augment(ExtensionTypeElementImpl element) {
addFields(element.fields);
addConstructors(element.constructors);
addAccessors(element.accessors);
addMethods(element.methods);
_updatedAugmented(element);
}
}

abstract class AugmentedInstanceDeclarationBuilder {
final Map<String, FieldElementImpl> fields = {};
final Map<String, ConstructorElementImpl> constructors = {};
Expand Down
11 changes: 4 additions & 7 deletions pkg/analyzer/lib/src/summary2/bundle_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@ class ExtensionTypeElementLinkedData
augmented.constructors = reader.readElementList();
augmented.methods = reader.readElementList();
}
element.augmented.typeErasure = reader.readRequiredType();
element.augmented
..primaryConstructor = element.constructors.first
..representation = element.fields.first
..typeErasure = reader.readRequiredType();
}
applyConstantOffsets?.perform();
}
Expand Down Expand Up @@ -1153,12 +1156,6 @@ class LibraryReader {
element.constructors = _readConstructors(unitElement, element, reference);
element.methods = _readMethods(unitElement, element, reference);

if (element.isAugmentationChainStart) {
element.augmentedInternal
..primaryConstructor = element.constructors.first
..representation = element.fields.first;
}

return element;
}

Expand Down
89 changes: 48 additions & 41 deletions pkg/analyzer/lib/src/summary2/element_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,20 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
// TODO(scheglov): We cannot do this anymore.
// Not for class augmentations, not for classes.
_resolveConstructorFieldFormals(element);

if (element.augmentationTarget != null) {
var builder = _libraryBuilder.getAugmentedBuilder(name);
if (builder is AugmentedExtensionTypeDeclarationBuilder) {
builder.augment(element);
}
} else {
_libraryBuilder.putAugmentedBuilder(
name,
AugmentedExtensionTypeDeclarationBuilder(
declaration: element,
),
);
}
}

@override
Expand Down Expand Up @@ -1442,48 +1456,43 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
required ExtensionTypeDeclarationImpl extensionNode,
required RepresentationDeclarationImpl representation,
}) {
if (extensionElement.augmentationTarget != null) {
return;
}

var fieldNameToken = representation.fieldName;
var fieldName = fieldNameToken.lexeme.ifNotEmptyOrElse('<empty>');

ParameterElementImpl formalParameterElement;
if (extensionElement.augmentationTarget == null) {
var fieldElement = FieldElementImpl(
fieldName,
fieldNameToken.offset,
);
fieldElement.isFinal = true;
fieldElement.metadata = _buildAnnotations(representation.fieldMetadata);

var fieldBeginToken =
representation.fieldMetadata.beginToken ?? representation.fieldType;
var fieldCodeRangeOffset = fieldBeginToken.offset;
var fieldCodeRangeLength = fieldNameToken.end - fieldCodeRangeOffset;
fieldElement.setCodeRange(fieldCodeRangeOffset, fieldCodeRangeLength);

representation.fieldElement = fieldElement;
_linker.elementNodes[fieldElement] = representation;
_enclosingContext.addNonSyntheticField(fieldElement);

formalParameterElement = FieldFormalParameterElementImpl(
name: fieldName,
nameOffset: fieldNameToken.offset,
parameterKind: ParameterKind.REQUIRED,
)
..field = fieldElement
..hasImplicitType = true;
formalParameterElement.setCodeRange(
fieldCodeRangeOffset,
fieldCodeRangeLength,
);
var fieldElement = FieldElementImpl(
fieldName,
fieldNameToken.offset,
);
fieldElement.isFinal = true;
fieldElement.metadata = _buildAnnotations(representation.fieldMetadata);

var fieldBeginToken =
representation.fieldMetadata.beginToken ?? representation.fieldType;
var fieldCodeRangeOffset = fieldBeginToken.offset;
var fieldCodeRangeLength = fieldNameToken.end - fieldCodeRangeOffset;
fieldElement.setCodeRange(fieldCodeRangeOffset, fieldCodeRangeLength);

representation.fieldElement = fieldElement;
_linker.elementNodes[fieldElement] = representation;
_enclosingContext.addNonSyntheticField(fieldElement);

var formalParameterElement = FieldFormalParameterElementImpl(
name: fieldName,
nameOffset: fieldNameToken.offset,
parameterKind: ParameterKind.REQUIRED,
)
..field = fieldElement
..hasImplicitType = true;
formalParameterElement.setCodeRange(
fieldCodeRangeOffset,
fieldCodeRangeLength,
);

extensionElement.augmented.representation = fieldElement;
} else {
formalParameterElement = ParameterElementImpl(
name: fieldName,
nameOffset: fieldNameToken.offset,
parameterKind: ParameterKind.REQUIRED,
);
}
extensionElement.augmented.representation = fieldElement;

{
String name;
Expand Down Expand Up @@ -1515,9 +1524,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
_linker.elementNodes[constructorElement] = representation;
_enclosingContext.addConstructor(constructorElement);

if (extensionElement.augmentationTarget == null) {
extensionElement.augmented.primaryConstructor = constructorElement;
}
extensionElement.augmented.primaryConstructor = constructorElement;
}

representation.fieldType.accept(this);
Expand Down
32 changes: 8 additions & 24 deletions pkg/analyzer/lib/src/summary2/informative_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class InformativeDataApplier {
);

if (element.isAugmentationChainStart) {
var representationField = element.representation;
var representationField = element.fields.first;
var infoRep = info.representation;
representationField.nameOffset = infoRep.fieldNameOffset;
representationField.setCodeRange(
Expand Down Expand Up @@ -483,33 +483,17 @@ class InformativeDataApplier {
infoRep.fieldCodeOffset,
infoRep.fieldCodeLength,
);
} else {
var infoRep = info.representation;

var primaryConstructor = element.constructors.first;
primaryConstructor.setCodeRange(
infoRep.constructorCodeOffset,
infoRep.constructorCodeLength,
);
primaryConstructor.periodOffset = infoRep.constructorPeriodOffset;
primaryConstructor.nameOffset = infoRep.constructorNameOffset;
primaryConstructor.nameEnd = infoRep.constructorNameEnd;
var restFields = element.fields.skip(1).toList();
_applyToFields(restFields, info.fields);

var primaryConstructorParameter = primaryConstructor
.parameters_unresolved.first as ParameterElementImpl;
primaryConstructorParameter.nameOffset = infoRep.fieldNameOffset;
primaryConstructorParameter.setCodeRange(
infoRep.fieldCodeOffset,
infoRep.fieldCodeLength,
);
var restConstructors = element.constructors.skip(1).toList();
_applyToConstructors(restConstructors, info.constructors);
} else {
_applyToFields(element.fields, info.fields);
_applyToConstructors(element.constructors, info.constructors);
}

var restFields = element.fields.skip(1).toList();
_applyToFields(restFields, info.fields);

var restConstructors = element.constructors.skip(1).toList();
_applyToConstructors(restConstructors, info.constructors);

_applyToAccessors(element.accessors, info.accessors);
_applyToMethods(element.methods, info.methods);

Expand Down
12 changes: 9 additions & 3 deletions pkg/analyzer/test/src/summary/element_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,15 @@ class _ElementWriter {
while (current != null) {
expect(current.augmented, same(e.augmented));
expect(current.thisType, same(e.thisType));
if (e is ExtensionElementImpl) {
current as ExtensionElementImpl;
expect(current.extendedType, same(e.extendedType));
switch (e) {
case ExtensionElementImpl():
current as ExtensionElementImpl;
expect(current.extendedType, same(e.extendedType));
case ExtensionTypeElementImpl():
current as ExtensionTypeElementImpl;
expect(current.primaryConstructor, same(e.primaryConstructor));
expect(current.representation, same(e.representation));
expect(current.typeErasure, same(e.typeErasure));
}
current = current.augmentationTarget;
}
Expand Down
Loading

0 comments on commit 386cac0

Please sign in to comment.