diff options
| author | Ariel D'Alessandro <ariel.dalessandro@auto1.com> | 2022-05-31 11:43:22 +0200 |
|---|---|---|
| committer | Ariel D'Alessandro <ariel.dalessandro@auto1.com> | 2022-05-31 11:43:22 +0200 |
| commit | e271d3a3ff8234a68030a6aad8bf586f44f70b7e (patch) | |
| tree | 116f56a23dc155a5779a64da68dc4ee5d6c0c19c /lua/alpha/setter_getter_template.lua | |
| parent | 8ae521098fd01524156dac1bd3e1bd1280bfcb48 (diff) | |
| download | nvim-conf-e271d3a3ff8234a68030a6aad8bf586f44f70b7e.tar.gz nvim-conf-e271d3a3ff8234a68030a6aad8bf586f44f70b7e.zip | |
refactor to get the comment types
Diffstat (limited to 'lua/alpha/setter_getter_template.lua')
| -rw-r--r-- | lua/alpha/setter_getter_template.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lua/alpha/setter_getter_template.lua b/lua/alpha/setter_getter_template.lua new file mode 100644 index 0000000..f4a6f81 --- /dev/null +++ b/lua/alpha/setter_getter_template.lua @@ -0,0 +1,58 @@ +local utils = require("alpha.utils") + +local M = {} + +local function isNullable(nullable) + if nullable then + return "?" + end + + return "" +end + +local function toTable(fn) + local t = {} + for s in fn:gmatch("[^\r\n]+") do + table.insert(t, s) + end + + return t +end + +M.getGetter = function(property, nullable, types) + local fn = string.format([[ + public function get%s(): %s%s + { + return $this->%s; + } + ]], + utils.ucfirst(property), + isNullable(nullable), + table.concat(types, "|"), + property + ) + + return toTable(fn) +end + +M.getSetter = function(property, nullable, types) + local fn = string.format([[ + public function set%s(%s%s $%s): self + { + $this->%s = $%s; + + return $this; + } + ]], + utils.ucfirst(property), + isNullable(nullable), + table.concat(types, "|"), + property, + property, + property + ) + + return toTable(fn) +end + +return M |