Wikia

Vim Tips Wiki

Changes: Script:490

Edit

Back to page

(Added quick hack to support generics #2 (hint to javadoc creation))
(Change <tt> to <code>, perhaps also minor tweak.)
Line 12: Line 12:
   
 
:A quick hack to support generics:
 
:A quick hack to support generics:
:#Open your <tt>java_getset.vim</tt> file
+
:#Open your <code>java_getset.vim</code> file
:#Search for definition of <tt>s:variable</tt> (i.e. <tt>let s:variable = ......</tt>)
+
:#Search for definition of <code>s:variable</code> (i.e. <code>let s:variable = ......</code>)
:#Before that line add a new definition: <tt>let s:generics = '\%(\s*\%(<.*>\)\)\='</tt>
+
:#Before that line add a new definition: <code>let s:generics = '\%(\s*\%(<.*>\)\)\='</code>
:#Change the definition of <tt>s:variable</tt> to (see underlined part): <tt>let s:variable = '\(\s*\)\(\(' . s:modifier . '\s\+\)*\)\(' . s:javaname . <u>s:generics . </u>'\)' . s:brackets . '\s\+\(' . s:javaname . '\)\s*\(;\|=[^;]\+;\)'</tt>
+
:#Change the definition of <code>s:variable</code> to (see underlined part): <code>let s:variable = '\(\s*\)\(\(' . s:modifier . '\s\+\)*\)\(' . s:javaname . <u>s:generics . </u>'\)' . s:brackets . '\s\+\(' . s:javaname . '\)\s*\(;\|=[^;]\+;\)'</code>
:What this does is it extends the regular expression matching the field definitions by adding "<tt><...></tt>" to the type part. Actually it does not check for what's inside the angle brackets and since allowing for multi-type generics and nested generics, too.
+
:What this does is it extends the regular expression matching the field definitions by adding "<code><...></code>" to the type part. Actually it does not check for what's inside the angle brackets and since allowing for multi-type generics and nested generics, too.
 
:(As with the nature of quick hacks this one does not fix the javadoc creation where angle brackets will still appear as angle brackets instead of HTML-code.)
 
:(As with the nature of quick hacks this one does not fix the javadoc creation where angle brackets will still appear as angle brackets instead of HTML-code.)
 
:--February 27, 2012
 
:--February 27, 2012

Revision as of 09:53, July 14, 2012

Use this page to discuss script 490 java_getset: automatically add getter/setters for Java properties

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on vim.org).
  • This page may be out of date: check the script's vim.org page above, and its release notes.

Problem with generics

Superb script really great, however it seems to fail on generics.

private List<String> foo;

getset won't generate methods for this field.

private List foo;

but it will when generics are removed. --January 16, 2012


A quick hack to support generics:
  1. Open your java_getset.vim file
  2. Search for definition of s:variable (i.e. let s:variable = ......)
  3. Before that line add a new definition: let s:generics = '\%(\s*\%(<.*>\)\)\='
  4. Change the definition of s:variable to (see underlined part): let s:variable = '\(\s*\)\(\(' . s:modifier . '\s\+\)*\)\(' . s:javaname . s:generics . '\)' . s:brackets . '\s\+\(' . s:javaname . '\)\s*\(;\|=[^;]\+;\)'
What this does is it extends the regular expression matching the field definitions by adding "<...>" to the type part. Actually it does not check for what's inside the angle brackets and since allowing for multi-type generics and nested generics, too.
(As with the nature of quick hacks this one does not fix the javadoc creation where angle brackets will still appear as angle brackets instead of HTML-code.)
--February 27, 2012

Comments

Around Wikia's network

Random Wiki