Skip to content

Commit

Permalink
feat: Add support for Groovy by inhering Java logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Jun 18, 2019
1 parent efb1a88 commit 798bf38
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ simply put your cursor on a function, press `<C-d>`(<kbd>Ctrl</kbd> +
- [x] Coffeescript ([JSDoc](https://jsdoc.app))
- [x] Lua ([LDoc](https://github.com/stevedonovan/LDoc))
- [x] Java ([JavaDoc](https://www.oracle.com/technetwork/articles/javase/index-137868.html))
- [x] Groovy ([JavaDoc](https://www.oracle.com/technetwork/articles/javase/index-137868.html))
- [x] Ruby ([YARD](https://www.rubydoc.info/gems/yard/file/docs/Tags.md))
- [x] Scala ([ScalaDoc](https://docs.scala-lang.org/style/scaladoc.html))
- [x] Kotlin ([KDoc](https://kotlinlang.org/docs/reference/kotlin-doc.html))
Expand Down
48 changes: 48 additions & 0 deletions ftplugin/groovy.vim
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
80 changes: 80 additions & 0 deletions test/filetypes/groovy/class-methods.vader
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) {}
}

0 comments on commit 798bf38

Please sign in to comment.