All files / src/objects/rename rename_table.ts

94.11% Statements 32/34
66.66% Branches 2/3
100% Functions 2/2
94.11% Lines 32/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 341x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 3x     3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x
import {IRegistry} from "../../_iregistry";
import {WorkspaceEdit, TextDocumentEdit, CreateFile, RenameFile, DeleteFile} from "vscode-languageserver-types";
import {Table} from "..";
import {ObjectRenamer} from "./_object_renamer";
import {IObject} from "../_iobject";
import {RenamerHelper} from "./renamer_helper";
 
export class RenameTable implements ObjectRenamer {
  private readonly reg: IRegistry;
 
  public constructor(reg: IRegistry) {
    this.reg = reg;
  }
 
  public buildEdits(obj: IObject, oldName: string, newName: string): WorkspaceEdit | undefined {
    if (!(obj instanceof Table)) {
      throw new Error("RenameTable, not a table");
    }
 
    let changes: (TextDocumentEdit | CreateFile | RenameFile | DeleteFile)[] = [];
    const helper = new RenamerHelper(this.reg);
    changes = changes.concat(helper.buildXMLFileEdits(obj, "TABNAME", oldName, newName));
    changes = changes.concat(helper.buildXMLFileEdits(obj, "FORTABLE", oldName, newName));
    changes = changes.concat(helper.renameFiles(obj, oldName, newName));
    changes = changes.concat(helper.renameDDICCodeReferences(obj, oldName, newName));
    changes = changes.concat(helper.renameDDICTABLReferences(obj, oldName, newName));
    changes = changes.concat(helper.renameDDICTTYPReferences(obj, oldName, newName));
 
    return {
      documentChanges: changes,
    };
  }
 
}