Version 2.14.0-350.0.dev
Merge commit '40766bd74266af011e410614179f054ac5db4226' into 'dev'
diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json
index e05af29..06c07a9 100644
--- a/.dart_tool/package_config.json
+++ b/.dart_tool/package_config.json
@@ -11,7 +11,7 @@
"constraint, update this by running tools/generate_package_config.dart."
],
"configVersion": 2,
- "generated": "2021-07-22T12:39:20.084398",
+ "generated": "2021-07-23T12:33:04.456358",
"generator": "tools/generate_package_config.dart",
"packages": [
{
@@ -731,7 +731,7 @@
"name": "typed_data",
"rootUri": "../third_party/pkg/typed_data",
"packageUri": "lib/",
- "languageVersion": "2.10"
+ "languageVersion": "2.12"
},
{
"name": "usage",
@@ -800,4 +800,4 @@
"languageVersion": "2.12"
}
]
-}
\ No newline at end of file
+}
diff --git a/DEPS b/DEPS
index f31a4bf..b299924 100644
--- a/DEPS
+++ b/DEPS
@@ -115,7 +115,7 @@
"html_rev": "00cd3c22dac0e68e6ed9e7e4945101aedb1b3109",
"http_io_rev": "2fa188caf7937e313026557713f7feffedd4978b",
"http_multi_server_rev": "de1b312164c24a1690b46c6e97bd47eff40c4649",
- "http_parser_rev": "7720bfd42a0c096734c5213478fdce92c62f0293",
+ "http_parser_rev": "202391286ddc13c4c3c284ac5b511f04697250ed",
"http_rev": "778174bca2c13becd88ef3353309190b1e8b9479",
"http_throttle_tag" : "1.0.2",
"icu_rev" : "81d656878ec611cb0b42d52c82e9dae93920d9ba",
@@ -164,7 +164,7 @@
"term_glyph_rev": "6a0f9b6fb645ba75e7a00a4e20072678327a0347",
"test_reflective_loader_rev": "54e930a11c372683792e22bddad79197728c91ce",
"test_rev": "099dcc4d052a30c6921489cfbefa1c8531d12975",
- "typed_data_tag": "f94fc57b8e8c0e4fe4ff6cfd8290b94af52d3719",
+ "typed_data_rev": "29ce5a92b03326d0b8035916ac04f528874994bd",
"usage_rev": "e0780cd8b2f8af69a28dc52678ffe8492da27d06",
"vector_math_rev": "0c9f5d68c047813a6dcdeb88ba7a42daddf25025",
"watcher_rev": "3924194385fb215cef483193ed2879a618a3d69c",
@@ -456,7 +456,7 @@
Var("dart_git") + "test_reflective_loader.git" +
"@" + Var("test_reflective_loader_rev"),
Var("dart_root") + "/third_party/pkg/typed_data":
- Var("dart_git") + "typed_data.git" + "@" + Var("typed_data_tag"),
+ Var("dart_git") + "typed_data.git" + "@" + Var("typed_data_rev"),
Var("dart_root") + "/third_party/pkg/usage":
Var("dart_git") + "usage.git" + "@" + Var("usage_rev"),
Var("dart_root") + "/third_party/pkg/vector_math":
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 017468a..5342239 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -80,7 +80,7 @@
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
- static const int DATA_VERSION = 164;
+ static const int DATA_VERSION = 166;
/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index d466919..7660639 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:collection';
+import 'dart:typed_data';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/session.dart';
@@ -2046,9 +2047,6 @@
/// The length of the element's code, or `null` if the element is synthetic.
int? _codeLength;
- /// The language version for the library.
- LibraryLanguageVersion? _languageVersion;
-
/// Initialize a newly created element to have the given [name] at the given
/// [_nameOffset].
ElementImpl(String? name, this._nameOffset, {this.reference}) {
@@ -2361,15 +2359,6 @@
/// children of this element's parent.
String get identifier => name!;
- /// Return `true` if this element was created from a macro-generated code.
- bool get isFromMacro {
- return hasModifier(Modifier.IS_FROM_MACRO);
- }
-
- set isFromMacro(bool isFromMacro) {
- setModifier(Modifier.IS_FROM_MACRO, isFromMacro);
- }
-
bool get isNonFunctionTypeAliasesEnabled {
return library!.featureSet.isEnabled(Feature.nonfunction_type_aliases);
}
@@ -2723,7 +2712,12 @@
/// The code that for produced by the macro.
final String code;
- ElementMacro(this.id, this.code);
+ /// When we build elements from macro-produced code, we remember informative
+ /// data, such as offsets - to store it into bytes. This field is set to
+ /// an empty list when reading from bytes.
+ final Uint8List informative;
+
+ ElementMacro(this.id, this.code, this.informative);
}
/// An [AbstractClassElementImpl] which is an enum.
@@ -3638,6 +3632,9 @@
@override
final AnalysisSession session;
+ /// The language version for the library.
+ LibraryLanguageVersion? _languageVersion;
+
bool hasTypeProviderSystemSet = false;
@override
@@ -4308,26 +4305,23 @@
/// type being referred to is the return type.
static const Modifier IMPLICIT_TYPE = Modifier('IMPLICIT_TYPE', 16);
- /// Indicates that this element was created from macro-generated code.
- static const Modifier IS_FROM_MACRO = Modifier('IS_FROM_MACRO', 17);
-
/// Indicates that modifier 'lazy' was applied to the element.
- static const Modifier LATE = Modifier('LATE', 18);
+ static const Modifier LATE = Modifier('LATE', 17);
/// Indicates that a class is a mixin application.
- static const Modifier MIXIN_APPLICATION = Modifier('MIXIN_APPLICATION', 19);
+ static const Modifier MIXIN_APPLICATION = Modifier('MIXIN_APPLICATION', 18);
/// Indicates that the pseudo-modifier 'set' was applied to the element.
- static const Modifier SETTER = Modifier('SETTER', 20);
+ static const Modifier SETTER = Modifier('SETTER', 19);
/// Indicates that the modifier 'static' was applied to the element.
- static const Modifier STATIC = Modifier('STATIC', 21);
+ static const Modifier STATIC = Modifier('STATIC', 20);
/// Indicates that the element does not appear in the source code but was
/// implicitly created. For example, if a class does not define any
/// constructors, an implicit zero-argument constructor will be created and it
/// will be marked as being synthetic.
- static const Modifier SYNTHETIC = Modifier('SYNTHETIC', 22);
+ static const Modifier SYNTHETIC = Modifier('SYNTHETIC', 21);
static const List<Modifier> values = [
ABSTRACT,
@@ -4346,7 +4340,6 @@
HAS_INITIALIZER,
HAS_PART_OF_DIRECTIVE,
IMPLICIT_TYPE,
- IS_FROM_MACRO,
LATE,
MIXIN_APPLICATION,
SETTER,
diff --git a/pkg/analyzer/lib/src/macro/impl/macro.dart b/pkg/analyzer/lib/src/macro/impl/macro.dart
index 85f0223..ddb1a2b 100644
--- a/pkg/analyzer/lib/src/macro/impl/macro.dart
+++ b/pkg/analyzer/lib/src/macro/impl/macro.dart
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:typed_data';
+
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart' as ast;
import 'package:analyzer/dart/ast/token.dart';
@@ -9,6 +11,7 @@
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/macro/api/code.dart';
import 'package:analyzer/src/macro/api/macro.dart';
+import 'package:analyzer/src/summary2/informative_data.dart';
class ClassDeclarationBuilderImpl extends DeclarationBuilderImpl
implements ClassDeclarationBuilder {
@@ -19,27 +22,31 @@
@override
void addToClass(Declaration declaration) {
+ var declarationCode = declaration.code.trim();
+
// TODO(scheglov) feature set
// TODO(scheglov) throw if errors?
var parseResult = parseString(
- content: 'class ${node.name.name} { $declaration }',
+ content: 'class ${node.name.name} { $declarationCode }',
);
var parsedDeclarations = parseResult.unit.declarations;
var parsedClass = parsedDeclarations.single as ast.ClassDeclaration;
var parsedMember = parsedClass.members.single;
- _resetOffsets(parsedMember);
+ _rebaseOffsets(parsedMember);
node.members.add(parsedMember);
_collector._add(parsedMember, declaration);
}
/// We parsed [node] in the context of some synthetic code string, its
- /// current offsets are meaningless. So, we reset them for now.
- static void _resetOffsets(ast.AstNode node) {
+ /// current offsets only have meaning relative to the begin offset of the
+ /// [node]. So, we update offsets accordingly.
+ static void _rebaseOffsets(ast.AstNode node) {
+ var baseOffset = node.offset;
for (Token? t = node.beginToken;
t != null && t != node.endToken;
t = t.next) {
- t.offset = -1;
+ t.offset -= baseOffset;
}
}
}
@@ -68,9 +75,11 @@
if (node is ast.Declaration) {
var element = node.declaredElement;
if (element is HasElementMacro) {
+ var collectedDeclaration = entry.value;
(element as HasElementMacro).macro = ElementMacro(
- entry.value.id,
- entry.value.declaration.code,
+ collectedDeclaration.id,
+ collectedDeclaration.declaration.code,
+ collectedDeclaration.informative,
);
}
}
@@ -78,13 +87,22 @@
}
void _add(ast.AstNode node, Declaration declaration) {
- _declarations[node] = _CollectedDeclaration(_nextId++, declaration);
+ _declarations[node] = _CollectedDeclaration(
+ _nextId++,
+ declaration,
+ writeDeclarationInformative(node),
+ );
}
}
class _CollectedDeclaration {
final int id;
final Declaration declaration;
+ final Uint8List informative;
- _CollectedDeclaration(this.id, this.declaration);
+ _CollectedDeclaration(
+ this.id,
+ this.declaration,
+ this.informative,
+ );
}
diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
index 94e46ae..13b33b1 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
@@ -495,8 +495,10 @@
_declareDartCoreDynamicNever();
- InformativeDataApplier(_elementFactory, _unitsInformativeBytes)
- .applyTo(libraryElement);
+ InformativeDataApplier(_elementFactory).applyTo(
+ _unitsInformativeBytes,
+ libraryElement,
+ );
return libraryElement;
}
@@ -850,12 +852,17 @@
return LibraryLanguageVersion(package: package, override: override);
}
- ElementMacro? _readMacro() {
- var hasData = _reader.readBool();
- if (hasData) {
- var id = _reader.readUInt30();
- var code = _reader.readStringUtf8();
- return ElementMacro(id, code);
+ void _readMacro(Element element, HasElementMacro hasMacro) {
+ if (_reader.readBool()) {
+ hasMacro.macro = ElementMacro(
+ _reader.readUInt30(),
+ _reader.readStringUtf8(),
+ Uint8List(0),
+ );
+ InformativeDataApplier(_elementFactory).applyToDeclaration(
+ element,
+ _reader.readUint8List(),
+ );
}
}
@@ -995,7 +1002,6 @@
var element = PropertyAccessorElementImpl(name, -1);
PropertyAccessorElementFlags.read(_reader, element);
- element.macro = _readMacro();
var reference = classReference
.getChild(element.isGetter ? '@getter' : '@setter')
@@ -1009,6 +1015,7 @@
element.setLinkedData(reference, linkedData);
element.parameters = _readParameters(element, reference);
+ _readMacro(element, element);
return element;
}
diff --git a/pkg/analyzer/lib/src/summary2/bundle_writer.dart b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
index a112b46..b9be7f8 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
@@ -285,6 +285,7 @@
if (macro != null) {
_sink.writeUInt30(macro.id);
_sink.writeStringUtf8(macro.code);
+ _sink.writeUint8List(macro.informative);
}
}
@@ -372,11 +373,12 @@
_sink.writeUInt30(_resolutionSink.offset);
_sink._writeStringReference(element.displayName);
PropertyAccessorElementFlags.write(_sink, element);
- _writeMacro(element.macro);
_resolutionSink._writeAnnotationList(element.metadata);
_resolutionSink.writeType(element.returnType);
+
_writeList(element.parameters, _writeParameterElement);
+ _writeMacro(element.macro);
}
void _writeReferences(List<Reference> references) {
diff --git a/pkg/analyzer/lib/src/summary2/element_builder.dart b/pkg/analyzer/lib/src/summary2/element_builder.dart
index 983c60a..790c470 100644
--- a/pkg/analyzer/lib/src/summary2/element_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/element_builder.dart
@@ -96,25 +96,10 @@
) {
var holder = _buildClassMembers(element, members);
- for (var newElement in holder.propertyAccessors) {
- newElement.isFromMacro = true;
- element.accessors.add(newElement);
- }
-
- for (var newElement in holder.constructors) {
- newElement.isFromMacro = true;
- element.constructors.add(newElement);
- }
-
- for (var newElement in holder.properties.whereType<FieldElementImpl>()) {
- newElement.isFromMacro = true;
- element.fields.add(newElement);
- }
-
- for (var newElement in holder.methods) {
- newElement.isFromMacro = true;
- element.methods.add(newElement);
- }
+ element.accessors.addAll(holder.propertyAccessors);
+ element.constructors.addAll(holder.constructors);
+ element.fields.addAll(holder.properties.whereType<FieldElementImpl>());
+ element.methods.addAll(holder.methods);
}
@override
diff --git a/pkg/analyzer/lib/src/summary2/element_flags.dart b/pkg/analyzer/lib/src/summary2/element_flags.dart
index f43df16..529a06f 100644
--- a/pkg/analyzer/lib/src/summary2/element_flags.dart
+++ b/pkg/analyzer/lib/src/summary2/element_flags.dart
@@ -8,14 +8,12 @@
class ClassElementFlags {
static const int _isAbstract = 1 << 0;
- static const int _isFromMacro = 1 << 1;
static const int _isMixinApplication = 1 << 2;
static const int _isSimplyBounded = 1 << 3;
static void read(SummaryDataReader reader, ClassElementImpl element) {
var byte = reader.readByte();
element.isAbstract = (byte & _isAbstract) != 0;
- element.isFromMacro = (byte & _isFromMacro) != 0;
element.isMixinApplication = (byte & _isMixinApplication) != 0;
element.isSimplyBounded = (byte & _isSimplyBounded) != 0;
}
@@ -23,7 +21,6 @@
static void write(BufferedSink sink, ClassElementImpl element) {
var result = 0;
result |= element.isAbstract ? _isAbstract : 0;
- result |= element.isFromMacro ? _isFromMacro : 0;
result |= element.isMixinApplication ? _isMixinApplication : 0;
result |= element.isSimplyBounded ? _isSimplyBounded : 0;
sink.writeByte(result);
@@ -63,7 +60,6 @@
static const int _isCovariant = 1 << 5;
static const int _isExternal = 1 << 6;
static const int _isFinal = 1 << 7;
- static const int _isFromMacro = 1 << 8;
static const int _isLate = 1 << 9;
static const int _isStatic = 1 << 10;
@@ -77,7 +73,6 @@
element.isCovariant = (byte & _isCovariant) != 0;
element.isExternal = (byte & _isExternal) != 0;
element.isFinal = (byte & _isFinal) != 0;
- element.isFromMacro = (byte & _isFromMacro) != 0;
element.isLate = (byte & _isLate) != 0;
element.isStatic = (byte & _isStatic) != 0;
}
@@ -92,7 +87,6 @@
result |= element.isCovariant ? _isCovariant : 0;
result |= element.isExternal ? _isExternal : 0;
result |= element.isFinal ? _isFinal : 0;
- result |= element.isFromMacro ? _isFromMacro : 0;
result |= element.isLate ? _isLate : 0;
result |= element.isStatic ? _isStatic : 0;
sink.writeUInt30(result);
@@ -167,7 +161,6 @@
static const int _isAbstract = 1 << 1;
static const int _isAsynchronous = 1 << 2;
static const int _isExternal = 1 << 3;
- static const int _isFromMacro = 1 << 4;
static const int _isGenerator = 1 << 5;
static const int _isStatic = 1 << 6;
@@ -177,7 +170,6 @@
element.isAbstract = (byte & _isAbstract) != 0;
element.isAsynchronous = (byte & _isAsynchronous) != 0;
element.isExternal = (byte & _isExternal) != 0;
- element.isFromMacro = (byte & _isFromMacro) != 0;
element.isGenerator = (byte & _isGenerator) != 0;
element.isStatic = (byte & _isStatic) != 0;
}
@@ -188,7 +180,6 @@
result |= element.isAbstract ? _isAbstract : 0;
result |= element.isAsynchronous ? _isAsynchronous : 0;
result |= element.isExternal ? _isExternal : 0;
- result |= element.isFromMacro ? _isFromMacro : 0;
result |= element.isGenerator ? _isGenerator : 0;
result |= element.isStatic ? _isStatic : 0;
sink.writeByte(result);
@@ -226,7 +217,6 @@
static const int _isAbstract = 1 << 3;
static const int _isAsynchronous = 1 << 4;
static const int _isExternal = 1 << 5;
- static const int _isFromMacro = 1 << 6;
static const int _isGenerator = 1 << 7;
static const int _isStatic = 1 << 8;
@@ -241,7 +231,6 @@
element.isAbstract = (byte & _isAbstract) != 0;
element.isAsynchronous = (byte & _isAsynchronous) != 0;
element.isExternal = (byte & _isExternal) != 0;
- element.isFromMacro = (byte & _isFromMacro) != 0;
element.isGenerator = (byte & _isGenerator) != 0;
element.isStatic = (byte & _isStatic) != 0;
}
@@ -254,7 +243,6 @@
result |= element.isAbstract ? _isAbstract : 0;
result |= element.isAsynchronous ? _isAsynchronous : 0;
result |= element.isExternal ? _isExternal : 0;
- result |= element.isFromMacro ? _isFromMacro : 0;
result |= element.isGenerator ? _isGenerator : 0;
result |= element.isStatic ? _isStatic : 0;
sink.writeUInt30(result);
diff --git a/pkg/analyzer/lib/src/summary2/informative_data.dart b/pkg/analyzer/lib/src/summary2/informative_data.dart
index 1dd1e5f..ca9e274 100644
--- a/pkg/analyzer/lib/src/summary2/informative_data.dart
+++ b/pkg/analyzer/lib/src/summary2/informative_data.dart
@@ -19,6 +19,15 @@
import 'package:analyzer/src/util/comment.dart';
import 'package:collection/collection.dart';
+/// Write the informative data (mostly offsets) of the given [node].
+/// Throw [UnimplementedError] if [node] is not supported.
+Uint8List writeDeclarationInformative(AstNode node) {
+ var byteSink = ByteSink();
+ var sink = BufferedSink(byteSink);
+ _InformativeDataWriter(sink).writeDeclaration(node);
+ return sink.flushAndTake();
+}
+
Uint8List writeUnitInformative(CompilationUnit unit) {
var byteSink = ByteSink();
var sink = BufferedSink(byteSink);
@@ -55,14 +64,13 @@
class InformativeDataApplier {
final LinkedElementFactory _elementFactory;
- final Map<Uri, Uint8List> _unitsInformativeBytes2;
- InformativeDataApplier(
- this._elementFactory,
- this._unitsInformativeBytes2,
- );
+ InformativeDataApplier(this._elementFactory);
- void applyTo(LibraryElementImpl libraryElement) {
+ void applyTo(
+ Map<Uri, Uint8List> unitsInformativeBytes,
+ LibraryElementImpl libraryElement,
+ ) {
if (_elementFactory.isApplyingInformativeData) {
throw StateError('Unexpected recursion.');
}
@@ -72,7 +80,7 @@
for (var i = 0; i < unitElements.length; i++) {
var unitElement = unitElements[i] as CompilationUnitElementImpl;
var unitUri = unitElement.source.uri;
- var unitInfoBytes = _unitsInformativeBytes2[unitUri];
+ var unitInfoBytes = unitsInformativeBytes[unitUri];
if (unitInfoBytes != null) {
var unitReader = SummaryDataReader(unitInfoBytes);
var unitInfo = _InfoUnit(unitReader);
@@ -140,35 +148,41 @@
_elementFactory.isApplyingInformativeData = false;
}
+ /// Read informative data from [bytes], and apply it to [element].
+ /// The data and the [element] must correspond to each other.
+ void applyToDeclaration(Element element, Uint8List bytes) {
+ if (_elementFactory.isApplyingInformativeData) {
+ throw StateError('Unexpected recursion.');
+ }
+ _elementFactory.isApplyingInformativeData = true;
+
+ var reader = SummaryDataReader(bytes);
+
+ var kindIndex = reader.readByte();
+ var kind = _DeclarationKind.values[kindIndex];
+
+ if (kind == _DeclarationKind.methodDeclaration &&
+ element is PropertyAccessorElement) {
+ var info = _InfoMethodDeclaration(reader);
+ _applyToPropertyAccessor(element, info);
+ } else {
+ throw UnimplementedError(
+ 'Unsupported kind: $kind, '
+ 'or element: ${element.runtimeType}',
+ );
+ }
+
+ _elementFactory.isApplyingInformativeData = false;
+ }
+
void _applyToAccessors(
List<PropertyAccessorElement> elementList,
List<_InfoMethodDeclaration> infoList,
) {
- forCorrespondingPairs<PropertyAccessorElement, _InfoMethodDeclaration>(
+ forCorrespondingPairs(
elementList.notSynthetic,
infoList,
- (element, info) {
- element as PropertyAccessorElementImpl;
- element.setCodeRange(info.codeOffset, info.codeLength);
- element.nameOffset = info.nameOffset;
- element.documentationComment = info.documentationComment;
- _applyToFormalParameters(
- element.parameters_unresolved,
- info.parameters,
- );
-
- var linkedData = element.linkedData;
- if (linkedData is PropertyAccessorElementLinkedData) {
- linkedData.applyConstantOffsets = ApplyConstantOffsets(
- info.constantOffsets,
- (applier) {
- applier.applyToMetadata(element);
- applier.applyToTypeParameters(element.typeParameters);
- applier.applyToFormalParameters(element.parameters);
- },
- );
- }
- },
+ _applyToPropertyAccessor,
);
}
@@ -499,6 +513,31 @@
);
}
+ void _applyToMethod(MethodElement element, _InfoMethodDeclaration info) {
+ element as MethodElementImpl;
+ element.setCodeRange(info.codeOffset, info.codeLength);
+ element.nameOffset = info.nameOffset;
+ element.documentationComment = info.documentationComment;
+ _applyToTypeParameters(
+ element.typeParameters_unresolved,
+ info.typeParameters,
+ );
+ _applyToFormalParameters(
+ element.parameters_unresolved,
+ info.parameters,
+ );
+
+ var linkedData = element.linkedData as MethodElementLinkedData;
+ linkedData.applyConstantOffsets = ApplyConstantOffsets(
+ info.constantOffsets,
+ (applier) {
+ applier.applyToMetadata(element);
+ applier.applyToTypeParameters(element.typeParameters);
+ applier.applyToFormalParameters(element.parameters);
+ },
+ );
+ }
+
void _applyToMethods(
List<MethodElement> elementList,
List<_InfoMethodDeclaration> infoList,
@@ -506,30 +545,7 @@
forCorrespondingPairs<MethodElement, _InfoMethodDeclaration>(
elementList,
infoList,
- (element, info) {
- element as MethodElementImpl;
- element.setCodeRange(info.codeOffset, info.codeLength);
- element.nameOffset = info.nameOffset;
- element.documentationComment = info.documentationComment;
- _applyToTypeParameters(
- element.typeParameters_unresolved,
- info.typeParameters,
- );
- _applyToFormalParameters(
- element.parameters_unresolved,
- info.parameters,
- );
-
- var linkedData = element.linkedData as MethodElementLinkedData;
- linkedData.applyConstantOffsets = ApplyConstantOffsets(
- info.constantOffsets,
- (applier) {
- applier.applyToMetadata(element);
- applier.applyToTypeParameters(element.typeParameters);
- applier.applyToFormalParameters(element.parameters);
- },
- );
- },
+ _applyToMethod,
);
}
@@ -560,6 +576,32 @@
);
}
+ void _applyToPropertyAccessor(
+ PropertyAccessorElement element,
+ _InfoMethodDeclaration info,
+ ) {
+ element as PropertyAccessorElementImpl;
+ element.setCodeRange(info.codeOffset, info.codeLength);
+ element.nameOffset = info.nameOffset;
+ element.documentationComment = info.documentationComment;
+ _applyToFormalParameters(
+ element.parameters_unresolved,
+ info.parameters,
+ );
+
+ var linkedData = element.linkedData;
+ if (linkedData is PropertyAccessorElementLinkedData) {
+ linkedData.applyConstantOffsets = ApplyConstantOffsets(
+ info.constantOffsets,
+ (applier) {
+ applier.applyToMetadata(element);
+ applier.applyToTypeParameters(element.typeParameters);
+ applier.applyToFormalParameters(element.parameters);
+ },
+ );
+ }
+ }
+
void _applyToTopLevelVariable(
TopLevelVariableElement element,
_InfoTopLevelVariable info,
@@ -629,6 +671,10 @@
}
}
+enum _DeclarationKind {
+ methodDeclaration,
+}
+
class _InfoClassDeclaration {
final int codeOffset;
final int codeLength;
@@ -1289,6 +1335,15 @@
);
}
+ void writeDeclaration(AstNode node) {
+ if (node is MethodDeclaration) {
+ sink.addByte(_DeclarationKind.methodDeclaration.index);
+ _writeMethod(node);
+ } else {
+ throw UnimplementedError('(${node.runtimeType}) $node');
+ }
+ }
+
int _codeOffsetForVariable(VariableDeclaration node) {
var codeOffset = node.offset;
var variableList = node.parent as VariableDeclarationList;
@@ -1383,19 +1438,7 @@
.whereType<MethodDeclaration>()
.where((e) => e.isGetter || e.isSetter)
.toList(),
- (node) {
- sink.writeUInt30(node.offset);
- sink.writeUInt30(node.length);
- sink.writeUInt30(node.name.offset);
- _writeDocumentationComment(node);
- _writeTypeParameters(node.typeParameters);
- _writeFormalParameters(node.parameters);
- _writeOffsets(
- metadata: node.metadata,
- typeParameters: node.typeParameters,
- formalParameters: node.parameters,
- );
- },
+ _writeMethod,
);
}
@@ -1420,25 +1463,27 @@
);
}
+ void _writeMethod(MethodDeclaration node) {
+ sink.writeUInt30(node.offset);
+ sink.writeUInt30(node.length);
+ sink.writeUInt30(node.name.offset);
+ _writeDocumentationComment(node);
+ _writeTypeParameters(node.typeParameters);
+ _writeFormalParameters(node.parameters);
+ _writeOffsets(
+ metadata: node.metadata,
+ typeParameters: node.typeParameters,
+ formalParameters: node.parameters,
+ );
+ }
+
void _writeMethods(List<ClassMember> members) {
sink.writeList<MethodDeclaration>(
members
.whereType<MethodDeclaration>()
.where((e) => !(e.isGetter || e.isSetter))
.toList(),
- (node) {
- sink.writeUInt30(node.offset);
- sink.writeUInt30(node.length);
- sink.writeUInt30(node.name.offset);
- _writeDocumentationComment(node);
- _writeTypeParameters(node.typeParameters);
- _writeFormalParameters(node.parameters);
- _writeOffsets(
- metadata: node.metadata,
- typeParameters: node.typeParameters,
- formalParameters: node.parameters,
- );
- },
+ _writeMethod,
);
}
diff --git a/pkg/analyzer/lib/src/summary2/reference.dart b/pkg/analyzer/lib/src/summary2/reference.dart
index a2cf17b..7269b91 100644
--- a/pkg/analyzer/lib/src/summary2/reference.dart
+++ b/pkg/analyzer/lib/src/summary2/reference.dart
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/summary2/scope.dart';
@@ -32,14 +31,6 @@
/// The simple name of the reference in its [parent].
final String name;
- /// The node accessor, used to read nodes lazily.
- /// Or `null` if a named container.
- ReferenceNodeAccessor? nodeAccessor;
-
- /// The corresponding [AstNode], or `null` if a named container.
- /// TODO(scheglov) remove it
- AstNode? node;
-
/// The corresponding [Element], or `null` if a named container.
Element? element;
@@ -97,21 +88,6 @@
return map[name] ??= Reference._(this, name);
}
- /// If the reference has element, and it is for the [node], return `true`.
- ///
- /// The element might be not `null`, but the node is different in case of
- /// duplicate declarations.
- bool hasElementFor(AstNode node) {
- if (element != null && this.node == node) {
- return true;
- } else {
- if (this.node == null) {
- this.node = node;
- }
- return false;
- }
- }
-
void removeChild(String name) {
_children!.remove(name);
}
@@ -119,13 +95,3 @@
@override
String toString() => parent == null ? 'root' : '$parent::$name';
}
-
-abstract class ReferenceNodeAccessor {
- /// Return the node that corresponds to this [Reference], read it if not yet.
- AstNode get node;
-
- /// Fill [Reference.nodeAccessor] for children.
- ///
- /// TODO(scheglov) only class reader has a meaningful implementation.
- void readIndex();
-}
diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart
index 8e2ebe9..42f8774 100644
--- a/pkg/analyzer/test/src/summary/element_text.dart
+++ b/pkg/analyzer/test/src/summary/element_text.dart
@@ -685,7 +685,7 @@
}
}
- if (e.isSynthetic || e.isFromMacro) {
+ if (e.isSynthetic) {
expect(e.nameOffset, -1);
} else {
expect(e.nameOffset, isPositive);
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 7c789a4f..bc3a7da 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -21288,17 +21288,17 @@
requiredPositional __f @-1
type: int
returnType: void
- get f @-1
+ get f @8
macro
id: 0
code: int get f => _f;
returnType: int
- set f @-1
+ set f @4
macro
id: 1
code: set f(int val) {\n print('Setting f to ${val}');\n _f = val;\n}
parameters
- requiredPositional val @-1
+ requiredPositional val @10
type: int
returnType: void
''');
@@ -21349,17 +21349,17 @@
requiredPositional __f @-1
type: T
returnType: void
- get f @-1
+ get f @6
macro
id: 0
code: T get f => _f;
returnType: T
- set f @-1
+ set f @4
macro
id: 1
code: set f(T val) {\n print('Setting f to ${val}');\n _f = val;\n}
parameters
- requiredPositional val @-1
+ requiredPositional val @8
type: T
returnType: void
''');
diff --git a/tools/VERSION b/tools/VERSION
index 1633d98..110a5dc 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 14
PATCH 0
-PRERELEASE 349
+PRERELEASE 350
PRERELEASE_PATCH 0
\ No newline at end of file