Implementation
@override
Future<List<String>?> maybeApplyMacro(
TypeChecker checker,
Macro macro,
analyzer.Element element,
Resolver resolver,
StringBuffer buffer,
StringBuffer libraryBuffer,
String originalSource) async {
if (!checker.hasAnnotationOf(element)) return null;
_checkValidMacroApplication(element, macro);
macro = _instantiateFromMeta(macro, checker.firstAnnotationOf(element)!);
if (element is analyzer.ClassElement && macro is ClassDeclarationMacro) {
macro.visitClassDeclaration(
AnalyzerClassDeclaration(element,
originalReference: element.thisType),
_MacroClassDeclarationBuilder(
classBuffer: buffer,
libraryBuffer: libraryBuffer,
libraryElement: element.library));
// TODO: return list of names of declarations modified
} else if (element is analyzer.FieldElement &&
macro is FieldDeclarationMacro) {
macro.visitFieldDeclaration(
AnalyzerFieldDeclaration(element),
_MacroClassDeclarationBuilder(
classBuffer: buffer,
libraryBuffer: libraryBuffer,
libraryElement: element.library));
} else if ((element is analyzer.MethodElement ||
element is analyzer.ConstructorElement) &&
macro is MethodDeclarationMacro) {
macro.visitMethodDeclaration(
AnalyzerMethodDeclaration(element as analyzer.ExecutableElement),
_MacroClassDeclarationBuilder(
classBuffer: buffer,
libraryBuffer: libraryBuffer,
libraryElement: element.library));
} else if (element is analyzer.FunctionElement &&
macro is FunctionDeclarationMacro) {
macro.visitFunctionDeclaration(
AnalyzerMethodDeclaration(element),
_MacroLibraryDeclarationBuilder(
libraryBuffer: libraryBuffer, libraryElement: element.library));
}
}