@abaplint/transpiler
Version:
58 lines • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EndMethodTranspiler = void 0;
const abaplint = require("@abaplint/core");
const traversal_1 = require("../traversal");
const chunk_1 = require("../chunk");
class EndMethodTranspiler {
transpile(node, traversal) {
const token = node.getFirstToken();
const scope = traversal.findCurrentScopeByToken(token);
if (scope === undefined) {
throw new Error("EndMethodTranspiler, scope not found");
}
let returning = "";
returning += this.setSubrc(scope, traversal);
const vars = scope.getData().vars;
for (const n in vars) {
const identifier = vars[n];
if (identifier.getMeta().includes("returning" /* abaplint.IdentifierMeta.MethodReturning */)) {
returning += "return " + traversal_1.Traversal.prefixVariable(n.toLowerCase()) + ";\n";
}
}
const data = scope.getIdentifier();
if (data.stype === abaplint.ScopeType.Method && data.sname.toLowerCase() === "constructor") {
returning += "return this;\n";
}
return new chunk_1.Chunk().append(returning + "}", node, traversal);
}
setSubrc(scope, traversal) {
let methodName = undefined;
if (scope?.getIdentifier().stype === abaplint.ScopeType.Method) {
methodName = scope?.getIdentifier().sname;
}
let className = undefined;
if (scope?.getParent()?.getIdentifier().stype === abaplint.ScopeType.ClassImplementation) {
className = scope?.getParent()?.getIdentifier().sname;
}
if (methodName === undefined || className === undefined) {
return "";
}
let methodDef = undefined;
if (methodName.includes("~")) {
const split = methodName.split("~");
const classDef = traversal.findInterfaceDefinition(split[0], scope);
methodDef = classDef?.getMethodDefinitions().getByName(split[1]);
}
else {
const classDef = traversal.findClassDefinition(className, scope);
methodDef = classDef?.getMethodDefinitions().getByName(methodName);
}
if (methodDef && methodDef.getExceptions().length > 0) {
return "abap.builtin.sy.get().subrc.set(0);\n";
}
return "";
}
}
exports.EndMethodTranspiler = EndMethodTranspiler;
//# sourceMappingURL=end_method.js.map