-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for Groovy by inhering Java logic
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
" ============================================================================== | ||
" The Groovy documentation should follow the 'JavaDoc' conventions. | ||
" see https://www.oracle.com/technetwork/articles/javase/index-137868.html | ||
" | ||
" This ftplugin should always reflect the logic of the ftplugin/java.vim. | ||
" ============================================================================== | ||
|
||
|
||
let s:save_cpo = &cpoptions | ||
set cpoptions&vim | ||
|
||
let b:doge_patterns = [] | ||
|
||
" ============================================================================== | ||
" Matches class methods. | ||
" ============================================================================== | ||
" | ||
" Matches the following scenarios: | ||
" | ||
" private void setChildrenRecursively(ElementDto childDto, int childId) {} | ||
" | ||
" private List<ElementDto> createSortedList(Map<Integer, ElementDto> map, int type) {} | ||
" | ||
" void foo(Map<String, Object> parameters) {} | ||
" | ||
" void MyParameterizedFunction(String param1, int param2, Boolean ...params) {} | ||
call add(b:doge_patterns, { | ||
\ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s*\)*\%(\%(\([[:alnum:]_]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\)\?\s\+\)\?\([[:alnum:]_]\+\)(\(.\{-}\))\s*{', | ||
\ 'match_group_names': ['returnType', 'funcName', 'parameters'], | ||
\ 'parameters': { | ||
\ 'match': '\m\%(\([[:alnum:]_]\+\)\%(<[[:alnum:][:space:]_,]\+>\)\?\)\%(\s\+[.]\{3}\s\+\|\s\+[.]\{3}\|[.]\{3}\s\+\|\s\+\)\([[:alnum:]_]\+\)', | ||
\ 'match_group_names': ['type', 'name'], | ||
\ 'format': ['@param', '{type}', '{name}', 'TODO'], | ||
\ }, | ||
\ 'comment': { | ||
\ 'insert': 'above', | ||
\ 'template': [ | ||
\ '/**', | ||
\ ' * TODO', | ||
\ ' * {parameters}', | ||
\ '! * @return {returnType|void} TODO', | ||
\ ' */', | ||
\ ], | ||
\ }, | ||
\}) | ||
|
||
let &cpoptions = s:save_cpo | ||
unlet s:save_cpo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Groovy tests should be equal to Java tests. | ||
|
||
# ============================================================================== | ||
# Method without parameters. | ||
# ============================================================================== | ||
Given groovy (method without parameters): | ||
class Test { | ||
List<Element> createSortedList() {} | ||
} | ||
|
||
Do (trigger doge): | ||
:2\<CR> | ||
\<C-d> | ||
|
||
Expect groovy (method with 'TODO' and a @return tag): | ||
class Test { | ||
/** | ||
* TODO | ||
* @return List TODO | ||
*/ | ||
List<Element> createSortedList() {} | ||
} | ||
|
||
# ============================================================================== | ||
# Methods without return type. | ||
# ============================================================================== | ||
Given groovy (method without return type): | ||
class Test { | ||
public createSortedList() {} | ||
} | ||
|
||
Do (trigger doge): | ||
:2\<CR> | ||
\<C-d> | ||
|
||
Expect groovy (method with 'TODO' and a @return tag containing 'void'): | ||
class Test { | ||
/** | ||
* TODO | ||
* @return void TODO | ||
*/ | ||
public createSortedList() {} | ||
} | ||
|
||
# ============================================================================== | ||
# Methods with parameters. | ||
# ============================================================================== | ||
Given groovy (methods with parameters): | ||
class Test { | ||
private static MstRelation MyParameterizedMethod(String param1, int param2, Boolean ...params) {} | ||
|
||
ListResultBean<MstRelation> MyParameterizedMethod(String param1, int param2, Boolean... params) {} | ||
} | ||
|
||
Do (trigger doge): | ||
:2\<CR> | ||
\<C-d> | ||
:11\<CR> | ||
\<C-d> | ||
|
||
Expect groovy (generated comments with @param and @return tags): | ||
class Test { | ||
/** | ||
* TODO | ||
* @param String param1 TODO | ||
* @param int param2 TODO | ||
* @param Boolean params TODO | ||
* @return MstRelation TODO | ||
*/ | ||
private static MstRelation MyParameterizedMethod(String param1, int param2, Boolean ...params) {} | ||
|
||
/** | ||
* TODO | ||
* @param String param1 TODO | ||
* @param int param2 TODO | ||
* @param Boolean params TODO | ||
* @return ListResultBean TODO | ||
*/ | ||
ListResultBean<MstRelation> MyParameterizedMethod(String param1, int param2, Boolean... params) {} | ||
} |