|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a
|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
5 |
| -import 'package:macros/macros.dart' as macro; |
6 |
| -import 'package:macros/src/executor.dart' as macro; |
7 |
| -import 'package:macros/src/executor/span.dart' as macro; |
8 | 5 | import 'package:_fe_analyzer_shared/src/macros/uri.dart';
|
9 | 6 | import 'package:_fe_analyzer_shared/src/scanner/scanner.dart';
|
10 | 7 | import 'package:front_end/src/fasta/uri_offset.dart';
|
11 | 8 | import 'package:kernel/ast.dart';
|
12 | 9 | import 'package:kernel/class_hierarchy.dart';
|
| 10 | +import 'package:macros/macros.dart' as macro; |
| 11 | +import 'package:macros/src/executor.dart' as macro; |
| 12 | +import 'package:macros/src/executor/span.dart' as macro; |
13 | 13 |
|
14 | 14 | import '../../../api_prototype/compiler_options.dart';
|
15 | 15 | import '../../../base/common.dart';
|
@@ -551,22 +551,34 @@ class MacroApplications {
|
551 | 551 | try {
|
552 | 552 | benchmarker?.beginSubdivide(BenchmarkSubdivides
|
553 | 553 | .macroApplications_macroExecutorInstantiateMacro);
|
554 |
| - macro.MacroInstanceIdentifier instance = |
555 |
| - application.instanceIdentifier = instanceIdCache[ |
556 |
| - application] ??= |
557 |
| - // TODO: Dispose of these instances using |
558 |
| - // `macroExecutor.disposeMacro` once we are done with them. |
559 |
| - await macroExecutor.instantiateMacro( |
560 |
| - libraryUri, |
561 |
| - macroClassName, |
562 |
| - application.constructorName, |
563 |
| - application.arguments); |
564 |
| - |
565 |
| - application.phasesToExecute = macro.Phase.values.where((phase) { |
566 |
| - return instance.shouldExecute(targetDeclarationKind, phase); |
567 |
| - }).toSet(); |
568 |
| - |
569 |
| - if (!instance.supportsDeclarationKind(targetDeclarationKind)) { |
| 554 | + macro.MacroInstanceIdentifier? instance; |
| 555 | + try { |
| 556 | + instance = application.instanceIdentifier = instanceIdCache[ |
| 557 | + application] ??= |
| 558 | + // TODO: Dispose of these instances using |
| 559 | + // `macroExecutor.disposeMacro` once we are done with them. |
| 560 | + await macroExecutor.instantiateMacro( |
| 561 | + libraryUri, |
| 562 | + macroClassName, |
| 563 | + application.constructorName, |
| 564 | + application.arguments); |
| 565 | + } catch (_) { |
| 566 | + applicationData.libraryBuilder.addProblem( |
| 567 | + messageUnsupportedMacroApplication, |
| 568 | + application.uriOffset.fileOffset, |
| 569 | + noLength, |
| 570 | + application.uriOffset.uri); |
| 571 | + } |
| 572 | + |
| 573 | + application.phasesToExecute = instance == null |
| 574 | + ? {} |
| 575 | + : macro.Phase.values.where((phase) { |
| 576 | + return instance! |
| 577 | + .shouldExecute(targetDeclarationKind, phase); |
| 578 | + }).toSet(); |
| 579 | + |
| 580 | + if (instance != null && |
| 581 | + !instance.supportsDeclarationKind(targetDeclarationKind)) { |
570 | 582 | Iterable<macro.DeclarationKind> supportedKinds = macro
|
571 | 583 | .DeclarationKind.values
|
572 | 584 | .where(instance.supportsDeclarationKind);
|
|
0 commit comments