Skip to content

Commit

Permalink
feat(java): support exceptions in method declaration along with @throws
Browse files Browse the repository at this point in the history
… tag (#90)
  • Loading branch information
kkoomen committed Jul 24, 2020
1 parent ae944bd commit c6ecbb0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 46 deletions.
3 changes: 3 additions & 0 deletions autoload/doge/preprocessors/java.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function! doge#preprocessors#java#tokens(tokens) abort
if has_key(a:tokens, 'returnType') && a:tokens['returnType'] ==# 'void'
let a:tokens['returnType'] = ''
endif
if has_key(a:tokens, 'exceptions') && !empty(a:tokens['exceptions'])
let a:tokens['exceptions'] = map(split(a:tokens['exceptions'], ','), {k, v -> doge#helpers#trim(v)})
endif
endfunction

let &cpoptions = s:save_cpo
Expand Down
7 changes: 5 additions & 2 deletions ftplugin/java.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ let s:pattern_base = {
"
" ==============================================================================
let s:class_method_pattern = doge#helpers#deepextend(s:pattern_base, {
\ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s*\)*\%(\%(\([[:alnum:]_]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\)\?\s\+\)\?\%([[:alnum:]_]\+\)(\(.\{-}\))\s*[;{]',
\ 'tokens': ['returnType', 'parameters'],
\ 'match': '\m^\%(\%(public\|private\|protected\|static\|final\)\s*\)*\%(\%(\([[:alnum:]_]\+\)\?\s*\%(<[[:alnum:][:space:]_,]*>\)\?\)\?\s\+\)\?\%([[:alnum:]_]\+\)(\(.\{-}\))\s*\%(throws\s\+\(\%(\%([[:alnum:]_]\+\)\%(,\s\+\)\?\)\+\)\)\?\s*[;{]',
\ 'tokens': ['returnType', 'parameters', 'exceptions'],
\ 'parameters': {
\ 'match': '\m\%(\([[:alnum:]_]\+\)\%(<[[:alnum:][:space:]_,]\+>\)\?\)\%(\s\+[.]\{3}\s\+\|\s\+[.]\{3}\|[.]\{3}\s\+\|\s\+\)\([[:alnum:]_]\+\)',
\ 'tokens': ['type', 'name'],
Expand All @@ -51,7 +51,10 @@ call doge#buffer#register_doc_standard('javadoc', [
\ ' * !description',
\ '%(parameters| *)%',
\ '%(parameters| * {parameters})%',
\ '%(returnType| *)%',
\ '%(returnType| * @return !description)%',
\ '%(exceptions| *)%',
\ '%(exceptions| * @throws {exceptions})%',
\ ' */',
\ ],
\ }),
Expand Down
95 changes: 55 additions & 40 deletions playground/test.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
class Test {
/**
* [TODO:description]
* @param ElementDto childDto [TODO:description]
* @param int childId [TODO:description]
* @return void [TODO:description]
*
* @param childDto [TODO:description]
* @param childId [TODO:description]
*/
private void setChildrenRecursively(ElementDto childDto, int childId) {
//
}

/**
* [TODO:description]
* @return void [TODO:description]
*/
void foo();

/**
* [TODO:description]
* @param int childId [TODO:description]
* @return MstRelation [TODO:description]
*
* @param childId [TODO:description]
*
* @return [TODO:description]
*/
@Override
private MstRelation getUpwardRelation(int childId) {
Expand All @@ -27,37 +28,43 @@ private MstRelation getUpwardRelation(int childId) {

/**
* [TODO:description]
* @param int childId [TODO:description]
* @return MstRelation [TODO:description]
*
* @param childId [TODO:description]
*
* @return [TODO:description]
*/
private MstRelation getUpwardRelation(int childId) {
//
}

/**
* [TODO:description]
* @param int parentId [TODO:description]
* @return ListResultBean [TODO:description]
*
* @param parentId [TODO:description]
*
* @return [TODO:description]
*/
private ListResultBean<MstRelation> getAllRelation(int parentId) {
//
}

/**
* [TODO:description]
* @param Map map [TODO:description]
* @param int type [TODO:description]
* @return List [TODO:description]
*
* @param map [TODO:description]
* @param type [TODO:description]
*
* @return [TODO:description]
*/
private List<Element> createSortedList(Map<Integer, ElementDto> map, int type) {
//
}

/**
* [TODO:description]
* @param int parentId [TODO:description]
* @param ListResultBean rels [TODO:description]
* @return void [TODO:description]
*
* @param parentId [TODO:description]
* @param rels [TODO:description]
*/
private void removeRelations(int parentId, ListResultBean<MstRelation> rels) {
//
Expand All @@ -66,59 +73,67 @@ private void removeRelations(int parentId, ListResultBean<MstRelation> rels) {

/**
* [TODO:description]
* @param Map parameters [TODO:description]
* @return void [TODO:description]
*
* @param parameters [TODO:description]
*/
void foo(Map<String, Object> parameters) {
//
}
/**

/**
* [TODO:description]
* @param String p1 [TODO:description]
* @param int p2 [TODO:description]
* @param Boolean params [TODO:description]
* @return void [TODO:description]
*
* @param p1 [TODO:description]
* @param p2 [TODO:description]
* @param params [TODO:description]
*/
void MyParameterizedFunction(String p1, int p2, Boolean... params) {}

/**
* [TODO:description]
* @param String p1 [TODO:description]
* @param int p2 [TODO:description]
* @param Boolean params [TODO:description]
* @return void [TODO:description]
*
* @param p1 [TODO:description]
* @param p2 [TODO:description]
* @param params [TODO:description]
*/
void MyParameterizedFunction(String p1, int p2, Boolean ... params) {}

/**
* [TODO:description]
* @param String p1 [TODO:description]
* @param int p2 [TODO:description]
* @param Boolean params [TODO:description]
* @return void [TODO:description]
*
* @param p1 [TODO:description]
* @param p2 [TODO:description]
* @param params [TODO:description]
*/
void MyParameterizedFunction(String p1, int p2, Boolean ...params) {}

/**
* [TODO:description]
* @return List [TODO:description]
*
* @return [TODO:description]
*/
List<Element> createSortedList() {}

/**
* [TODO:description]
* @param Collection scriptRequests [TODO:description]
* @return Collection [TODO:description]
*
* @param scriptRequests [TODO:description]
*
* @return [TODO:description]
*/
protected Collection<ScriptRequest> createSecureScriptRequests(Collection<ScriptRequest> scriptRequests) {}

/**
* [TODO:description]
* @param IndexSettings indexSettings [TODO:description]
* @param Environment env [TODO:description]
* @param String name [TODO:description]
* @param Settings settings [TODO:description]
* @return void [TODO:description]
*
* @param indexSettings [TODO:description]
* @param env [TODO:description]
* @param name [TODO:description]
* @param settings [TODO:description]
*
* @return [TODO:description]
*
* @throws IOException
* @throws IndexOutOfBoundsException
*/
public UkrainianAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {}
public Collection<ScriptRequest> UkrainianAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) throws IOException, IndexOutOfBoundsException {}
14 changes: 10 additions & 4 deletions test/filetypes/java/class-methods.vader
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ Given java (method without parameters):
Do (trigger doge):
:2\<CR>
\<C-d>
:8\<CR>
:9\<CR>
\<C-d>

Expect java (method with 'TODO' and a @return tag):
class Test {
/**
* [TODO:description]
*
* @return [TODO:description]
*/
List<Element> createSortedList() {}
Expand Down Expand Up @@ -53,15 +54,15 @@ Expect java (method with 'TODO' and a description):
# ==============================================================================
Given java (methods with parameters):
class Test {
private static MstRelation MyParameterizedMethod(String p1, int p2, Boolean ...params) {}
private static MstRelation MyParameterizedMethod(String p1, int p2, Boolean ...params) throws IOException, IndexOutOfBoundsException {}

ListResultBean<MstRelation> MyParameterizedMethod(String p1, int p2, Boolean... params) {}
}

Do (trigger doge):
:2\<CR>
\<C-d>
:12\<CR>
:16\<CR>
\<C-d>

Expect java (generated comments with @param and @return tags):
Expand All @@ -72,16 +73,21 @@ Expect java (generated comments with @param and @return tags):
* @param p1 [TODO:description]
* @param p2 [TODO:description]
* @param params [TODO:description]
*
* @return [TODO:description]
*
* @throws IOException
* @throws IndexOutOfBoundsException
*/
private static MstRelation MyParameterizedMethod(String p1, int p2, Boolean ...params) {}
private static MstRelation MyParameterizedMethod(String p1, int p2, Boolean ...params) throws IOException, IndexOutOfBoundsException {}

/**
* [TODO:description]
*
* @param p1 [TODO:description]
* @param p2 [TODO:description]
* @param params [TODO:description]
*
* @return [TODO:description]
*/
ListResultBean<MstRelation> MyParameterizedMethod(String p1, int p2, Boolean... params) {}
Expand Down

0 comments on commit c6ecbb0

Please sign in to comment.