anchor.diff:      // If still at the beginning of the file, add before the first declaration.
       int offset;
       bool insertEmptyLineAfter = false;
  -    if (unit.declarations.isNotEmpty) {
  -      offset = unit.declarations.first.offset;
  +    if (resolvedUnit.unit.declarations.isNotEmpty) {
  +      offset = resolvedUnit.unit.declarations.first.offset;
         insertEmptyLineAfter = true;
       } else {
  -      offset = unit.end;
  +      offset = resolvedUnit.unit.end;
       }
       addInsertion(offset, (EditBuilder builder) {
         for (int i = 0; i < importList.length; i++) {
  
positive.code:             {ImportDirective prev,
              ImportDirective next,
              bool trailingNewLine: false}) {
            LineInfo lineInfo = unit.lineInfo;
            if (prev != null) {
              int offset = prev.end;
              int line = lineInfo.getLocation(offset).lineNumber;
  
negative.code:     LibraryDirective libraryDirective;
      List<ImportDirective> importDirectives = <ImportDirective>[];
      PartDirective partDirective;
      for (Directive directive in resolvedUnit.unit.directives) {
        if (directive is LibraryDirective) {
          libraryDirective = directive;
        } else if (directive is ImportDirective) {
  