"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemberFactory = void 0; const MemberInitializer_1 = require("./MemberInitializer"); const Method_1 = require("./members/Method"); const Field_1 = require("./members/Field"); const Signal_1 = require("./members/Signal"); class MemberFactory { static grabMembers(membersData, accessModifier) { let members = []; if (!membersData) { return members; } for (let it in membersData) { if (!membersData.hasOwnProperty(it)) { continue; } let nameDefinition = it; let memberData = membersData[it]; if (MemberFactory.actionRegex.test(nameDefinition)) { let name = MemberFactory.actionRegex.exec(nameDefinition)[1]; let upperCaseName = name[0].toUpperCase() + name.substring(1); let actionName = `on${upperCaseName}`; let signal = `signal ${name}()`; members.push(MemberFactory.create(accessModifier, signal, {})); members.push(MemberFactory.create(accessModifier, actionName, "Node")); } else if (MemberFactory.propertyRegex.test(nameDefinition)) { let result = MemberFactory.propertyRegex.exec(nameDefinition); let signalName = result[1]; let fieldName = result[2]; signalName = signalName || `${fieldName}Changed`; let upperCaseName = signalName[0].toUpperCase() + signalName.substring(1); let actionName = `on${upperCaseName}`; let signal = `signal ${signalName}()`; if (!result[1]) { members.push(MemberFactory.create(accessModifier, signal, {})); members.push(MemberFactory.create(accessModifier, actionName, "Node")); } let field = MemberFactory.create(accessModifier, fieldName, memberData); field.isProperty = true; field.propertySignalName = signalName; field.propertyActionName = actionName; members.push(field); } else { let classMember = MemberFactory.create(accessModifier, nameDefinition, memberData); members.push(classMember); } } return members; } static create(accessModifier, nameDefinition, body) { let memberInitializer = new MemberInitializer_1.MemberInitializer(); if (nameDefinition.indexOf("()") != -1) { memberInitializer.isMethod = true; memberInitializer.isVirtual = true; let typeRegex = /\(\)\s*(?:\:\s*(.+)\s*)?$/; let result = typeRegex.exec(nameDefinition); if (result[1]) { memberInitializer.type = result[1]; } nameDefinition = nameDefinition.replace(typeRegex, ""); } let names = nameDefinition.split(/\s+/); memberInitializer.name = names[names.length - 1]; for (let i = 0; i < names.length - 1; i++) { if ("final" === names[i]) { memberInitializer.isVirtual = false; } if ("static" === names[i]) { memberInitializer.isStatic = true; } if ("signal" === names[i]) { memberInitializer.isSignal = true; } } let member = null; if (memberInitializer.isMethod) { if (memberInitializer.isSignal) { member = new Signal_1.Signal(memberInitializer); } else { member = new Method_1.Method(memberInitializer); } } else { member = new Field_1.Field(memberInitializer); } member.accessModifier = accessModifier; member.parseBody(body); return member; } } exports.MemberFactory = MemberFactory; MemberFactory.actionRegex = /^\s*action\s+(\w+)\s*$/; MemberFactory.propertyRegex = /^\s*property(?:\s*\@\s*(\w+))?\s+(\w+)\s*$/; //# sourceMappingURL=MemberFactory.js.map