Files
sdk/pkg/analyzer/tool/api/generate.dart
kevmoo a2055fbb82 pkg:api_summary
- Moved existing summary logic to the new package

Change-Id: I47d032f5a253cfa32d9b685d9ff18bb08f534177
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499440
Commit-Queue: Vijay Menon <vsm@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
Reviewed-by: Vijay Menon <vsm@google.com>
2026-05-01 11:29:56 -07:00

44 lines
1.5 KiB
Dart

// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// 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.
/// Generates the file `api.txt`, which describes the analyzer public API.
library;
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer_testing/package_root.dart' as pkg_root;
import 'package:analyzer_utilities/tool/api.dart';
import 'package:analyzer_utilities/tools.dart';
import 'package:api_summary/api_summary.dart';
Future<void> main() async {
await GeneratedContent.generateAll(pkg_root.packageRoot, allTargets);
}
/// A list of all targets generated by this code generator.
final List<GeneratedContent> allTargets = allTargetsForPackage(
'analyzer',
createCustomizer: _ApiSummaryCustomizer.new,
);
/// Customization of the API summary tool that recognizes the
/// `@AnalyzerPublicApi` annotation.
base class _ApiSummaryCustomizer extends ApiSummaryCustomizer {
@override
bool shouldShowDetails(Element element) =>
super.shouldShowDetails(element) ||
element.metadata.annotations.any(_isPublicApiAnnotation);
bool _isPublicApiAnnotation(ElementAnnotation annotation) {
if (annotation.computeConstantValue() case DartObject(
type: InterfaceType(element: InterfaceElement(name: 'AnalyzerPublicApi')),
)) {
return true;
} else {
return false;
}
}
}