@abaplint/core
Version:
abaplint - Core API
77 lines • 4.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AttributeName = void 0;
const void_type_1 = require("../../types/basic/void_type");
const structure_type_1 = require("../../types/basic/structure_type");
const object_reference_type_1 = require("../../types/basic/object_reference_type");
const _object_oriented_1 = require("../_object_oriented");
const data_reference_type_1 = require("../../types/basic/data_reference_type");
const _reference_1 = require("../_reference");
const basic_1 = require("../../types/basic");
const _syntax_input_1 = require("../_syntax_input");
class AttributeName {
static runSyntax(context, node, input, type, error = true) {
if (context instanceof void_type_1.VoidType) {
return context;
}
const helper = new _object_oriented_1.ObjectOriented(input.scope);
let ret = undefined;
if (context instanceof object_reference_type_1.ObjectReferenceType) {
const def = input.scope.findObjectDefinition(context.getIdentifierName());
if (def === undefined) {
const message = "Definition for \"" + context.getIdentifierName() + "\" not found in scope(AttributeName)";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
const token = node.getFirstToken();
const name = token.getStr();
let found = helper.searchAttributeName(def, name);
if (found === undefined) {
found = helper.searchConstantName(def, name);
}
if (found === undefined) {
const message = "Attribute or constant \"" + name + "\" not found in \"" + def.getName() + "\"";
if (error === true) {
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
}
return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
if (type) {
input.scope.addReference(token, found, type, input.filename);
}
if (found && name.includes("~")) {
const idef = input.scope.findInterfaceDefinition(name.split("~")[0]);
if (idef) {
input.scope.addReference(token, idef, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
}
}
ret = found.getType();
}
else if (context instanceof data_reference_type_1.DataReference) {
const sub = context.getType();
const name = node.getFirstToken().getStr();
if (name === "*" || sub instanceof void_type_1.VoidType || sub instanceof basic_1.AnyType) {
return sub;
}
if (!(sub instanceof structure_type_1.StructureType)) {
const message = "Data reference not structured";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
ret = sub.getComponentByName(name);
if (ret === undefined) {
const message = "Component \"" + name + "\" not found in data reference structure";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
}
else {
const message = "Not an object reference, attribute name";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
return ret;
}
}
exports.AttributeName = AttributeName;
//# sourceMappingURL=attribute_name.js.map