UNPKG

@abaplint/core

Version:
55 lines 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RenameGlobalClass = void 0; const Statements = require("../../abap/2_statements/statements"); const Expressions = require("../../abap/2_statements/expressions"); const vscode_languageserver_types_1 = require("vscode-languageserver-types"); const __1 = require(".."); const _lsp_utils_1 = require("../../lsp/_lsp_utils"); const renamer_helper_1 = require("./renamer_helper"); class RenameGlobalClass { constructor(reg) { this.reg = reg; } buildEdits(obj, oldName, newName) { if (!(obj instanceof __1.Class)) { throw new Error("not a class"); } const main = obj.getMainABAPFile(); if (main === undefined) { throw new Error(`Main file not found, ${obj.getType()} ${obj.getName()}`); } let changes = []; // todo, this is actually the same as "id" ? { const edits = []; for (const s of main.getStatements()) { if (s.get() instanceof Statements.ClassDefinition) { const exp = s.findFirstExpression(Expressions.ClassName); if (exp === undefined) { continue; } edits.push(vscode_languageserver_types_1.TextEdit.replace(_lsp_utils_1.LSPUtils.tokenToRange(exp.getFirstToken()), newName.toLowerCase())); } else if (s.get() instanceof Statements.ClassImplementation) { const exp = s.findFirstExpression(Expressions.ClassName); if (exp === undefined) { continue; } edits.push(vscode_languageserver_types_1.TextEdit.replace(_lsp_utils_1.LSPUtils.tokenToRange(exp.getFirstToken()), newName.toLowerCase())); } } changes.push(vscode_languageserver_types_1.TextDocumentEdit.create({ uri: main.getFilename(), version: 1 }, edits)); } const helper = new renamer_helper_1.RenamerHelper(this.reg); changes = changes.concat(helper.buildXMLFileEdits(obj, "CLSNAME", oldName, newName)); changes = changes.concat(helper.renameFiles(obj, oldName, newName)); changes = changes.concat(helper.renameReferences(obj.getIdentifier(), oldName, newName)); changes = changes.concat(helper.renameDDICTABLReferences(obj, oldName, newName)); return { documentChanges: changes, }; } } exports.RenameGlobalClass = RenameGlobalClass; //# sourceMappingURL=rename_global_class.js.map