Skip to content

Do not crash in the presence of macro applications. #3665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/src/model/method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -136,8 +135,7 @@ class PubPackageBuilder implements PackageBuilder {

late final Map<String, List<Folder>> _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?
Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion lib/src/model/source_code_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
};
}
}