maybeApplyMacro method Null safety

  1. @override
Future<List<String>?> maybeApplyMacro(
  1. TypeChecker checker,
  2. Macro macro,
  3. Element element,
  4. Resolver resolver,
  5. StringBuffer buffer,
  6. StringBuffer libraryBuffer,
  7. String originalSource
)

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));
  }
}