diff --git a/lib/src/model/method.dart b/lib/src/model/method.dart index 2f0cc5d0a0..006aaa8660 100644 --- a/lib/src/model/method.dart +++ b/lib/src/model/method.dart @@ -113,7 +113,8 @@ class Method extends ModelElement return null; } var parent = element.enclosingElement as InterfaceElement; - for (var t in parent.allSupertypes) { + var parentDeclaration = parent.augmented?.declaration ?? parent; + for (var t in parentDeclaration.allSupertypes) { Element? e = t.getMethod(element.name); if (e != null) { assert( diff --git a/lib/src/model/package_builder.dart b/lib/src/model/package_builder.dart index 6096b071a2..eb259f4ba4 100644 --- a/lib/src/model/package_builder.dart +++ b/lib/src/model/package_builder.dart @@ -4,7 +4,6 @@ import 'dart:async'; -import 'package:analyzer/dart/analysis/analysis_context_collection.dart'; import 'package:analyzer/dart/analysis/context_root.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/ast/ast.dart'; @@ -136,8 +135,7 @@ class PubPackageBuilder implements PackageBuilder { late final Map> _packageMap; - late final AnalysisContextCollection _contextCollection = - AnalysisContextCollectionImpl( + late final _contextCollection = AnalysisContextCollectionImpl( includedPaths: [_config.inputDir], // TODO(jcollins-g): should we pass excluded directories here instead of // handling it ourselves? @@ -464,6 +462,8 @@ class PubPackageBuilder implements PackageBuilder { specialFiles.difference(files), addingSpecials: true, ); + // Shutdown macro support. + await _contextCollection.dispose(); } /// Throws an exception if any configured-to-be-included files were not found diff --git a/lib/src/model/source_code_mixin.dart b/lib/src/model/source_code_mixin.dart index eafd92bfeb..79505d4f11 100644 --- a/lib/src/model/source_code_mixin.dart +++ b/lib/src/model/source_code_mixin.dart @@ -13,7 +13,8 @@ mixin SourceCode implements Documentable { Element? get element; - bool get hasSourceCode => config.includeSource && sourceCode.isNotEmpty; + bool get hasSourceCode => + config.includeSource && !element.isAugmentation && sourceCode.isNotEmpty; Library? get library; @@ -22,3 +23,18 @@ mixin SourceCode implements Documentable { return modelNode == null ? '' : modelNode.sourceCode; } } + +extension on Element? { + /// Whether `this` is an augmentation method or property. + /// + /// This property should only be referenced for elements whose source code we + /// may wish to refer to. + bool get isAugmentation { + final self = this; + return switch (self) { + ExecutableElement() => self.augmentationTarget != null, + PropertyInducingElement() => self.augmentationTarget != null, + _ => false, + }; + } +}