diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-12-18 18:44:30 +0100 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-12-18 18:44:30 +0100 |
| commit | 605048dda6dc0ab6596bf9b76a6212cedf80a497 (patch) | |
| tree | bec0e13e209655d14cef112c21a416af1c3a1ff2 /lua/alpha/setter_getter_template.lua | |
| parent | eedea2b9c040c41305c0593a22fae7c88a473465 (diff) | |
| download | nvim-conf-605048dda6dc0ab6596bf9b76a6212cedf80a497.tar.gz nvim-conf-605048dda6dc0ab6596bf9b76a6212cedf80a497.zip | |
feat several improvements
Diffstat (limited to 'lua/alpha/setter_getter_template.lua')
| -rw-r--r-- | lua/alpha/setter_getter_template.lua | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/lua/alpha/setter_getter_template.lua b/lua/alpha/setter_getter_template.lua deleted file mode 100644 index fc2099f..0000000 --- a/lua/alpha/setter_getter_template.lua +++ /dev/null @@ -1,99 +0,0 @@ -local utils = require("alpha.utils") - -local M = {} - -local function isNullable(nullable) - if nullable then - return "?" - end - - return "" -end - -local function getReturnTypes(nullable, types) if #types > 0 then - return string.format(": %s%s", isNullable(nullable), table.concat(types, "|")) - end - return "" -end - -local function getTypeHint(nullable, types) if #types > 0 then - return string.format("%s%s ", isNullable(nullable), table.concat(types, "|")) - end - return "" -end - - -local function toTable(fn) - local t = {} - -- todo check why removes all lines - for s in fn:gmatch("[^\r\n]+") do - table.insert(t, s) - end - - return t -end - -M.getGetter = function(property, nullable, types, have_dock_block) - local comment = "" - if have_dock_block and #types > 0 then - comment = string.format( - [[ - /** - * @return %s - */ -]], - table.concat(types, "|") - ) - end - - local fn = string.format( - [[ - public function get%s()%s - { - return $this->%s; - } - ]] , - utils.ucfirst(property), - getReturnTypes(nullable, types), - property - ) - - return toTable(comment .. fn) -end - -M.getSetter = function(property, nullable, types, have_dock_block) - - local comment = "" - if have_dock_block and #types > 0 then - comment = string.format( - [[ - /** - * @param %s $%s - * - * @return self - */ -]], - table.concat(types, "|"), - property - ) - end - local fn = string.format( - [[ - public function set%s(%s$%s): self - { - $this->%s = $%s; - - return $this; - } - ]] , - utils.ucfirst(property), - getTypeHint(nullable, types), - property, - property, - property - ) - - return toTable(comment .. fn) -end - -return M |