1
0
Fork 0
mirror of synced 2024-11-24 01:35:35 -05:00
ultimate-vim/sources_non_forked/vim-snippets/UltiSnips/java.snippets

437 lines
7.8 KiB
Text
Raw Normal View History

priority -50
2012-08-16 23:41:25 -04:00
# Many of the snippets here use a global option called
# "g:ultisnips_java_brace_style" which, if set to "nl" will put a newline
# before '{' braces.
# Setting "g:ultisnips_java_junit" will change how the test method snippet
# looks, it is defaulted to junit4, setting this option to 3 will remove the
# @Test annotation from the method
2012-08-16 23:41:25 -04:00
global !p
def junit(snip):
if snip.opt("g:ultisnips_java_junit", "") == "3":
snip += ""
else:
snip.rv += "@Test\n\t"
2012-08-16 23:41:25 -04:00
def nl(snip):
if snip.opt("g:ultisnips_java_brace_style", "") == "nl":
snip += ""
else:
snip.rv += " "
def getArgs(group):
import re
word = re.compile('[a-zA-Z><.]+ \w+')
return [i.split(" ") for i in word.findall(group) ]
def camel(word):
2014-04-18 08:58:02 -04:00
if not word: return ''
return word[0].upper() + word[1:]
2014-04-18 08:58:02 -04:00
def mixedCase(word):
if not word: return ''
return word[0].lower() + word[1:]
2012-08-16 23:41:25 -04:00
endglobal
snippet sleep "try sleep catch" b
try {
Thread.sleep(${1:1000});
} catch (InterruptedException e){
e.printStackTrace();
}
endsnippet
snippet /i|n/ "new primitive or int" br
${1:int} ${2:i} = ${3:1};
$0
endsnippet
snippet /o|v/ "new Object or variable" br
${1:Object} ${2:var} = new $1(${3});
endsnippet
snippet f "field" b
${1:private} ${2:String} ${3:`!p snip.rv = t[2].lower()`};
endsnippet
2012-08-16 23:41:25 -04:00
snippet ab "abstract" b
abstract $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet as "assert" b
2014-07-02 07:18:18 -04:00
assert ${1:test}${2/(.+)/(?1: \: ")/}${2:Failure message}${2/(.+)/(?1:")/};
2012-08-16 23:41:25 -04:00
endsnippet
snippet at "assert true" b
assertTrue(${1:actual});
endsnippet
snippet af "assert false" b
2014-07-02 07:18:18 -04:00
assertFalse(${1:actual});
endsnippet
snippet ae "assert equals" b
assertEquals(${1:expected}, ${2:actual});
endsnippet
2012-08-16 23:41:25 -04:00
snippet br "break"
break;
endsnippet
snippet cs "case" b
case $1:
$2
$0
endsnippet
snippet ca "catch" b
catch (${1:Exception} ${2:e})`!p nl(snip)`{
$0
}
endsnippet
snippet cle "class extends" b
public class ${1:`!p
2012-08-16 23:41:25 -04:00
snip.rv = snip.basename or "untitled"`} ${2:extends ${3:Parent} }${4:implements ${5:Interface} }{
$0
}
endsnippet
snippet clc "class with constructor, fields, setter and getters" b
public class `!p
snip.rv = snip.basename or "untitled"` {
`!p
args = getArgs(t[1])
if len(args) == 0: snip.rv = ""
for i in args:
snip.rv += "\n\tprivate " + i[0] + " " + i[1]+ ";"
if len(args) > 0:
snip.rv += "\n"`
public `!p snip.rv = snip.basename or "unknown"`($1) { `!p
args = getArgs(t[1])
for i in args:
snip.rv += "\n\t\tthis." + i[1] + " = " + i[1] + ";"
if len(args) == 0:
snip.rv += "\n"`
}$0
`!p
args = getArgs(t[1])
if len(args) == 0: snip.rv = ""
for i in args:
snip.rv += "\n\tpublic void set" + camel(i[1]) + "(" + i[0] + " " + i[1] + ") {\n" + "\
\tthis." + i[1] + " = " + i[1] + ";\n\t}\n"
snip.rv += "\n\tpublic " + i[0] + " get" + camel(i[1]) + "() {\
\n\t\treturn " + i[1] + ";\n\t}\n"
`
}
endsnippet
snippet clc "class with constructor, with field names" b
public class `!p
snip.rv = snip.basename or "untitled"` {
`!p
args = getArgs(t[1])
for i in args:
snip.rv += "\n\tprivate " + i[0] + " " + i[1]+ ";"
if len(args) > 0:
snip.rv += "\n"`
public `!p snip.rv = snip.basename or "unknown"`($1) { `!p
args = getArgs(t[1])
for i in args:
2014-07-02 07:18:18 -04:00
snip.rv += "\n\t\tthis.%s = %s;" % (i[1], i[1])
if len(args) == 0:
snip.rv += "\n"`
}
}
endsnippet
snippet clc "class and constructor" b
public class `!p
snip.rv = snip.basename or "untitled"` {
public `!p snip.rv = snip.basename or "untitled"`($2) {
$0
}
}
endsnippet
snippet cl "class" b
public class ${1:`!p
snip.rv = snip.basename or "untitled"`} {
$0
}
endsnippet
2012-08-16 23:41:25 -04:00
snippet cos "constant string" b
public static final String ${1:var} = "$2";$0
2012-08-16 23:41:25 -04:00
endsnippet
snippet co "constant" b
public static final ${1:String} ${2:var} = $3;$0
2012-08-16 23:41:25 -04:00
endsnippet
snippet de "default" b
default:
$0
endsnippet
2014-04-18 08:58:02 -04:00
snippet elif "else if"
2012-08-16 23:41:25 -04:00
else if ($1)`!p nl(snip)`{
2014-09-27 11:32:18 -04:00
$0${VISUAL}
2012-08-16 23:41:25 -04:00
}
endsnippet
2014-08-03 18:02:51 -04:00
snippet el "else" w
2012-08-16 23:41:25 -04:00
else`!p nl(snip)`{
2014-09-27 11:32:18 -04:00
$0${VISUAL}
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet fi "final" b
final $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet fore "for (each)" b
for ($1 : $2)`!p nl(snip)`{
$0
}
endsnippet
snippet fori "for" b
for (int ${1:i} = 0; $1 < ${2:10}; $1++)`!p nl(snip)`{
$0
}
endsnippet
2012-08-16 23:41:25 -04:00
snippet for "for" b
for ($1; $2; $3)`!p nl(snip)`{
$0
}
endsnippet
snippet if "if" b
if ($1)`!p nl(snip)`{
2014-09-27 11:32:18 -04:00
$0${VISUAL}
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet imt "import junit_framework_TestCase;" b
import junit.framework.TestCase;
$0
endsnippet
snippet im "import" b
2014-07-02 07:18:18 -04:00
import ${1:java}.${2:util}.$0;
2012-08-16 23:41:25 -04:00
endsnippet
snippet in "interface" b
interface ${1:`!p snip.rv = snip.basename or "untitled"`} ${2:extends ${3:Parent} }{
$0
}
endsnippet
snippet cc "constructor call or setter body"
this.${1:var} = $1;
endsnippet
snippet list "Collections List" b
List<${1:String}> ${2:list} = new ${3:Array}List<$1>();
endsnippet
snippet map "Collections Map" b
Map<${1:String}, ${2:String}> ${3:map} = new ${4:Hash}Map<$1, $2>();
endsnippet
snippet set "Collections Set" b
Set<${1:String}> ${2:set} = new ${3:Hash}Set<$1>();
endsnippet
snippet /Str?|str/ "String" br
String $0
endsnippet
snippet cn "Constructor" b
public `!p snip.rv = snip.basename or "untitled"`(${1:}) {
$0
}
endsnippet
snippet cn "constructor, \w fields + assigments" b
`!p
args = getArgs(t[1])
for i in args:
snip.rv += "\n\tprivate " + i[0] + " " + i[1]+ ";"
if len(args) > 0:
snip.rv += "\n"`
public `!p snip.rv = snip.basename or "unknown"`($1) { `!p
args = getArgs(t[1])
for i in args:
2014-07-02 07:18:18 -04:00
snip.rv += "\n\t\tthis.%s = %s;" % (i[1], i[1])
if len(args) == 0:
snip.rv += "\n"`
}
endsnippet
2012-08-16 23:41:25 -04:00
snippet j.b "java_beans_" i
java.beans.
endsnippet
snippet j.i "java_io" i
java.io.
endsnippet
snippet j.m "java_math" i
java.math.
endsnippet
snippet j.n "java_net_" i
java.net.
endsnippet
snippet j.u "java_util_" i
java.util.
endsnippet
snippet main "method (main)" b
public static void main(String[] args)`!p nl(snip)`{
$0
}
endsnippet
snippet try "try/catch" b
try {
2014-09-27 11:32:18 -04:00
$1${VISUAL}
} catch(${2:Exception} ${3:e}){
${4:e.printStackTrace();}
}
endsnippet
snippet mt "method throws" b
${1:private} ${2:void} ${3:method}(${4}) ${5:throws $6 }{
$0
}
endsnippet
snippet m "method" b
${1:private} ${2:void} ${3:method}(${4}) {
$0
}
endsnippet
snippet md "Method With javadoc" b
/**
* ${7:Short Description}`!p
for i in getArgs(t[4]):
snip.rv += "\n\t * @param " + i[1] + " usage..."`
* `!p
if "throws" in t[5]:
snip.rv = "\n\t * @throws " + t[6]
else:
snip.rv = ""` `!p
if not "void" in t[2]:
snip.rv = "\n\t * @return object"
else:
snip.rv = ""`
**/
${1:public} ${2:void} ${3:method}($4) ${5:throws $6 }{
2012-08-16 23:41:25 -04:00
$0
}
endsnippet
snippet /get(ter)?/ "getter" br
public ${1:String} get${2:Name}() {
2014-04-18 08:58:02 -04:00
return `!p snip.rv = mixedCase(t[2])`;
}
endsnippet
snippet /set(ter)?/ "setter" br
2014-04-18 08:58:02 -04:00
public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) {
this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`;
}
endsnippet
2012-08-16 23:41:25 -04:00
snippet /se?tge?t|ge?tse?t|gs/ "setter and getter" br
2014-04-18 08:58:02 -04:00
public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) {
this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`;
}
public $2 get$1() {
2014-04-18 08:58:02 -04:00
return `!p snip.rv = mixedCase(t[1])`;
}
2012-08-16 23:41:25 -04:00
endsnippet
snippet pa "package" b
package $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet p "print" b
System.out.print($1);$0
endsnippet
snippet pl "println" b
System.out.println($1);$0
endsnippet
snippet pr "private" b
private $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet po "protected" b
protected $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet pu "public" b
public $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet re "return" b
return $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet st "static"
static $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet sw "switch" b
switch ($1)`!p nl(snip)`{
case $2: $0
2012-08-16 23:41:25 -04:00
}
endsnippet
snippet sy "synchronized"
synchronized $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet tc "test case"
public class ${1:`!p snip.rv = snip.basename or "untitled"`} extends ${2:TestCase}`!p nl(snip)`{
$0
}
endsnippet
snippet t "test" b
`!p junit(snip)`public void test${1:Name}() {
2012-08-16 23:41:25 -04:00
$0
}
endsnippet
snippet tt "test throws" b
`!p junit(snip)`public void test${1:Name}() ${2:throws Exception }{
$0
}
2012-08-16 23:41:25 -04:00
endsnippet
snippet th "throw" b
throw new $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet wh "while" b
while ($1)`!p nl(snip)`{
$0
}
endsnippet
# vim:ft=snippets: