performInsertions method

void performInsertions(
  1. AFCommandContext context,
  2. AFSourceTemplateInsertions insertions
)

Converts AFSourceTemplateInsertion tags into the values specified in insertions.

Implementation

void performInsertions(AFCommandContext context, AFSourceTemplateInsertions insertions) {
  // first, insert all the source templates.
  for(final key in insertions.keys) {
    var value = insertions.valueFor(key);
    if(key == AFSourceTemplate.insertExtraImportsInsertion) {
      value = _buildExtraImportsFor(context, insertions, value);
    }

    final insertion = key.insertionPoint;
    if (value is AFSourceTemplate) {
      if(containsInsertionPoint(insertion)) {
        final buffer = value.toBuffer(context);
        buffer.performInsertions(context, insertions);
        replaceTextLines(context, insertion, buffer.lines);
      }
    } else if(value is AFCodeBuffer) {
      replaceTextLines(context, insertion, value.lines);
    } else if(value is List<String>) {
      replaceTextLines(context, insertion, value);
    }
  }

  // then, insert all the text strings
  for(final key in insertions.keys) {
    final value = insertions.valueFor(key);
    final insertion = key.insertionPoint;
    if(value is String) {
      replaceText(context, insertion, value);
    }
  }
}