Skip to content

Commit ea42c16

Browse files
committed
Add support generate methods
1 parent b1b9e3d commit ea42c16

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

autoload/javaunit.vim

+30-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif
2020
let s:JavaUnit_TestMethod_Source =
2121
\g:JavaUnit_Home
2222
\.s:Fsep
23-
\.join(['src','com','wsdjeg','util','TestMethod.java'],s:Fsep)
23+
\.join(['src' , 'com' , 'wsdjeg' , 'util' , '*.java'],s:Fsep)
2424

2525
function! javaunit#Compile() abort
2626
silent exec '!javac -encoding utf8 -d "'.s:JavaUnit_tempdir.'" "'.s:JavaUnit_TestMethod_Source .'"'
@@ -176,5 +176,34 @@ function! javaunit#TestMain(...) abort
176176
endif
177177
call javaunit#util#ExecCMD(cmd)
178178
endfunction
179+
180+
fu! javaunit#GenerateTestMethods()
181+
let testClassName = expand('%:t:r')
182+
if stridx(testClassName, 'test') != -1 || stridx(testClassName, 'Test') != -1
183+
let line = getline(search("package","nb",getline("0$")))
184+
let testClassName = split(split(line," ")[1],";")[0]."." . testClassName
185+
if stridx(testClassName, 'Test') == len(testClassName) - 4
186+
let className = strpart(testClassName, 0,len(testClassName) - 4)
187+
echomsg testClassName
188+
echomsg className
189+
let cmd="java -cp '"
190+
\.s:JavaUnit_tempdir
191+
\.s:Psep
192+
\.getcwd()
193+
\.join(['','target','test-classes'],s:Fsep)
194+
\.s:Psep
195+
\.get(g:,'JavaComplete_LibsPath','.')
196+
\."' com.wsdjeg.util.GenerateMethod "
197+
\.className
198+
echomsg system(cmd)
199+
else
200+
echohl WarningMsg | echomsg "This is not a testClassName,now only support className end with 'Test'" | echohl None
201+
endif
202+
else
203+
echohl WarningMsg | echomsg "This is not a testClassName" | echohl None
204+
endif
205+
endf
206+
207+
179208
let &cpo = s:save_cpo
180209
unlet s:save_cpo

plugin/javaunit.vim

+4
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ command! -nargs=0
3535
\ JavaUnitServerCompile
3636
\ call javaunit#Compile()
3737

38+
command! -nargs=0
39+
\ JUGenerateM
40+
\ call javaunit#GenerateTestMethods()
41+
3842
let &cpo = s:save_cpo
3943
unlet s:save_cpo
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.wsdjeg.util;
2+
3+
import java.lang.reflect.Method;
4+
5+
public class GenerateMethod {
6+
public static void main(String[] args) {
7+
System.out.println(listMethos(args[0]));
8+
}
9+
private static String listMethos(String name){
10+
Class<?> clazz = null;
11+
try {
12+
clazz = Class.forName(name);
13+
} catch(Exception e){
14+
e.printStackTrace();
15+
}
16+
Method[] mds = clazz.getDeclaredMethods();
17+
String result = "";
18+
for (int i = 0; i < mds.length; i++) {
19+
if (result.length()>0) {
20+
result = result + "|" +mds[0].getName();
21+
}else{
22+
result = mds[0].getName();
23+
}
24+
}
25+
return result;
26+
}
27+
}
28+

0 commit comments

Comments
 (0)