Fandom

Vim Tips Wiki

JavaBeans helper function

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 525 Printable Monobook Previous Next

created 2003 · complexity intermediate · author Lech Ambrzykowski · version 6.0


This one helps creating beans. Nothing serious actually, but might come in handy.

nnoremap <buffer> <silent>dc :call <SID>AddBean()<CR>
function! s:AddBean()
  let line = line('.')
  let name = inputdialog('Enter the name of the variable: ')
  let type = inputdialog('Enter the type of the variable: ')
  let upperName = substitute(name, '^\(\w\)\(.*\)$', '\u\1\2', '')
  call append(line, "\t}")
  call append(line, "\t\tthis.".name." = ".name.";")
  call append(line, "\tpublic void set".upperName."(".type." ".name.") {")
  call append(line, "")
  call append(line, "\t}")
  call append(line, "\t\treturn (this.".name.");")
  call append(line, "\tpublic ".type." get"."".upperName."() { ")
  call append(line, "")
  call append(line, "\tprivate ".type." ".name.";")
  call append(line, "\t//".name)
  return line
endfunction

CommentsEdit

You might be interested in http://www.ophinity.com/papers/wrangling/index.html#multiply

It's fairly generic but i use it to chug thru a list of values and apply those to a code-template. it lends itself to setters & getters.


Also on Fandom

Random Wiki