From e5d98a60b121f4a37ab09ac43bcbc4ad41e35178 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 11:28:36 +1000 Subject: [PATCH 01/13] feat: add common java snippets for functions and templates Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- extension.toml | 1 + snippets.json | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 snippets.json diff --git a/extension.toml b/extension.toml index a3f8248..4918fa2 100644 --- a/extension.toml +++ b/extension.toml @@ -9,6 +9,7 @@ authors = [ ] description = "Java support." repository = "https://github.com/zed-extensions/java" +snippets = "snippets.json" [grammars.java] repository = "https://github.com/tree-sitter/tree-sitter-java" diff --git a/snippets.json b/snippets.json new file mode 100644 index 0000000..158a2d0 --- /dev/null +++ b/snippets.json @@ -0,0 +1,85 @@ +{ + "Package declaration": { + "prefix": "jpkg", + "body": ["package ${1:com.example};", ""], + "description": "Insert a package declaration." + }, + "Import block": { + "prefix": "jimp", + "body": ["import ${1:java.util.*};", ""], + "description": "Insert an import statement." + }, + "Class skeleton": { + "prefix": "jclass", + "body": ["public class ${1:ClassName} {", " $0", "}", ""], + "description": "Public class skeleton." + }, + "Class + main": { + "prefix": "jmain", + "body": [ + "public class ${1:Main} {", + " public static void main(String[] args) {", + " $0", + " }", + "}", + "" + ], + "description": "Class with a main method." + }, + "Method (public)": { + "prefix": "jpubm", + "body": [ + "public ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Public method template." + }, + "Method (private)": { + "prefix": "jprim", + "body": [ + "private ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Private method template." + }, + "Constructor": { + "prefix": "jctor", + "body": [ + "public ${1:ClassName}(${2:Type arg}) {", + " this.${3:field} = ${2:arg};", + " $0", + "}", + "" + ], + "description": "Constructor template." + }, + "Field (private final)": { + "prefix": "jpf", + "body": ["private final ${1:Type} ${2:name};", ""], + "description": "Private final field." + }, + "Getter": { + "prefix": "jget", + "body": [ + "public ${1:Type} get${2:Name}() {", + " return ${3:field};", + "}", + "" + ], + "description": "Getter method." + }, + "Setter": { + "prefix": "jset", + "body": [ + "public void set${1:Name}(${2:Type} ${3:value}) {", + " this.${4:field} = ${3:value};", + "}", + "" + ], + "description": "Setter method." + } +} From b69c536b41ce9bcfc63d12ae6a53442f4108fe28 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 13:56:55 +1000 Subject: [PATCH 02/13] feat: added snippets for commonly used functions Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 113 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 81 insertions(+), 32 deletions(-) diff --git a/snippets.json b/snippets.json index 158a2d0..77e303a 100644 --- a/snippets.json +++ b/snippets.json @@ -1,68 +1,117 @@ { - "Package declaration": { + "package": { "prefix": "jpkg", - "body": ["package ${1:com.example};", ""], - "description": "Insert a package declaration." + "body": ["package ${1:com.example};", "", "$0"], + "description": "Package declaration." }, - "Import block": { + "import": { "prefix": "jimp", - "body": ["import ${1:java.util.*};", ""], - "description": "Insert an import statement." + "body": ["import ${1:java.util.*};", "$0"], + "description": "Import statement." }, - "Class skeleton": { + "static import": { + "prefix": "jimps", + "body": ["import static ${1:org.junit.jupiter.api.Assertions}.*;", "$0"], + "description": "Static import statement." + }, + + "class": { "prefix": "jclass", "body": ["public class ${1:ClassName} {", " $0", "}", ""], "description": "Public class skeleton." }, - "Class + main": { - "prefix": "jmain", + "final class": { + "prefix": "jfclass", + "body": ["public final class ${1:ClassName} {", " $0", "}", ""], + "description": "Final class skeleton." + }, + "abstract class": { + "prefix": "jabs", + "body": ["public abstract class ${1:AbstractName} {", " $0", "}", ""], + "description": "Abstract class skeleton." + }, + "interface": { + "prefix": "jint", + "body": ["public interface ${1:MyInterface} {", " $0", "}", ""], + "description": "Interface skeleton." + }, + "enum": { + "prefix": "jenum", + "body": ["public enum ${1:MyEnum} {", " ${2:VALUE};", " $0", "}", ""], + "description": "Enum skeleton." + }, + "record (Java 16+)": { + "prefix": "jrec", + "body": ["public record ${1:Name}(${2:Type field}) {", " $0", "}", ""], + "description": "Record skeleton." + }, + "sealed interface (Java 17+)": { + "prefix": "jsealedint", "body": [ - "public class ${1:Main} {", - " public static void main(String[] args) {", - " $0", - " }", + "public sealed interface ${1:Shape} permits ${2:Circle}, ${3:Square} {", + " $0", "}", "" ], - "description": "Class with a main method." + "description": "Sealed interface skeleton." }, - "Method (public)": { - "prefix": "jpubm", + "sealed class (Java 17+)": { + "prefix": "jsealedclass", "body": [ - "public ${1:void} ${2:methodName}(${3:Type arg}) {", + "public sealed class ${1:Base} permits ${2:ChildA}, ${3:ChildB} {", " $0", "}", "" ], - "description": "Public method template." + "description": "Sealed class skeleton." }, - "Method (private)": { - "prefix": "jprim", + + "class + main": { + "prefix": "jmain", "body": [ - "private ${1:void} ${2:methodName}(${3:Type arg}) {", - " $0", + "public class ${1:Main} {", + " public static void main(String[] args) {", + " $0", + " }", "}", "" ], - "description": "Private method template." + "description": "Class with main method." + }, + "private field": { + "prefix": "jpf", + "body": ["private ${1:Type} ${2:name};", "$0"], + "description": "Private field." + }, + "private final field": { + "prefix": "jpff", + "body": ["private final ${1:Type} ${2:name};", "$0"], + "description": "Private final field." }, - "Constructor": { + "public static final constant": { + "prefix": "jconst", + "body": ["public static final ${1:Type} ${2:NAME} = ${3:value};", "$0"], + "description": "Constant declaration." + }, + + "constructor": { "prefix": "jctor", "body": [ - "public ${1:ClassName}(${2:Type arg}) {", - " this.${3:field} = ${2:arg};", + "public ${1:ClassName}(${2:Type ${3:arg}}) {", + " this.${4:field} = ${3:arg};", " $0", "}", "" ], "description": "Constructor template." }, - "Field (private final)": { - "prefix": "jpf", - "body": ["private final ${1:Type} ${2:name};", ""], - "description": "Private final field." + "no-args constructor": { + "prefix": "jctor0", + "body": ["public ${1:ClassName}() {", " $0", "}", ""], + "description": "No-args constructor." }, - "Getter": { + + "getter": { "prefix": "jget", "body": [ "public ${1:Type} get${2:Name}() {", @@ -72,7 +121,7 @@ ], "description": "Getter method." }, - "Setter": { + "setter": { "prefix": "jset", "body": [ "public void set${1:Name}(${2:Type} ${3:value}) {", From 5e909d4e75de95b1885e7692a28be708df41ff6c Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 13:59:04 +1000 Subject: [PATCH 03/13] feat: added snippets for common function patterns Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/snippets.json b/snippets.json index 77e303a..bcc4b22 100644 --- a/snippets.json +++ b/snippets.json @@ -130,5 +130,90 @@ "" ], "description": "Setter method." + }, + "method (public)": { + "prefix": "jpubm", + "body": [ + "public ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Public method template." + }, + "method (private)": { + "prefix": "jprim", + "body": [ + "private ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Private method template." + }, + "static method": { + "prefix": "jstaticm", + "body": [ + "public static ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Static method template." + }, + "generic method": { + "prefix": "jgenm", + "body": [ + "public static <${1:T}> ${1:T} ${2:methodName}(${1:T} ${3:value}) {", + " return ${3:value};", + "}", + "" + ], + "description": "Generic method template." + }, + + "override method": { + "prefix": "joverride", + "body": [ + "@Override", + "public ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "@Override method template." + }, + + "equals/hashCode (Objects)": { + "prefix": "jeqh", + "body": [ + "@Override", + "public boolean equals(Object o) {", + " if (this == o) return true;", + " if (o == null || getClass() != o.getClass()) return false;", + " ${1:ClassName} that = (${1:ClassName}) o;", + " return java.util.Objects.equals(${2:field}, that.${2:field});", + "}", + "", + "@Override", + "public int hashCode() {", + " return java.util.Objects.hash(${2:field});", + "}", + "" + ], + "description": "equals/hashCode using java.util.Objects." + }, + "toString": { + "prefix": "jts", + "body": [ + "@Override", + "public String toString() {", + " return \"${1:ClassName}{\" +", + " \"${2:field}=\" + ${2:field} +", + " '}';", + "}", + "" + ], + "description": "toString template." } } From f3bd73e9447f259b69ca177e5ab058886577adbd Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:00:55 +1000 Subject: [PATCH 04/13] feat: added snippets for common expressions Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/snippets.json b/snippets.json index bcc4b22..0786617 100644 --- a/snippets.json +++ b/snippets.json @@ -215,5 +215,167 @@ "" ], "description": "toString template." + }, + "System.out.println": { + "prefix": "sout", + "body": ["System.out.println(${1:msg});", "$0"], + "description": "Print to stdout." + }, + "System.err.println": { + "prefix": "serr", + "body": ["System.err.println(${1:msg});", "$0"], + "description": "Print to stderr." + }, + + "Javadoc (method)": { + "prefix": "jdoc", + "body": [ + "/**", + " * ${1:Summary}", + " *", + " * @param ${2:param} ${3:description}", + " * @return ${4:description}", + " */", + "$0" + ], + "description": "Javadoc template." + }, + "TODO": { + "prefix": "todo", + "body": ["// TODO(${1:you}): ${2:what}", "$0"], + "description": "TODO comment." + }, + + "if": { + "prefix": "jif", + "body": ["if (${1:condition}) {", " $0", "}"], + "description": "If statement." + }, + "if/else": { + "prefix": "jife", + "body": ["if (${1:condition}) {", " ${2:// ...}", "} else {", " $0", "}"], + "description": "If/else statement." + }, + "switch statement": { + "prefix": "jswitch", + "body": [ + "switch (${1:expr}) {", + " case ${2:VALUE}:", + " $0", + " break;", + " default:", + " break;", + "}" + ], + "description": "Switch statement." + }, + "switch expression (Java 14+)": { + "prefix": "jswitchx", + "body": [ + "${1:var} = switch (${2:expr}) {", + " case ${3:VALUE} -> ${4:result};", + " default -> ${5:result};", + "};", + "$0" + ], + "description": "Switch expression." + }, + + "for (index)": { + "prefix": "jfor", + "body": ["for (int ${1:i} = 0; ${1:i} < ${2:n}; ${1:i}++) {", " $0", "}"], + "description": "Indexed for loop." + }, + "foreach": { + "prefix": "jforeach", + "body": ["for (${1:Type} ${2:item} : ${3:items}) {", " $0", "}"], + "description": "Enhanced for loop." + }, + "while": { + "prefix": "jwhile", + "body": ["while (${1:condition}) {", " $0", "}"], + "description": "While loop." + }, + "do/while": { + "prefix": "jdowhile", + "body": ["do {", " $0", "} while (${1:condition});"], + "description": "Do/while loop." + }, + + "requireNonNull": { + "prefix": "jnonn", + "body": [ + "java.util.Objects.requireNonNull(${1:obj}, \"${2:message}\");", + "$0" + ], + "description": "Objects.requireNonNull guard." + }, + "null guard return": { + "prefix": "jngret", + "body": ["if (${1:obj} == null) {", " return ${2:null};", "}", "$0"], + "description": "Null guard with return." + }, + "null guard throw": { + "prefix": "jngthrow", + "body": [ + "if (${1:obj} == null) {", + " throw new ${2:IllegalArgumentException}(\"${3:message}\");", + "}", + "$0" + ], + "description": "Null guard with throw." + }, + + "try/catch": { + "prefix": "jtry", + "body": [ + "try {", + " $0", + "} catch (${1:Exception} e) {", + " ${2:e.printStackTrace();}", + "}" + ], + "description": "try/catch block." + }, + "try/catch/finally": { + "prefix": "jtryf", + "body": [ + "try {", + " $0", + "} catch (${1:Exception} e) {", + " ${2:e.printStackTrace();}", + "} finally {", + " ${3:// cleanup}", + "}" + ], + "description": "try/catch/finally block." + }, + "try-with-resources": { + "prefix": "jtryr", + "body": [ + "try (${1:var} ${2:resource} = ${3:initializer}) {", + " $0", + "} catch (${4:Exception} e) {", + " ${5:e.printStackTrace();}", + "}" + ], + "description": "Try-with-resources." + }, + + "custom exception": { + "prefix": "jex", + "body": [ + "public class ${1:MyException} extends RuntimeException {", + " public ${1:MyException}(String message) {", + " super(message);", + " }", + "", + " public ${1:MyException}(String message, Throwable cause) {", + " super(message, cause);", + " }", + "}", + "" + ], + "description": "Custom RuntimeException." } } From 97302c88116b5dbd30b9da3c4fd080e5b8f21034 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:02:01 +1000 Subject: [PATCH 05/13] feat: added snippets for common Data structure expressions with logging extra Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/snippets.json b/snippets.json index 0786617..5f6d7ba 100644 --- a/snippets.json +++ b/snippets.json @@ -377,5 +377,107 @@ "" ], "description": "Custom RuntimeException." + }, + "List declaration": { + "prefix": "jlist", + "body": [ + "java.util.List<${1:Type}> ${2:list} = new java.util.ArrayList<>();", + "$0" + ], + "description": "New ArrayList." + }, + "Set declaration": { + "prefix": "jset", + "body": [ + "java.util.Set<${1:Type}> ${2:set} = new java.util.HashSet<>();", + "$0" + ], + "description": "New HashSet." + }, + "Map declaration": { + "prefix": "jmap", + "body": [ + "java.util.Map<${1:K}, ${2:V}> ${3:map} = new java.util.HashMap<>();", + "$0" + ], + "description": "New HashMap." + }, + + "Stream filter/map/toList": { + "prefix": "jstream", + "body": [ + "${1:list}.stream()", + " .filter(${2:x} -> ${3:predicate})", + " .map(${2:x} -> ${4:transform})", + " .toList();", + "$0" + ], + "description": "Stream pipeline (Java 16+ toList)." + }, + "Collectors.toList": { + "prefix": "jcolist", + "body": [ + "${1:stream}.collect(java.util.stream.Collectors.toList());", + "$0" + ], + "description": "Collect stream to list." + }, + "Collectors.toMap": { + "prefix": "jcomap", + "body": [ + "${1:stream}.collect(java.util.stream.Collectors.toMap(", + " ${2:x} -> ${3:key},", + " ${2:x} -> ${4:value}", + "));", + "$0" + ], + "description": "Collect stream to map." + }, + "Comparator.comparing": { + "prefix": "jcomp", + "body": ["java.util.Comparator.comparing(${1:Type}::${2:getField})", "$0"], + "description": "Comparator.comparing reference." + }, + + "Optional.ofNullable": { + "prefix": "jopt", + "body": [ + "java.util.Optional.ofNullable(${1:value})", + " .orElse(${2:defaultValue});", + "$0" + ], + "description": "Optional.ofNullable(...).orElse(...)." + }, + "Optional.orElseThrow": { + "prefix": "joptx", + "body": [ + "${1:optional}.orElseThrow(() -> new ${2:IllegalStateException}(\"${3:message}\"));", + "$0" + ], + "description": "Optional.orElseThrow with custom exception." + }, + + "logger (SLF4J)": { + "prefix": "jlog", + "body": [ + "private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(${1:ClassName}.class);", + "$0" + ], + "description": "SLF4J logger field." + }, + "log.info": { + "prefix": "jinfo", + "body": ["log.info(\"${1:message}: {}\", ${2:value});", "$0"], + "description": "log.info with placeholder." + }, + "log.warn": { + "prefix": "jwarn", + "body": ["log.warn(\"${1:message}: {}\", ${2:value});", "$0"], + "description": "log.warn with placeholder." + }, + "log.error (with throwable)": { + "prefix": "jerr", + "body": ["log.error(\"${1:message}\", ${2:throwable});", "$0"], + "description": "log.error with throwable." } } From de4bb3ad9231a0f23b816b55ec27fe34efbf52f0 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:03:04 +1000 Subject: [PATCH 06/13] feat: added snippets for parllelism and file handling Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/snippets.json b/snippets.json index 5f6d7ba..7169b19 100644 --- a/snippets.json +++ b/snippets.json @@ -479,5 +479,93 @@ "prefix": "jerr", "body": ["log.error(\"${1:message}\", ${2:throwable});", "$0"], "description": "log.error with throwable." + }, + "Java: Thread (lambda)": { + "prefix": "jthread", + "body": ["new Thread(() -> {", " $0", "}).start();"], + "description": "Start a Thread with lambda." + }, + "Java: Runnable": { + "prefix": "jrunnable", + "body": ["Runnable ${1:task} = () -> {", " $0", "};"], + "description": "Runnable lambda." + }, + "Java: Callable": { + "prefix": "jcallable", + "body": [ + "java.util.concurrent.Callable<${1:T}> ${2:task} = () -> {", + " return $0;", + "};" + ], + "description": "Callable lambda." + }, + "Java: ExecutorService (fixed pool)": { + "prefix": "jexec", + "body": [ + "java.util.concurrent.ExecutorService ${1:pool} = java.util.concurrent.Executors.newFixedThreadPool(${2:nThreads});", + "try {", + " $0", + "} finally {", + " ${1:pool}.shutdown();", + "}" + ], + "description": "ExecutorService fixed thread pool." + }, + "Java: CompletableFuture.supplyAsync": { + "prefix": "jcf", + "body": [ + "java.util.concurrent.CompletableFuture<${1:T}> ${2:cf} = java.util.concurrent.CompletableFuture.supplyAsync(() -> {", + " return $0;", + "});" + ], + "description": "CompletableFuture.supplyAsync template." + }, + "Java: synchronized block": { + "prefix": "jsync", + "body": ["synchronized (${1:lock}) {", " $0", "}"], + "description": "Synchronized block." + }, + "Java: ReentrantLock": { + "prefix": "jlock", + "body": [ + "java.util.concurrent.locks.Lock ${1:lock} = new java.util.concurrent.locks.ReentrantLock();", + "${1:lock}.lock();", + "try {", + " $0", + "} finally {", + " ${1:lock}.unlock();", + "}" + ], + "description": "ReentrantLock with try/finally." + }, + + "Java: Path.of": { + "prefix": "jpath", + "body": [ + "java.nio.file.Path ${1:path} = java.nio.file.Path.of(${2:\"file.txt\"});", + "$0" + ], + "description": "Create a Path." + }, + "Java: Files.readString": { + "prefix": "jreadstr", + "body": [ + "String ${1:text} = java.nio.file.Files.readString(${2:path});", + "$0" + ], + "description": "Read file contents as String." + }, + "Java: Files.readAllLines": { + "prefix": "jreadlines", + "body": [ + "java.util.List ${1:lines} = java.nio.file.Files.readAllLines(${2:path});", + "$0" + ], + "description": "Read all lines into List." + }, + "Java: Files.writeString": { + "prefix": "jwritestr", + "body": ["java.nio.file.Files.writeString(${1:path}, ${2:text});", "$0"], + "description": "Write String to file." } } From c646c10eb17a782b6333784db815afe8b684fa97 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:07:01 +1000 Subject: [PATCH 07/13] feat: added snippets for common libraries, testing, mocking Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 224 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 213 insertions(+), 11 deletions(-) diff --git a/snippets.json b/snippets.json index 7169b19..dbf5269 100644 --- a/snippets.json +++ b/snippets.json @@ -480,17 +480,17 @@ "body": ["log.error(\"${1:message}\", ${2:throwable});", "$0"], "description": "log.error with throwable." }, - "Java: Thread (lambda)": { + "Thread (lambda)": { "prefix": "jthread", "body": ["new Thread(() -> {", " $0", "}).start();"], "description": "Start a Thread with lambda." }, - "Java: Runnable": { + "Runnable": { "prefix": "jrunnable", "body": ["Runnable ${1:task} = () -> {", " $0", "};"], "description": "Runnable lambda." }, - "Java: Callable": { + "Callable": { "prefix": "jcallable", "body": [ "java.util.concurrent.Callable<${1:T}> ${2:task} = () -> {", @@ -499,7 +499,7 @@ ], "description": "Callable lambda." }, - "Java: ExecutorService (fixed pool)": { + "ExecutorService (fixed pool)": { "prefix": "jexec", "body": [ "java.util.concurrent.ExecutorService ${1:pool} = java.util.concurrent.Executors.newFixedThreadPool(${2:nThreads});", @@ -511,7 +511,7 @@ ], "description": "ExecutorService fixed thread pool." }, - "Java: CompletableFuture.supplyAsync": { + "CompletableFuture.supplyAsync": { "prefix": "jcf", "body": [ "java.util.concurrent.CompletableFuture<${1:T}> ${2:cf} = java.util.concurrent.CompletableFuture.supplyAsync(() -> {", @@ -520,12 +520,12 @@ ], "description": "CompletableFuture.supplyAsync template." }, - "Java: synchronized block": { + "synchronized block": { "prefix": "jsync", "body": ["synchronized (${1:lock}) {", " $0", "}"], "description": "Synchronized block." }, - "Java: ReentrantLock": { + "ReentrantLock": { "prefix": "jlock", "body": [ "java.util.concurrent.locks.Lock ${1:lock} = new java.util.concurrent.locks.ReentrantLock();", @@ -539,7 +539,7 @@ "description": "ReentrantLock with try/finally." }, - "Java: Path.of": { + "Path.of": { "prefix": "jpath", "body": [ "java.nio.file.Path ${1:path} = java.nio.file.Path.of(${2:\"file.txt\"});", @@ -547,7 +547,7 @@ ], "description": "Create a Path." }, - "Java: Files.readString": { + "Files.readString": { "prefix": "jreadstr", "body": [ "String ${1:text} = java.nio.file.Files.readString(${2:path});", @@ -555,7 +555,7 @@ ], "description": "Read file contents as String." }, - "Java: Files.readAllLines": { + "Files.readAllLines": { "prefix": "jreadlines", "body": [ "java.util.List ${1:lines} = java.nio.file.Files.readAllLines(${2:path});", @@ -563,9 +563,211 @@ ], "description": "Read all lines into List." }, - "Java: Files.writeString": { + "Files.writeString": { "prefix": "jwritestr", "body": ["java.nio.file.Files.writeString(${1:path}, ${2:text});", "$0"], "description": "Write String to file." + }, + "HttpClient GET (Java 11+)": { + "prefix": "jhttpget", + "body": [ + "java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();", + "java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()", + " .uri(java.net.URI.create(${1:\"https://example.com\"}))", + " .GET()", + " .build();", + "", + "java.net.http.HttpResponse response = client.send(", + " request,", + " java.net.http.HttpResponse.BodyHandlers.ofString()", + ");", + "", + "$0" + ], + "description": "HttpClient GET request." + }, + "Java: HttpClient POST JSON (Java 11+)": { + "prefix": "jhttppost", + "body": [ + "java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();", + "java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()", + " .uri(java.net.URI.create(${1:\"https://example.com\"}))", + " .header(\"Content-Type\", \"application/json\")", + " .POST(java.net.http.HttpRequest.BodyPublishers.ofString(${2:json}))", + " .build();", + "", + "java.net.http.HttpResponse response = client.send(", + " request,", + " java.net.http.HttpResponse.BodyHandlers.ofString()", + ");", + "", + "$0" + ], + "description": "HttpClient POST JSON request." + }, + + "Java: Jackson ObjectMapper": { + "prefix": "jjackson", + "body": [ + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", + "$0" + ], + "description": "Create Jackson ObjectMapper." + }, + "Java: Jackson readValue (class)": { + "prefix": "jreadjson", + "body": [ + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", + "${1:Type} ${2:value} = mapper.readValue(${3:json}, ${1:Type}.class);", + "$0" + ], + "description": "Jackson readValue into class." + }, + "Java: Jackson writeValueAsString": { + "prefix": "jwritejson", + "body": [ + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", + "String ${1:json} = mapper.writeValueAsString(${2:obj});", + "$0" + ], + "description": "Jackson write object to JSON string." + }, + + "JUnit5: test class": { + "prefix": "junit", + "body": [ + "import org.junit.jupiter.api.Test;", + "import static org.junit.jupiter.api.Assertions.*;", + "", + "class ${1:TestName} {", + " @Test", + " void ${2:shouldDoThing}() {", + " $0", + " }", + "}", + "" + ], + "description": "JUnit 5 test class + assertion imports." + }, + "JUnit5: @BeforeEach": { + "prefix": "jbefore", + "body": [ + "@org.junit.jupiter.api.BeforeEach", + "void setUp() {", + " $0", + "}", + "" + ], + "description": "JUnit5 @BeforeEach." + }, + "JUnit5: @AfterEach": { + "prefix": "jafter", + "body": [ + "@org.junit.jupiter.api.AfterEach", + "void tearDown() {", + " $0", + "}", + "" + ], + "description": "JUnit5 @AfterEach." + }, + "JUnit5: assertEquals": { + "prefix": "aeq", + "body": [ + "org.junit.jupiter.api.Assertions.assertEquals(${1:expected}, ${2:actual});", + "$0" + ], + "description": "Assertions.assertEquals." + }, + "JUnit5: assertThrows": { + "prefix": "athrows", + "body": [ + "org.junit.jupiter.api.Assertions.assertThrows(${1:ExceptionType}.class, () -> {", + " $0", + "});" + ], + "description": "Assertions.assertThrows." + }, + "JUnit5: parameterized @ValueSource": { + "prefix": "jparam", + "body": [ + "import org.junit.jupiter.params.ParameterizedTest;", + "import org.junit.jupiter.params.provider.ValueSource;", + "", + "@ParameterizedTest", + "@ValueSource(${1:ints} = { ${2:1}, ${3:2}, ${4:3} })", + "void ${5:shouldWork}(${6:int value}) {", + " $0", + "}", + "" + ], + "description": "JUnit5 parameterized test with ValueSource." + }, + "JUnit5: @Nested": { + "prefix": "jnested", + "body": [ + "@org.junit.jupiter.api.Nested", + "class ${1:WhenSomething} {", + " @org.junit.jupiter.api.Test", + " void ${2:shouldDoX}() {", + " $0", + " }", + "}", + "" + ], + "description": "JUnit5 nested test class." + }, + + "AssertJ: assertThat": { + "prefix": "aj", + "body": [ + "org.assertj.core.api.Assertions.assertThat(${1:actual}).${2:isEqualTo}(${3:expected});", + "$0" + ], + "description": "AssertJ assertThat." + }, + "AssertJ: assertThatThrownBy": { + "prefix": "ajthrow", + "body": [ + "org.assertj.core.api.Assertions.assertThatThrownBy(() -> {", + " $0", + "}).isInstanceOf(${1:ExceptionType}.class);" + ], + "description": "AssertJ assertThatThrownBy." + }, + + "Mockito: mock": { + "prefix": "mmock", + "body": [ + "${1:Type} ${2:mock} = org.mockito.Mockito.mock(${1:Type}.class);", + "$0" + ], + "description": "Create Mockito mock." + }, + "Mockito: when/thenReturn": { + "prefix": "mwhen", + "body": [ + "org.mockito.Mockito.when(${1:mock}.${2:method}(${3:args})).thenReturn(${4:value});", + "$0" + ], + "description": "Mockito stubbing." + }, + "Mockito: verify": { + "prefix": "mverify", + "body": [ + "org.mockito.Mockito.verify(${1:mock}).${2:method}(${3:args});", + "$0" + ], + "description": "Mockito verify call." + }, + "Mockito: ArgumentCaptor": { + "prefix": "mcap", + "body": [ + "org.mockito.ArgumentCaptor<${1:Type}> ${2:captor} = org.mockito.ArgumentCaptor.forClass(${1:Type}.class);", + "org.mockito.Mockito.verify(${3:mock}).${4:method}(${2:captor}.capture());", + "${1:Type} ${5:value} = ${2:captor}.getValue();", + "$0" + ], + "description": "Mockito ArgumentCaptor pattern." } } From ead4a70a024df272b2f34161ca42411cd726b964 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:08:19 +1000 Subject: [PATCH 08/13] feat: added snippets for spring, jakarta, lombok Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/snippets.json b/snippets.json index dbf5269..c15a809 100644 --- a/snippets.json +++ b/snippets.json @@ -769,5 +769,186 @@ "$0" ], "description": "Mockito ArgumentCaptor pattern." + }, + "Spring Boot: @SpringBootApplication main": { + "prefix": "sbapp", + "body": [ + "import org.springframework.boot.SpringApplication;", + "import org.springframework.boot.autoconfigure.SpringBootApplication;", + "", + "@SpringBootApplication", + "public class ${1:Application} {", + " public static void main(String[] args) {", + " SpringApplication.run(${1:Application}.class, args);", + " }", + "}", + "" + ], + "description": "Spring Boot application entry." + }, + "Spring: @RestController": { + "prefix": "sbrest", + "body": [ + "import org.springframework.web.bind.annotation.*;", + "", + "@RestController", + "@RequestMapping(\"/${1:resource}\")", + "public class ${2:Resource}Controller {", + " @GetMapping", + " public ${3:String} index() {", + " return ${4:\"ok\"};", + " }", + "", + " $0", + "}", + "" + ], + "description": "Spring REST controller skeleton." + }, + "Spring: @Service": { + "prefix": "sbservice", + "body": [ + "import org.springframework.stereotype.Service;", + "", + "@Service", + "public class ${1:ServiceName} {", + " $0", + "}", + "" + ], + "description": "Spring @Service skeleton." + }, + "Spring: @Repository": { + "prefix": "sbrepo", + "body": [ + "import org.springframework.stereotype.Repository;", + "", + "@Repository", + "public class ${1:RepositoryName} {", + " $0", + "}", + "" + ], + "description": "Spring @Repository skeleton." + }, + "Spring Data: CrudRepository": { + "prefix": "sbcrud", + "body": [ + "import org.springframework.data.repository.CrudRepository;", + "", + "public interface ${1:RepoName} extends CrudRepository<${2:Entity}, ${3:IdType}> {", + " $0", + "}", + "" + ], + "description": "Spring Data CrudRepository interface." + }, + "Spring: @ControllerAdvice (exception handler)": { + "prefix": "sbadvice", + "body": [ + "import org.springframework.http.*;", + "import org.springframework.web.bind.annotation.*;", + "", + "@ControllerAdvice", + "public class ${1:GlobalExceptionHandler} {", + " @ExceptionHandler(${2:ExceptionType}.class)", + " public ResponseEntity<${3:String}> handle(${2:ExceptionType} e) {", + " return ResponseEntity.status(HttpStatus.${4:BAD_REQUEST}).body(e.getMessage());", + " }", + "}", + "" + ], + "description": "Spring global exception handler." + }, + "JPA: @Entity": { + "prefix": "jpaentity", + "body": [ + "import jakarta.persistence.*;", + "", + "@Entity", + "@Table(name = \"${1:table_name}\")", + "public class ${2:EntityName} {", + " @Id", + " @GeneratedValue(strategy = GenerationType.IDENTITY)", + " private ${3:Long} id;", + "", + " $0", + "}", + "" + ], + "description": "JPA entity skeleton." + }, + "JPA: @Column": { + "prefix": "jpacol", + "body": [ + "@Column(name = \"${1:col}\", nullable = ${2:true})", + "private ${3:Type} ${4:field};", + "$0" + ], + "description": "JPA column field." + }, + "JPA: @ManyToOne": { + "prefix": "jpam2o", + "body": [ + "@ManyToOne(fetch = FetchType.LAZY)", + "@JoinColumn(name = \"${1:other_id}\")", + "private ${2:OtherEntity} ${3:other};", + "$0" + ], + "description": "JPA ManyToOne association." + }, + "JPA: @OneToMany": { + "prefix": "jpao2m", + "body": [ + "@OneToMany(mappedBy = \"${1:owner}\", cascade = CascadeType.ALL, orphanRemoval = true)", + "private java.util.List<${2:ChildEntity}> ${3:children} = new java.util.ArrayList<>();", + "$0" + ], + "description": "JPA OneToMany association." + }, + + "Jakarta Validation: @Valid + @NotNull": { + "prefix": "jvalid", + "body": [ + "import jakarta.validation.Valid;", + "import jakarta.validation.constraints.NotNull;", + "", + "public ${1:void} ${2:method}(@Valid @NotNull ${3:Type} ${4:req}) {", + " $0", + "}", + "" + ], + "description": "Validation annotations template." + }, + + "Lombok: @Data class": { + "prefix": "ldata", + "body": [ + "import lombok.Data;", + "", + "@Data", + "public class ${1:Dto} {", + " private ${2:Type} ${3:field};", + " $0", + "}", + "" + ], + "description": "Lombok @Data class." + }, + "Lombok: @Builder": { + "prefix": "lbuilder", + "body": [ + "import lombok.Builder;", + "import lombok.Value;", + "", + "@Value", + "@Builder", + "public class ${1:ValueType} {", + " ${2:Type} ${3:field};", + " $0", + "}", + "" + ], + "description": "Lombok immutable + builder." } } From c5732e1265c9c9211cae0364787e6c00b34997cb Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:09:35 +1000 Subject: [PATCH 09/13] feat: added snippets for common design patterns Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- extension.toml | 1 + snippets.json | 88 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/extension.toml b/extension.toml index 4918fa2..117b6e4 100644 --- a/extension.toml +++ b/extension.toml @@ -6,6 +6,7 @@ authors = [ "Valentine Briese ", "Samuser107 L.Longheval ", "Yury Abykhodau ", + "Keys <70819367+keys-i@users.noreply.github.com>" ] description = "Java support." repository = "https://github.com/zed-extensions/java" diff --git a/snippets.json b/snippets.json index c15a809..4cf8f32 100644 --- a/snippets.json +++ b/snippets.json @@ -586,7 +586,7 @@ ], "description": "HttpClient GET request." }, - "Java: HttpClient POST JSON (Java 11+)": { + " HttpClient POST JSON (Java 11+)": { "prefix": "jhttppost", "body": [ "java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();", @@ -606,7 +606,7 @@ "description": "HttpClient POST JSON request." }, - "Java: Jackson ObjectMapper": { + " Jackson ObjectMapper": { "prefix": "jjackson", "body": [ "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", @@ -614,7 +614,7 @@ ], "description": "Create Jackson ObjectMapper." }, - "Java: Jackson readValue (class)": { + " Jackson readValue (class)": { "prefix": "jreadjson", "body": [ "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", @@ -623,7 +623,7 @@ ], "description": "Jackson readValue into class." }, - "Java: Jackson writeValueAsString": { + " Jackson writeValueAsString": { "prefix": "jwritejson", "body": [ "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", @@ -950,5 +950,85 @@ "" ], "description": "Lombok immutable + builder." + }, + "Pattern: Builder (manual)": { + "prefix": "jbuilder", + "body": [ + "public static class Builder {", + " private ${1:Type} ${2:field};", + "", + " public Builder ${2:field}(${1:Type} ${3:value}) {", + " this.${2:field} = ${3:value};", + " return this;", + " }", + "", + " public ${4:ClassName} build() {", + " return new ${4:ClassName}(this);", + " }", + "}", + "$0" + ], + "description": "Manual builder inner class." + }, + "Pattern: Singleton": { + "prefix": "jsingleton", + "body": [ + "public final class ${1:Singleton} {", + " private static final ${1:Singleton} INSTANCE = new ${1:Singleton}();", + "", + " private ${1:Singleton}() {}", + "", + " public static ${1:Singleton} getInstance() {", + " return INSTANCE;", + " }", + "}", + "" + ], + "description": "Eager singleton pattern." + }, + "Pattern: Factory method": { + "prefix": "jfactory", + "body": [ + "public static ${1:Type} ${2:create}(${3:Args}) {", + " return new ${1:Type}(${4:ctorArgs});", + "}", + "$0" + ], + "description": "Factory method template." + }, + + "Regex: Pattern/Matcher": { + "prefix": "jre", + "body": [ + "java.util.regex.Pattern p = java.util.regex.Pattern.compile(${1:\"\\\\\\\\d+\"});", + "java.util.regex.Matcher m = p.matcher(${2:input});", + "while (m.find()) {", + " $0", + "}" + ], + "description": "Regex Pattern/Matcher loop." + }, + + "DateTime: Instant.now": { + "prefix": "jnowi", + "body": ["java.time.Instant ${1:now} = java.time.Instant.now();", "$0"], + "description": "Instant.now()." + }, + "DateTime: LocalDate.now": { + "prefix": "jnowd", + "body": [ + "java.time.LocalDate ${1:today} = java.time.LocalDate.now();", + "$0" + ], + "description": "LocalDate.now()." + }, + "DateTime: DateTimeFormatter": { + "prefix": "jdtf", + "body": [ + "java.time.format.DateTimeFormatter ${1:fmt} = java.time.format.DateTimeFormatter.ofPattern(${2:\"yyyy-MM-dd\"});", + "String ${3:s} = ${4:date}.format(${1:fmt});", + "$0" + ], + "description": "DateTimeFormatter pattern + format." } } From ce34e7edd1b68b79bde25e4787a4bcb24a2a746f Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:21:07 +1000 Subject: [PATCH 10/13] feat: added snippets for build tools like gradle (groovy, kotlin dsl) Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets.json | 1034 ------------------------------------------ snippets/groovy.json | 53 +++ 2 files changed, 53 insertions(+), 1034 deletions(-) delete mode 100644 snippets.json create mode 100644 snippets/groovy.json diff --git a/snippets.json b/snippets.json deleted file mode 100644 index 4cf8f32..0000000 --- a/snippets.json +++ /dev/null @@ -1,1034 +0,0 @@ -{ - "package": { - "prefix": "jpkg", - "body": ["package ${1:com.example};", "", "$0"], - "description": "Package declaration." - }, - "import": { - "prefix": "jimp", - "body": ["import ${1:java.util.*};", "$0"], - "description": "Import statement." - }, - "static import": { - "prefix": "jimps", - "body": ["import static ${1:org.junit.jupiter.api.Assertions}.*;", "$0"], - "description": "Static import statement." - }, - - "class": { - "prefix": "jclass", - "body": ["public class ${1:ClassName} {", " $0", "}", ""], - "description": "Public class skeleton." - }, - "final class": { - "prefix": "jfclass", - "body": ["public final class ${1:ClassName} {", " $0", "}", ""], - "description": "Final class skeleton." - }, - "abstract class": { - "prefix": "jabs", - "body": ["public abstract class ${1:AbstractName} {", " $0", "}", ""], - "description": "Abstract class skeleton." - }, - "interface": { - "prefix": "jint", - "body": ["public interface ${1:MyInterface} {", " $0", "}", ""], - "description": "Interface skeleton." - }, - "enum": { - "prefix": "jenum", - "body": ["public enum ${1:MyEnum} {", " ${2:VALUE};", " $0", "}", ""], - "description": "Enum skeleton." - }, - "record (Java 16+)": { - "prefix": "jrec", - "body": ["public record ${1:Name}(${2:Type field}) {", " $0", "}", ""], - "description": "Record skeleton." - }, - "sealed interface (Java 17+)": { - "prefix": "jsealedint", - "body": [ - "public sealed interface ${1:Shape} permits ${2:Circle}, ${3:Square} {", - " $0", - "}", - "" - ], - "description": "Sealed interface skeleton." - }, - "sealed class (Java 17+)": { - "prefix": "jsealedclass", - "body": [ - "public sealed class ${1:Base} permits ${2:ChildA}, ${3:ChildB} {", - " $0", - "}", - "" - ], - "description": "Sealed class skeleton." - }, - - "class + main": { - "prefix": "jmain", - "body": [ - "public class ${1:Main} {", - " public static void main(String[] args) {", - " $0", - " }", - "}", - "" - ], - "description": "Class with main method." - }, - "private field": { - "prefix": "jpf", - "body": ["private ${1:Type} ${2:name};", "$0"], - "description": "Private field." - }, - "private final field": { - "prefix": "jpff", - "body": ["private final ${1:Type} ${2:name};", "$0"], - "description": "Private final field." - }, - "public static final constant": { - "prefix": "jconst", - "body": ["public static final ${1:Type} ${2:NAME} = ${3:value};", "$0"], - "description": "Constant declaration." - }, - - "constructor": { - "prefix": "jctor", - "body": [ - "public ${1:ClassName}(${2:Type ${3:arg}}) {", - " this.${4:field} = ${3:arg};", - " $0", - "}", - "" - ], - "description": "Constructor template." - }, - "no-args constructor": { - "prefix": "jctor0", - "body": ["public ${1:ClassName}() {", " $0", "}", ""], - "description": "No-args constructor." - }, - - "getter": { - "prefix": "jget", - "body": [ - "public ${1:Type} get${2:Name}() {", - " return ${3:field};", - "}", - "" - ], - "description": "Getter method." - }, - "setter": { - "prefix": "jset", - "body": [ - "public void set${1:Name}(${2:Type} ${3:value}) {", - " this.${4:field} = ${3:value};", - "}", - "" - ], - "description": "Setter method." - }, - "method (public)": { - "prefix": "jpubm", - "body": [ - "public ${1:void} ${2:methodName}(${3:Type arg}) {", - " $0", - "}", - "" - ], - "description": "Public method template." - }, - "method (private)": { - "prefix": "jprim", - "body": [ - "private ${1:void} ${2:methodName}(${3:Type arg}) {", - " $0", - "}", - "" - ], - "description": "Private method template." - }, - "static method": { - "prefix": "jstaticm", - "body": [ - "public static ${1:void} ${2:methodName}(${3:Type arg}) {", - " $0", - "}", - "" - ], - "description": "Static method template." - }, - "generic method": { - "prefix": "jgenm", - "body": [ - "public static <${1:T}> ${1:T} ${2:methodName}(${1:T} ${3:value}) {", - " return ${3:value};", - "}", - "" - ], - "description": "Generic method template." - }, - - "override method": { - "prefix": "joverride", - "body": [ - "@Override", - "public ${1:void} ${2:methodName}(${3:Type arg}) {", - " $0", - "}", - "" - ], - "description": "@Override method template." - }, - - "equals/hashCode (Objects)": { - "prefix": "jeqh", - "body": [ - "@Override", - "public boolean equals(Object o) {", - " if (this == o) return true;", - " if (o == null || getClass() != o.getClass()) return false;", - " ${1:ClassName} that = (${1:ClassName}) o;", - " return java.util.Objects.equals(${2:field}, that.${2:field});", - "}", - "", - "@Override", - "public int hashCode() {", - " return java.util.Objects.hash(${2:field});", - "}", - "" - ], - "description": "equals/hashCode using java.util.Objects." - }, - "toString": { - "prefix": "jts", - "body": [ - "@Override", - "public String toString() {", - " return \"${1:ClassName}{\" +", - " \"${2:field}=\" + ${2:field} +", - " '}';", - "}", - "" - ], - "description": "toString template." - }, - "System.out.println": { - "prefix": "sout", - "body": ["System.out.println(${1:msg});", "$0"], - "description": "Print to stdout." - }, - "System.err.println": { - "prefix": "serr", - "body": ["System.err.println(${1:msg});", "$0"], - "description": "Print to stderr." - }, - - "Javadoc (method)": { - "prefix": "jdoc", - "body": [ - "/**", - " * ${1:Summary}", - " *", - " * @param ${2:param} ${3:description}", - " * @return ${4:description}", - " */", - "$0" - ], - "description": "Javadoc template." - }, - "TODO": { - "prefix": "todo", - "body": ["// TODO(${1:you}): ${2:what}", "$0"], - "description": "TODO comment." - }, - - "if": { - "prefix": "jif", - "body": ["if (${1:condition}) {", " $0", "}"], - "description": "If statement." - }, - "if/else": { - "prefix": "jife", - "body": ["if (${1:condition}) {", " ${2:// ...}", "} else {", " $0", "}"], - "description": "If/else statement." - }, - "switch statement": { - "prefix": "jswitch", - "body": [ - "switch (${1:expr}) {", - " case ${2:VALUE}:", - " $0", - " break;", - " default:", - " break;", - "}" - ], - "description": "Switch statement." - }, - "switch expression (Java 14+)": { - "prefix": "jswitchx", - "body": [ - "${1:var} = switch (${2:expr}) {", - " case ${3:VALUE} -> ${4:result};", - " default -> ${5:result};", - "};", - "$0" - ], - "description": "Switch expression." - }, - - "for (index)": { - "prefix": "jfor", - "body": ["for (int ${1:i} = 0; ${1:i} < ${2:n}; ${1:i}++) {", " $0", "}"], - "description": "Indexed for loop." - }, - "foreach": { - "prefix": "jforeach", - "body": ["for (${1:Type} ${2:item} : ${3:items}) {", " $0", "}"], - "description": "Enhanced for loop." - }, - "while": { - "prefix": "jwhile", - "body": ["while (${1:condition}) {", " $0", "}"], - "description": "While loop." - }, - "do/while": { - "prefix": "jdowhile", - "body": ["do {", " $0", "} while (${1:condition});"], - "description": "Do/while loop." - }, - - "requireNonNull": { - "prefix": "jnonn", - "body": [ - "java.util.Objects.requireNonNull(${1:obj}, \"${2:message}\");", - "$0" - ], - "description": "Objects.requireNonNull guard." - }, - "null guard return": { - "prefix": "jngret", - "body": ["if (${1:obj} == null) {", " return ${2:null};", "}", "$0"], - "description": "Null guard with return." - }, - "null guard throw": { - "prefix": "jngthrow", - "body": [ - "if (${1:obj} == null) {", - " throw new ${2:IllegalArgumentException}(\"${3:message}\");", - "}", - "$0" - ], - "description": "Null guard with throw." - }, - - "try/catch": { - "prefix": "jtry", - "body": [ - "try {", - " $0", - "} catch (${1:Exception} e) {", - " ${2:e.printStackTrace();}", - "}" - ], - "description": "try/catch block." - }, - "try/catch/finally": { - "prefix": "jtryf", - "body": [ - "try {", - " $0", - "} catch (${1:Exception} e) {", - " ${2:e.printStackTrace();}", - "} finally {", - " ${3:// cleanup}", - "}" - ], - "description": "try/catch/finally block." - }, - "try-with-resources": { - "prefix": "jtryr", - "body": [ - "try (${1:var} ${2:resource} = ${3:initializer}) {", - " $0", - "} catch (${4:Exception} e) {", - " ${5:e.printStackTrace();}", - "}" - ], - "description": "Try-with-resources." - }, - - "custom exception": { - "prefix": "jex", - "body": [ - "public class ${1:MyException} extends RuntimeException {", - " public ${1:MyException}(String message) {", - " super(message);", - " }", - "", - " public ${1:MyException}(String message, Throwable cause) {", - " super(message, cause);", - " }", - "}", - "" - ], - "description": "Custom RuntimeException." - }, - "List declaration": { - "prefix": "jlist", - "body": [ - "java.util.List<${1:Type}> ${2:list} = new java.util.ArrayList<>();", - "$0" - ], - "description": "New ArrayList." - }, - "Set declaration": { - "prefix": "jset", - "body": [ - "java.util.Set<${1:Type}> ${2:set} = new java.util.HashSet<>();", - "$0" - ], - "description": "New HashSet." - }, - "Map declaration": { - "prefix": "jmap", - "body": [ - "java.util.Map<${1:K}, ${2:V}> ${3:map} = new java.util.HashMap<>();", - "$0" - ], - "description": "New HashMap." - }, - - "Stream filter/map/toList": { - "prefix": "jstream", - "body": [ - "${1:list}.stream()", - " .filter(${2:x} -> ${3:predicate})", - " .map(${2:x} -> ${4:transform})", - " .toList();", - "$0" - ], - "description": "Stream pipeline (Java 16+ toList)." - }, - "Collectors.toList": { - "prefix": "jcolist", - "body": [ - "${1:stream}.collect(java.util.stream.Collectors.toList());", - "$0" - ], - "description": "Collect stream to list." - }, - "Collectors.toMap": { - "prefix": "jcomap", - "body": [ - "${1:stream}.collect(java.util.stream.Collectors.toMap(", - " ${2:x} -> ${3:key},", - " ${2:x} -> ${4:value}", - "));", - "$0" - ], - "description": "Collect stream to map." - }, - "Comparator.comparing": { - "prefix": "jcomp", - "body": ["java.util.Comparator.comparing(${1:Type}::${2:getField})", "$0"], - "description": "Comparator.comparing reference." - }, - - "Optional.ofNullable": { - "prefix": "jopt", - "body": [ - "java.util.Optional.ofNullable(${1:value})", - " .orElse(${2:defaultValue});", - "$0" - ], - "description": "Optional.ofNullable(...).orElse(...)." - }, - "Optional.orElseThrow": { - "prefix": "joptx", - "body": [ - "${1:optional}.orElseThrow(() -> new ${2:IllegalStateException}(\"${3:message}\"));", - "$0" - ], - "description": "Optional.orElseThrow with custom exception." - }, - - "logger (SLF4J)": { - "prefix": "jlog", - "body": [ - "private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(${1:ClassName}.class);", - "$0" - ], - "description": "SLF4J logger field." - }, - "log.info": { - "prefix": "jinfo", - "body": ["log.info(\"${1:message}: {}\", ${2:value});", "$0"], - "description": "log.info with placeholder." - }, - "log.warn": { - "prefix": "jwarn", - "body": ["log.warn(\"${1:message}: {}\", ${2:value});", "$0"], - "description": "log.warn with placeholder." - }, - "log.error (with throwable)": { - "prefix": "jerr", - "body": ["log.error(\"${1:message}\", ${2:throwable});", "$0"], - "description": "log.error with throwable." - }, - "Thread (lambda)": { - "prefix": "jthread", - "body": ["new Thread(() -> {", " $0", "}).start();"], - "description": "Start a Thread with lambda." - }, - "Runnable": { - "prefix": "jrunnable", - "body": ["Runnable ${1:task} = () -> {", " $0", "};"], - "description": "Runnable lambda." - }, - "Callable": { - "prefix": "jcallable", - "body": [ - "java.util.concurrent.Callable<${1:T}> ${2:task} = () -> {", - " return $0;", - "};" - ], - "description": "Callable lambda." - }, - "ExecutorService (fixed pool)": { - "prefix": "jexec", - "body": [ - "java.util.concurrent.ExecutorService ${1:pool} = java.util.concurrent.Executors.newFixedThreadPool(${2:nThreads});", - "try {", - " $0", - "} finally {", - " ${1:pool}.shutdown();", - "}" - ], - "description": "ExecutorService fixed thread pool." - }, - "CompletableFuture.supplyAsync": { - "prefix": "jcf", - "body": [ - "java.util.concurrent.CompletableFuture<${1:T}> ${2:cf} = java.util.concurrent.CompletableFuture.supplyAsync(() -> {", - " return $0;", - "});" - ], - "description": "CompletableFuture.supplyAsync template." - }, - "synchronized block": { - "prefix": "jsync", - "body": ["synchronized (${1:lock}) {", " $0", "}"], - "description": "Synchronized block." - }, - "ReentrantLock": { - "prefix": "jlock", - "body": [ - "java.util.concurrent.locks.Lock ${1:lock} = new java.util.concurrent.locks.ReentrantLock();", - "${1:lock}.lock();", - "try {", - " $0", - "} finally {", - " ${1:lock}.unlock();", - "}" - ], - "description": "ReentrantLock with try/finally." - }, - - "Path.of": { - "prefix": "jpath", - "body": [ - "java.nio.file.Path ${1:path} = java.nio.file.Path.of(${2:\"file.txt\"});", - "$0" - ], - "description": "Create a Path." - }, - "Files.readString": { - "prefix": "jreadstr", - "body": [ - "String ${1:text} = java.nio.file.Files.readString(${2:path});", - "$0" - ], - "description": "Read file contents as String." - }, - "Files.readAllLines": { - "prefix": "jreadlines", - "body": [ - "java.util.List ${1:lines} = java.nio.file.Files.readAllLines(${2:path});", - "$0" - ], - "description": "Read all lines into List." - }, - "Files.writeString": { - "prefix": "jwritestr", - "body": ["java.nio.file.Files.writeString(${1:path}, ${2:text});", "$0"], - "description": "Write String to file." - }, - "HttpClient GET (Java 11+)": { - "prefix": "jhttpget", - "body": [ - "java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();", - "java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()", - " .uri(java.net.URI.create(${1:\"https://example.com\"}))", - " .GET()", - " .build();", - "", - "java.net.http.HttpResponse response = client.send(", - " request,", - " java.net.http.HttpResponse.BodyHandlers.ofString()", - ");", - "", - "$0" - ], - "description": "HttpClient GET request." - }, - " HttpClient POST JSON (Java 11+)": { - "prefix": "jhttppost", - "body": [ - "java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();", - "java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()", - " .uri(java.net.URI.create(${1:\"https://example.com\"}))", - " .header(\"Content-Type\", \"application/json\")", - " .POST(java.net.http.HttpRequest.BodyPublishers.ofString(${2:json}))", - " .build();", - "", - "java.net.http.HttpResponse response = client.send(", - " request,", - " java.net.http.HttpResponse.BodyHandlers.ofString()", - ");", - "", - "$0" - ], - "description": "HttpClient POST JSON request." - }, - - " Jackson ObjectMapper": { - "prefix": "jjackson", - "body": [ - "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", - "$0" - ], - "description": "Create Jackson ObjectMapper." - }, - " Jackson readValue (class)": { - "prefix": "jreadjson", - "body": [ - "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", - "${1:Type} ${2:value} = mapper.readValue(${3:json}, ${1:Type}.class);", - "$0" - ], - "description": "Jackson readValue into class." - }, - " Jackson writeValueAsString": { - "prefix": "jwritejson", - "body": [ - "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", - "String ${1:json} = mapper.writeValueAsString(${2:obj});", - "$0" - ], - "description": "Jackson write object to JSON string." - }, - - "JUnit5: test class": { - "prefix": "junit", - "body": [ - "import org.junit.jupiter.api.Test;", - "import static org.junit.jupiter.api.Assertions.*;", - "", - "class ${1:TestName} {", - " @Test", - " void ${2:shouldDoThing}() {", - " $0", - " }", - "}", - "" - ], - "description": "JUnit 5 test class + assertion imports." - }, - "JUnit5: @BeforeEach": { - "prefix": "jbefore", - "body": [ - "@org.junit.jupiter.api.BeforeEach", - "void setUp() {", - " $0", - "}", - "" - ], - "description": "JUnit5 @BeforeEach." - }, - "JUnit5: @AfterEach": { - "prefix": "jafter", - "body": [ - "@org.junit.jupiter.api.AfterEach", - "void tearDown() {", - " $0", - "}", - "" - ], - "description": "JUnit5 @AfterEach." - }, - "JUnit5: assertEquals": { - "prefix": "aeq", - "body": [ - "org.junit.jupiter.api.Assertions.assertEquals(${1:expected}, ${2:actual});", - "$0" - ], - "description": "Assertions.assertEquals." - }, - "JUnit5: assertThrows": { - "prefix": "athrows", - "body": [ - "org.junit.jupiter.api.Assertions.assertThrows(${1:ExceptionType}.class, () -> {", - " $0", - "});" - ], - "description": "Assertions.assertThrows." - }, - "JUnit5: parameterized @ValueSource": { - "prefix": "jparam", - "body": [ - "import org.junit.jupiter.params.ParameterizedTest;", - "import org.junit.jupiter.params.provider.ValueSource;", - "", - "@ParameterizedTest", - "@ValueSource(${1:ints} = { ${2:1}, ${3:2}, ${4:3} })", - "void ${5:shouldWork}(${6:int value}) {", - " $0", - "}", - "" - ], - "description": "JUnit5 parameterized test with ValueSource." - }, - "JUnit5: @Nested": { - "prefix": "jnested", - "body": [ - "@org.junit.jupiter.api.Nested", - "class ${1:WhenSomething} {", - " @org.junit.jupiter.api.Test", - " void ${2:shouldDoX}() {", - " $0", - " }", - "}", - "" - ], - "description": "JUnit5 nested test class." - }, - - "AssertJ: assertThat": { - "prefix": "aj", - "body": [ - "org.assertj.core.api.Assertions.assertThat(${1:actual}).${2:isEqualTo}(${3:expected});", - "$0" - ], - "description": "AssertJ assertThat." - }, - "AssertJ: assertThatThrownBy": { - "prefix": "ajthrow", - "body": [ - "org.assertj.core.api.Assertions.assertThatThrownBy(() -> {", - " $0", - "}).isInstanceOf(${1:ExceptionType}.class);" - ], - "description": "AssertJ assertThatThrownBy." - }, - - "Mockito: mock": { - "prefix": "mmock", - "body": [ - "${1:Type} ${2:mock} = org.mockito.Mockito.mock(${1:Type}.class);", - "$0" - ], - "description": "Create Mockito mock." - }, - "Mockito: when/thenReturn": { - "prefix": "mwhen", - "body": [ - "org.mockito.Mockito.when(${1:mock}.${2:method}(${3:args})).thenReturn(${4:value});", - "$0" - ], - "description": "Mockito stubbing." - }, - "Mockito: verify": { - "prefix": "mverify", - "body": [ - "org.mockito.Mockito.verify(${1:mock}).${2:method}(${3:args});", - "$0" - ], - "description": "Mockito verify call." - }, - "Mockito: ArgumentCaptor": { - "prefix": "mcap", - "body": [ - "org.mockito.ArgumentCaptor<${1:Type}> ${2:captor} = org.mockito.ArgumentCaptor.forClass(${1:Type}.class);", - "org.mockito.Mockito.verify(${3:mock}).${4:method}(${2:captor}.capture());", - "${1:Type} ${5:value} = ${2:captor}.getValue();", - "$0" - ], - "description": "Mockito ArgumentCaptor pattern." - }, - "Spring Boot: @SpringBootApplication main": { - "prefix": "sbapp", - "body": [ - "import org.springframework.boot.SpringApplication;", - "import org.springframework.boot.autoconfigure.SpringBootApplication;", - "", - "@SpringBootApplication", - "public class ${1:Application} {", - " public static void main(String[] args) {", - " SpringApplication.run(${1:Application}.class, args);", - " }", - "}", - "" - ], - "description": "Spring Boot application entry." - }, - "Spring: @RestController": { - "prefix": "sbrest", - "body": [ - "import org.springframework.web.bind.annotation.*;", - "", - "@RestController", - "@RequestMapping(\"/${1:resource}\")", - "public class ${2:Resource}Controller {", - " @GetMapping", - " public ${3:String} index() {", - " return ${4:\"ok\"};", - " }", - "", - " $0", - "}", - "" - ], - "description": "Spring REST controller skeleton." - }, - "Spring: @Service": { - "prefix": "sbservice", - "body": [ - "import org.springframework.stereotype.Service;", - "", - "@Service", - "public class ${1:ServiceName} {", - " $0", - "}", - "" - ], - "description": "Spring @Service skeleton." - }, - "Spring: @Repository": { - "prefix": "sbrepo", - "body": [ - "import org.springframework.stereotype.Repository;", - "", - "@Repository", - "public class ${1:RepositoryName} {", - " $0", - "}", - "" - ], - "description": "Spring @Repository skeleton." - }, - "Spring Data: CrudRepository": { - "prefix": "sbcrud", - "body": [ - "import org.springframework.data.repository.CrudRepository;", - "", - "public interface ${1:RepoName} extends CrudRepository<${2:Entity}, ${3:IdType}> {", - " $0", - "}", - "" - ], - "description": "Spring Data CrudRepository interface." - }, - "Spring: @ControllerAdvice (exception handler)": { - "prefix": "sbadvice", - "body": [ - "import org.springframework.http.*;", - "import org.springframework.web.bind.annotation.*;", - "", - "@ControllerAdvice", - "public class ${1:GlobalExceptionHandler} {", - " @ExceptionHandler(${2:ExceptionType}.class)", - " public ResponseEntity<${3:String}> handle(${2:ExceptionType} e) {", - " return ResponseEntity.status(HttpStatus.${4:BAD_REQUEST}).body(e.getMessage());", - " }", - "}", - "" - ], - "description": "Spring global exception handler." - }, - "JPA: @Entity": { - "prefix": "jpaentity", - "body": [ - "import jakarta.persistence.*;", - "", - "@Entity", - "@Table(name = \"${1:table_name}\")", - "public class ${2:EntityName} {", - " @Id", - " @GeneratedValue(strategy = GenerationType.IDENTITY)", - " private ${3:Long} id;", - "", - " $0", - "}", - "" - ], - "description": "JPA entity skeleton." - }, - "JPA: @Column": { - "prefix": "jpacol", - "body": [ - "@Column(name = \"${1:col}\", nullable = ${2:true})", - "private ${3:Type} ${4:field};", - "$0" - ], - "description": "JPA column field." - }, - "JPA: @ManyToOne": { - "prefix": "jpam2o", - "body": [ - "@ManyToOne(fetch = FetchType.LAZY)", - "@JoinColumn(name = \"${1:other_id}\")", - "private ${2:OtherEntity} ${3:other};", - "$0" - ], - "description": "JPA ManyToOne association." - }, - "JPA: @OneToMany": { - "prefix": "jpao2m", - "body": [ - "@OneToMany(mappedBy = \"${1:owner}\", cascade = CascadeType.ALL, orphanRemoval = true)", - "private java.util.List<${2:ChildEntity}> ${3:children} = new java.util.ArrayList<>();", - "$0" - ], - "description": "JPA OneToMany association." - }, - - "Jakarta Validation: @Valid + @NotNull": { - "prefix": "jvalid", - "body": [ - "import jakarta.validation.Valid;", - "import jakarta.validation.constraints.NotNull;", - "", - "public ${1:void} ${2:method}(@Valid @NotNull ${3:Type} ${4:req}) {", - " $0", - "}", - "" - ], - "description": "Validation annotations template." - }, - - "Lombok: @Data class": { - "prefix": "ldata", - "body": [ - "import lombok.Data;", - "", - "@Data", - "public class ${1:Dto} {", - " private ${2:Type} ${3:field};", - " $0", - "}", - "" - ], - "description": "Lombok @Data class." - }, - "Lombok: @Builder": { - "prefix": "lbuilder", - "body": [ - "import lombok.Builder;", - "import lombok.Value;", - "", - "@Value", - "@Builder", - "public class ${1:ValueType} {", - " ${2:Type} ${3:field};", - " $0", - "}", - "" - ], - "description": "Lombok immutable + builder." - }, - "Pattern: Builder (manual)": { - "prefix": "jbuilder", - "body": [ - "public static class Builder {", - " private ${1:Type} ${2:field};", - "", - " public Builder ${2:field}(${1:Type} ${3:value}) {", - " this.${2:field} = ${3:value};", - " return this;", - " }", - "", - " public ${4:ClassName} build() {", - " return new ${4:ClassName}(this);", - " }", - "}", - "$0" - ], - "description": "Manual builder inner class." - }, - "Pattern: Singleton": { - "prefix": "jsingleton", - "body": [ - "public final class ${1:Singleton} {", - " private static final ${1:Singleton} INSTANCE = new ${1:Singleton}();", - "", - " private ${1:Singleton}() {}", - "", - " public static ${1:Singleton} getInstance() {", - " return INSTANCE;", - " }", - "}", - "" - ], - "description": "Eager singleton pattern." - }, - "Pattern: Factory method": { - "prefix": "jfactory", - "body": [ - "public static ${1:Type} ${2:create}(${3:Args}) {", - " return new ${1:Type}(${4:ctorArgs});", - "}", - "$0" - ], - "description": "Factory method template." - }, - - "Regex: Pattern/Matcher": { - "prefix": "jre", - "body": [ - "java.util.regex.Pattern p = java.util.regex.Pattern.compile(${1:\"\\\\\\\\d+\"});", - "java.util.regex.Matcher m = p.matcher(${2:input});", - "while (m.find()) {", - " $0", - "}" - ], - "description": "Regex Pattern/Matcher loop." - }, - - "DateTime: Instant.now": { - "prefix": "jnowi", - "body": ["java.time.Instant ${1:now} = java.time.Instant.now();", "$0"], - "description": "Instant.now()." - }, - "DateTime: LocalDate.now": { - "prefix": "jnowd", - "body": [ - "java.time.LocalDate ${1:today} = java.time.LocalDate.now();", - "$0" - ], - "description": "LocalDate.now()." - }, - "DateTime: DateTimeFormatter": { - "prefix": "jdtf", - "body": [ - "java.time.format.DateTimeFormatter ${1:fmt} = java.time.format.DateTimeFormatter.ofPattern(${2:\"yyyy-MM-dd\"});", - "String ${3:s} = ${4:date}.format(${1:fmt});", - "$0" - ], - "description": "DateTimeFormatter pattern + format." - } -} diff --git a/snippets/groovy.json b/snippets/groovy.json new file mode 100644 index 0000000..9fb9697 --- /dev/null +++ b/snippets/groovy.json @@ -0,0 +1,53 @@ +{ + "Gradle (Groovy): Java library skeleton": { + "prefix": "gjava", + "body": [ + "plugins {", + " id 'java-library'", + "}", + "", + "group = '${1:com.example}'", + "version = '${2:0.1.0}'", + "", + "repositories {", + " mavenCentral()", + "}", + "", + "dependencies {", + " testImplementation 'org.junit.jupiter:junit-jupiter:${3:5.10.2}'", + " testImplementation 'org.mockito:mockito-core:${4:5.12.0}'", + " testImplementation 'org.assertj:assertj-core:${5:3.26.3}'", + "}", + "", + "test {", + " useJUnitPlatform()", + "}", + "" + ], + "description": "Gradle Groovy Java project template with JUnit/Mockito/AssertJ." + }, + "Gradle (Groovy): Spring Boot skeleton": { + "prefix": "gspring", + "body": [ + "plugins {", + " id 'java'", + " id 'org.springframework.boot' version '${1:3.3.5}'", + " id 'io.spring.dependency-management' version '${2:1.1.6}'", + "}", + "", + "group = '${3:com.example}'", + "version = '${4:0.1.0}'", + "", + "repositories {", + " mavenCentral()", + "}", + "", + "dependencies {", + " implementation 'org.springframework.boot:spring-boot-starter-web'", + " testImplementation 'org.springframework.boot:spring-boot-starter-test'", + "}", + "" + ], + "description": "Gradle Groovy Spring Boot template." + } +} From 3a3038c5af2bd2e4a3818fa1757f68e0d61f4312 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:22:13 +1000 Subject: [PATCH 11/13] feat: added snippets for build tools like gradle (groovy, kotlin dsl) and moved java snippets to snippets/ Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets/java.json | 1034 ++++++++++++++++++++++++++++++++++++++++++ snippets/kotlin.json | 53 +++ 2 files changed, 1087 insertions(+) create mode 100644 snippets/java.json create mode 100644 snippets/kotlin.json diff --git a/snippets/java.json b/snippets/java.json new file mode 100644 index 0000000..4cf8f32 --- /dev/null +++ b/snippets/java.json @@ -0,0 +1,1034 @@ +{ + "package": { + "prefix": "jpkg", + "body": ["package ${1:com.example};", "", "$0"], + "description": "Package declaration." + }, + "import": { + "prefix": "jimp", + "body": ["import ${1:java.util.*};", "$0"], + "description": "Import statement." + }, + "static import": { + "prefix": "jimps", + "body": ["import static ${1:org.junit.jupiter.api.Assertions}.*;", "$0"], + "description": "Static import statement." + }, + + "class": { + "prefix": "jclass", + "body": ["public class ${1:ClassName} {", " $0", "}", ""], + "description": "Public class skeleton." + }, + "final class": { + "prefix": "jfclass", + "body": ["public final class ${1:ClassName} {", " $0", "}", ""], + "description": "Final class skeleton." + }, + "abstract class": { + "prefix": "jabs", + "body": ["public abstract class ${1:AbstractName} {", " $0", "}", ""], + "description": "Abstract class skeleton." + }, + "interface": { + "prefix": "jint", + "body": ["public interface ${1:MyInterface} {", " $0", "}", ""], + "description": "Interface skeleton." + }, + "enum": { + "prefix": "jenum", + "body": ["public enum ${1:MyEnum} {", " ${2:VALUE};", " $0", "}", ""], + "description": "Enum skeleton." + }, + "record (Java 16+)": { + "prefix": "jrec", + "body": ["public record ${1:Name}(${2:Type field}) {", " $0", "}", ""], + "description": "Record skeleton." + }, + "sealed interface (Java 17+)": { + "prefix": "jsealedint", + "body": [ + "public sealed interface ${1:Shape} permits ${2:Circle}, ${3:Square} {", + " $0", + "}", + "" + ], + "description": "Sealed interface skeleton." + }, + "sealed class (Java 17+)": { + "prefix": "jsealedclass", + "body": [ + "public sealed class ${1:Base} permits ${2:ChildA}, ${3:ChildB} {", + " $0", + "}", + "" + ], + "description": "Sealed class skeleton." + }, + + "class + main": { + "prefix": "jmain", + "body": [ + "public class ${1:Main} {", + " public static void main(String[] args) {", + " $0", + " }", + "}", + "" + ], + "description": "Class with main method." + }, + "private field": { + "prefix": "jpf", + "body": ["private ${1:Type} ${2:name};", "$0"], + "description": "Private field." + }, + "private final field": { + "prefix": "jpff", + "body": ["private final ${1:Type} ${2:name};", "$0"], + "description": "Private final field." + }, + "public static final constant": { + "prefix": "jconst", + "body": ["public static final ${1:Type} ${2:NAME} = ${3:value};", "$0"], + "description": "Constant declaration." + }, + + "constructor": { + "prefix": "jctor", + "body": [ + "public ${1:ClassName}(${2:Type ${3:arg}}) {", + " this.${4:field} = ${3:arg};", + " $0", + "}", + "" + ], + "description": "Constructor template." + }, + "no-args constructor": { + "prefix": "jctor0", + "body": ["public ${1:ClassName}() {", " $0", "}", ""], + "description": "No-args constructor." + }, + + "getter": { + "prefix": "jget", + "body": [ + "public ${1:Type} get${2:Name}() {", + " return ${3:field};", + "}", + "" + ], + "description": "Getter method." + }, + "setter": { + "prefix": "jset", + "body": [ + "public void set${1:Name}(${2:Type} ${3:value}) {", + " this.${4:field} = ${3:value};", + "}", + "" + ], + "description": "Setter method." + }, + "method (public)": { + "prefix": "jpubm", + "body": [ + "public ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Public method template." + }, + "method (private)": { + "prefix": "jprim", + "body": [ + "private ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Private method template." + }, + "static method": { + "prefix": "jstaticm", + "body": [ + "public static ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "Static method template." + }, + "generic method": { + "prefix": "jgenm", + "body": [ + "public static <${1:T}> ${1:T} ${2:methodName}(${1:T} ${3:value}) {", + " return ${3:value};", + "}", + "" + ], + "description": "Generic method template." + }, + + "override method": { + "prefix": "joverride", + "body": [ + "@Override", + "public ${1:void} ${2:methodName}(${3:Type arg}) {", + " $0", + "}", + "" + ], + "description": "@Override method template." + }, + + "equals/hashCode (Objects)": { + "prefix": "jeqh", + "body": [ + "@Override", + "public boolean equals(Object o) {", + " if (this == o) return true;", + " if (o == null || getClass() != o.getClass()) return false;", + " ${1:ClassName} that = (${1:ClassName}) o;", + " return java.util.Objects.equals(${2:field}, that.${2:field});", + "}", + "", + "@Override", + "public int hashCode() {", + " return java.util.Objects.hash(${2:field});", + "}", + "" + ], + "description": "equals/hashCode using java.util.Objects." + }, + "toString": { + "prefix": "jts", + "body": [ + "@Override", + "public String toString() {", + " return \"${1:ClassName}{\" +", + " \"${2:field}=\" + ${2:field} +", + " '}';", + "}", + "" + ], + "description": "toString template." + }, + "System.out.println": { + "prefix": "sout", + "body": ["System.out.println(${1:msg});", "$0"], + "description": "Print to stdout." + }, + "System.err.println": { + "prefix": "serr", + "body": ["System.err.println(${1:msg});", "$0"], + "description": "Print to stderr." + }, + + "Javadoc (method)": { + "prefix": "jdoc", + "body": [ + "/**", + " * ${1:Summary}", + " *", + " * @param ${2:param} ${3:description}", + " * @return ${4:description}", + " */", + "$0" + ], + "description": "Javadoc template." + }, + "TODO": { + "prefix": "todo", + "body": ["// TODO(${1:you}): ${2:what}", "$0"], + "description": "TODO comment." + }, + + "if": { + "prefix": "jif", + "body": ["if (${1:condition}) {", " $0", "}"], + "description": "If statement." + }, + "if/else": { + "prefix": "jife", + "body": ["if (${1:condition}) {", " ${2:// ...}", "} else {", " $0", "}"], + "description": "If/else statement." + }, + "switch statement": { + "prefix": "jswitch", + "body": [ + "switch (${1:expr}) {", + " case ${2:VALUE}:", + " $0", + " break;", + " default:", + " break;", + "}" + ], + "description": "Switch statement." + }, + "switch expression (Java 14+)": { + "prefix": "jswitchx", + "body": [ + "${1:var} = switch (${2:expr}) {", + " case ${3:VALUE} -> ${4:result};", + " default -> ${5:result};", + "};", + "$0" + ], + "description": "Switch expression." + }, + + "for (index)": { + "prefix": "jfor", + "body": ["for (int ${1:i} = 0; ${1:i} < ${2:n}; ${1:i}++) {", " $0", "}"], + "description": "Indexed for loop." + }, + "foreach": { + "prefix": "jforeach", + "body": ["for (${1:Type} ${2:item} : ${3:items}) {", " $0", "}"], + "description": "Enhanced for loop." + }, + "while": { + "prefix": "jwhile", + "body": ["while (${1:condition}) {", " $0", "}"], + "description": "While loop." + }, + "do/while": { + "prefix": "jdowhile", + "body": ["do {", " $0", "} while (${1:condition});"], + "description": "Do/while loop." + }, + + "requireNonNull": { + "prefix": "jnonn", + "body": [ + "java.util.Objects.requireNonNull(${1:obj}, \"${2:message}\");", + "$0" + ], + "description": "Objects.requireNonNull guard." + }, + "null guard return": { + "prefix": "jngret", + "body": ["if (${1:obj} == null) {", " return ${2:null};", "}", "$0"], + "description": "Null guard with return." + }, + "null guard throw": { + "prefix": "jngthrow", + "body": [ + "if (${1:obj} == null) {", + " throw new ${2:IllegalArgumentException}(\"${3:message}\");", + "}", + "$0" + ], + "description": "Null guard with throw." + }, + + "try/catch": { + "prefix": "jtry", + "body": [ + "try {", + " $0", + "} catch (${1:Exception} e) {", + " ${2:e.printStackTrace();}", + "}" + ], + "description": "try/catch block." + }, + "try/catch/finally": { + "prefix": "jtryf", + "body": [ + "try {", + " $0", + "} catch (${1:Exception} e) {", + " ${2:e.printStackTrace();}", + "} finally {", + " ${3:// cleanup}", + "}" + ], + "description": "try/catch/finally block." + }, + "try-with-resources": { + "prefix": "jtryr", + "body": [ + "try (${1:var} ${2:resource} = ${3:initializer}) {", + " $0", + "} catch (${4:Exception} e) {", + " ${5:e.printStackTrace();}", + "}" + ], + "description": "Try-with-resources." + }, + + "custom exception": { + "prefix": "jex", + "body": [ + "public class ${1:MyException} extends RuntimeException {", + " public ${1:MyException}(String message) {", + " super(message);", + " }", + "", + " public ${1:MyException}(String message, Throwable cause) {", + " super(message, cause);", + " }", + "}", + "" + ], + "description": "Custom RuntimeException." + }, + "List declaration": { + "prefix": "jlist", + "body": [ + "java.util.List<${1:Type}> ${2:list} = new java.util.ArrayList<>();", + "$0" + ], + "description": "New ArrayList." + }, + "Set declaration": { + "prefix": "jset", + "body": [ + "java.util.Set<${1:Type}> ${2:set} = new java.util.HashSet<>();", + "$0" + ], + "description": "New HashSet." + }, + "Map declaration": { + "prefix": "jmap", + "body": [ + "java.util.Map<${1:K}, ${2:V}> ${3:map} = new java.util.HashMap<>();", + "$0" + ], + "description": "New HashMap." + }, + + "Stream filter/map/toList": { + "prefix": "jstream", + "body": [ + "${1:list}.stream()", + " .filter(${2:x} -> ${3:predicate})", + " .map(${2:x} -> ${4:transform})", + " .toList();", + "$0" + ], + "description": "Stream pipeline (Java 16+ toList)." + }, + "Collectors.toList": { + "prefix": "jcolist", + "body": [ + "${1:stream}.collect(java.util.stream.Collectors.toList());", + "$0" + ], + "description": "Collect stream to list." + }, + "Collectors.toMap": { + "prefix": "jcomap", + "body": [ + "${1:stream}.collect(java.util.stream.Collectors.toMap(", + " ${2:x} -> ${3:key},", + " ${2:x} -> ${4:value}", + "));", + "$0" + ], + "description": "Collect stream to map." + }, + "Comparator.comparing": { + "prefix": "jcomp", + "body": ["java.util.Comparator.comparing(${1:Type}::${2:getField})", "$0"], + "description": "Comparator.comparing reference." + }, + + "Optional.ofNullable": { + "prefix": "jopt", + "body": [ + "java.util.Optional.ofNullable(${1:value})", + " .orElse(${2:defaultValue});", + "$0" + ], + "description": "Optional.ofNullable(...).orElse(...)." + }, + "Optional.orElseThrow": { + "prefix": "joptx", + "body": [ + "${1:optional}.orElseThrow(() -> new ${2:IllegalStateException}(\"${3:message}\"));", + "$0" + ], + "description": "Optional.orElseThrow with custom exception." + }, + + "logger (SLF4J)": { + "prefix": "jlog", + "body": [ + "private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(${1:ClassName}.class);", + "$0" + ], + "description": "SLF4J logger field." + }, + "log.info": { + "prefix": "jinfo", + "body": ["log.info(\"${1:message}: {}\", ${2:value});", "$0"], + "description": "log.info with placeholder." + }, + "log.warn": { + "prefix": "jwarn", + "body": ["log.warn(\"${1:message}: {}\", ${2:value});", "$0"], + "description": "log.warn with placeholder." + }, + "log.error (with throwable)": { + "prefix": "jerr", + "body": ["log.error(\"${1:message}\", ${2:throwable});", "$0"], + "description": "log.error with throwable." + }, + "Thread (lambda)": { + "prefix": "jthread", + "body": ["new Thread(() -> {", " $0", "}).start();"], + "description": "Start a Thread with lambda." + }, + "Runnable": { + "prefix": "jrunnable", + "body": ["Runnable ${1:task} = () -> {", " $0", "};"], + "description": "Runnable lambda." + }, + "Callable": { + "prefix": "jcallable", + "body": [ + "java.util.concurrent.Callable<${1:T}> ${2:task} = () -> {", + " return $0;", + "};" + ], + "description": "Callable lambda." + }, + "ExecutorService (fixed pool)": { + "prefix": "jexec", + "body": [ + "java.util.concurrent.ExecutorService ${1:pool} = java.util.concurrent.Executors.newFixedThreadPool(${2:nThreads});", + "try {", + " $0", + "} finally {", + " ${1:pool}.shutdown();", + "}" + ], + "description": "ExecutorService fixed thread pool." + }, + "CompletableFuture.supplyAsync": { + "prefix": "jcf", + "body": [ + "java.util.concurrent.CompletableFuture<${1:T}> ${2:cf} = java.util.concurrent.CompletableFuture.supplyAsync(() -> {", + " return $0;", + "});" + ], + "description": "CompletableFuture.supplyAsync template." + }, + "synchronized block": { + "prefix": "jsync", + "body": ["synchronized (${1:lock}) {", " $0", "}"], + "description": "Synchronized block." + }, + "ReentrantLock": { + "prefix": "jlock", + "body": [ + "java.util.concurrent.locks.Lock ${1:lock} = new java.util.concurrent.locks.ReentrantLock();", + "${1:lock}.lock();", + "try {", + " $0", + "} finally {", + " ${1:lock}.unlock();", + "}" + ], + "description": "ReentrantLock with try/finally." + }, + + "Path.of": { + "prefix": "jpath", + "body": [ + "java.nio.file.Path ${1:path} = java.nio.file.Path.of(${2:\"file.txt\"});", + "$0" + ], + "description": "Create a Path." + }, + "Files.readString": { + "prefix": "jreadstr", + "body": [ + "String ${1:text} = java.nio.file.Files.readString(${2:path});", + "$0" + ], + "description": "Read file contents as String." + }, + "Files.readAllLines": { + "prefix": "jreadlines", + "body": [ + "java.util.List ${1:lines} = java.nio.file.Files.readAllLines(${2:path});", + "$0" + ], + "description": "Read all lines into List." + }, + "Files.writeString": { + "prefix": "jwritestr", + "body": ["java.nio.file.Files.writeString(${1:path}, ${2:text});", "$0"], + "description": "Write String to file." + }, + "HttpClient GET (Java 11+)": { + "prefix": "jhttpget", + "body": [ + "java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();", + "java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()", + " .uri(java.net.URI.create(${1:\"https://example.com\"}))", + " .GET()", + " .build();", + "", + "java.net.http.HttpResponse response = client.send(", + " request,", + " java.net.http.HttpResponse.BodyHandlers.ofString()", + ");", + "", + "$0" + ], + "description": "HttpClient GET request." + }, + " HttpClient POST JSON (Java 11+)": { + "prefix": "jhttppost", + "body": [ + "java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();", + "java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()", + " .uri(java.net.URI.create(${1:\"https://example.com\"}))", + " .header(\"Content-Type\", \"application/json\")", + " .POST(java.net.http.HttpRequest.BodyPublishers.ofString(${2:json}))", + " .build();", + "", + "java.net.http.HttpResponse response = client.send(", + " request,", + " java.net.http.HttpResponse.BodyHandlers.ofString()", + ");", + "", + "$0" + ], + "description": "HttpClient POST JSON request." + }, + + " Jackson ObjectMapper": { + "prefix": "jjackson", + "body": [ + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", + "$0" + ], + "description": "Create Jackson ObjectMapper." + }, + " Jackson readValue (class)": { + "prefix": "jreadjson", + "body": [ + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", + "${1:Type} ${2:value} = mapper.readValue(${3:json}, ${1:Type}.class);", + "$0" + ], + "description": "Jackson readValue into class." + }, + " Jackson writeValueAsString": { + "prefix": "jwritejson", + "body": [ + "com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();", + "String ${1:json} = mapper.writeValueAsString(${2:obj});", + "$0" + ], + "description": "Jackson write object to JSON string." + }, + + "JUnit5: test class": { + "prefix": "junit", + "body": [ + "import org.junit.jupiter.api.Test;", + "import static org.junit.jupiter.api.Assertions.*;", + "", + "class ${1:TestName} {", + " @Test", + " void ${2:shouldDoThing}() {", + " $0", + " }", + "}", + "" + ], + "description": "JUnit 5 test class + assertion imports." + }, + "JUnit5: @BeforeEach": { + "prefix": "jbefore", + "body": [ + "@org.junit.jupiter.api.BeforeEach", + "void setUp() {", + " $0", + "}", + "" + ], + "description": "JUnit5 @BeforeEach." + }, + "JUnit5: @AfterEach": { + "prefix": "jafter", + "body": [ + "@org.junit.jupiter.api.AfterEach", + "void tearDown() {", + " $0", + "}", + "" + ], + "description": "JUnit5 @AfterEach." + }, + "JUnit5: assertEquals": { + "prefix": "aeq", + "body": [ + "org.junit.jupiter.api.Assertions.assertEquals(${1:expected}, ${2:actual});", + "$0" + ], + "description": "Assertions.assertEquals." + }, + "JUnit5: assertThrows": { + "prefix": "athrows", + "body": [ + "org.junit.jupiter.api.Assertions.assertThrows(${1:ExceptionType}.class, () -> {", + " $0", + "});" + ], + "description": "Assertions.assertThrows." + }, + "JUnit5: parameterized @ValueSource": { + "prefix": "jparam", + "body": [ + "import org.junit.jupiter.params.ParameterizedTest;", + "import org.junit.jupiter.params.provider.ValueSource;", + "", + "@ParameterizedTest", + "@ValueSource(${1:ints} = { ${2:1}, ${3:2}, ${4:3} })", + "void ${5:shouldWork}(${6:int value}) {", + " $0", + "}", + "" + ], + "description": "JUnit5 parameterized test with ValueSource." + }, + "JUnit5: @Nested": { + "prefix": "jnested", + "body": [ + "@org.junit.jupiter.api.Nested", + "class ${1:WhenSomething} {", + " @org.junit.jupiter.api.Test", + " void ${2:shouldDoX}() {", + " $0", + " }", + "}", + "" + ], + "description": "JUnit5 nested test class." + }, + + "AssertJ: assertThat": { + "prefix": "aj", + "body": [ + "org.assertj.core.api.Assertions.assertThat(${1:actual}).${2:isEqualTo}(${3:expected});", + "$0" + ], + "description": "AssertJ assertThat." + }, + "AssertJ: assertThatThrownBy": { + "prefix": "ajthrow", + "body": [ + "org.assertj.core.api.Assertions.assertThatThrownBy(() -> {", + " $0", + "}).isInstanceOf(${1:ExceptionType}.class);" + ], + "description": "AssertJ assertThatThrownBy." + }, + + "Mockito: mock": { + "prefix": "mmock", + "body": [ + "${1:Type} ${2:mock} = org.mockito.Mockito.mock(${1:Type}.class);", + "$0" + ], + "description": "Create Mockito mock." + }, + "Mockito: when/thenReturn": { + "prefix": "mwhen", + "body": [ + "org.mockito.Mockito.when(${1:mock}.${2:method}(${3:args})).thenReturn(${4:value});", + "$0" + ], + "description": "Mockito stubbing." + }, + "Mockito: verify": { + "prefix": "mverify", + "body": [ + "org.mockito.Mockito.verify(${1:mock}).${2:method}(${3:args});", + "$0" + ], + "description": "Mockito verify call." + }, + "Mockito: ArgumentCaptor": { + "prefix": "mcap", + "body": [ + "org.mockito.ArgumentCaptor<${1:Type}> ${2:captor} = org.mockito.ArgumentCaptor.forClass(${1:Type}.class);", + "org.mockito.Mockito.verify(${3:mock}).${4:method}(${2:captor}.capture());", + "${1:Type} ${5:value} = ${2:captor}.getValue();", + "$0" + ], + "description": "Mockito ArgumentCaptor pattern." + }, + "Spring Boot: @SpringBootApplication main": { + "prefix": "sbapp", + "body": [ + "import org.springframework.boot.SpringApplication;", + "import org.springframework.boot.autoconfigure.SpringBootApplication;", + "", + "@SpringBootApplication", + "public class ${1:Application} {", + " public static void main(String[] args) {", + " SpringApplication.run(${1:Application}.class, args);", + " }", + "}", + "" + ], + "description": "Spring Boot application entry." + }, + "Spring: @RestController": { + "prefix": "sbrest", + "body": [ + "import org.springframework.web.bind.annotation.*;", + "", + "@RestController", + "@RequestMapping(\"/${1:resource}\")", + "public class ${2:Resource}Controller {", + " @GetMapping", + " public ${3:String} index() {", + " return ${4:\"ok\"};", + " }", + "", + " $0", + "}", + "" + ], + "description": "Spring REST controller skeleton." + }, + "Spring: @Service": { + "prefix": "sbservice", + "body": [ + "import org.springframework.stereotype.Service;", + "", + "@Service", + "public class ${1:ServiceName} {", + " $0", + "}", + "" + ], + "description": "Spring @Service skeleton." + }, + "Spring: @Repository": { + "prefix": "sbrepo", + "body": [ + "import org.springframework.stereotype.Repository;", + "", + "@Repository", + "public class ${1:RepositoryName} {", + " $0", + "}", + "" + ], + "description": "Spring @Repository skeleton." + }, + "Spring Data: CrudRepository": { + "prefix": "sbcrud", + "body": [ + "import org.springframework.data.repository.CrudRepository;", + "", + "public interface ${1:RepoName} extends CrudRepository<${2:Entity}, ${3:IdType}> {", + " $0", + "}", + "" + ], + "description": "Spring Data CrudRepository interface." + }, + "Spring: @ControllerAdvice (exception handler)": { + "prefix": "sbadvice", + "body": [ + "import org.springframework.http.*;", + "import org.springframework.web.bind.annotation.*;", + "", + "@ControllerAdvice", + "public class ${1:GlobalExceptionHandler} {", + " @ExceptionHandler(${2:ExceptionType}.class)", + " public ResponseEntity<${3:String}> handle(${2:ExceptionType} e) {", + " return ResponseEntity.status(HttpStatus.${4:BAD_REQUEST}).body(e.getMessage());", + " }", + "}", + "" + ], + "description": "Spring global exception handler." + }, + "JPA: @Entity": { + "prefix": "jpaentity", + "body": [ + "import jakarta.persistence.*;", + "", + "@Entity", + "@Table(name = \"${1:table_name}\")", + "public class ${2:EntityName} {", + " @Id", + " @GeneratedValue(strategy = GenerationType.IDENTITY)", + " private ${3:Long} id;", + "", + " $0", + "}", + "" + ], + "description": "JPA entity skeleton." + }, + "JPA: @Column": { + "prefix": "jpacol", + "body": [ + "@Column(name = \"${1:col}\", nullable = ${2:true})", + "private ${3:Type} ${4:field};", + "$0" + ], + "description": "JPA column field." + }, + "JPA: @ManyToOne": { + "prefix": "jpam2o", + "body": [ + "@ManyToOne(fetch = FetchType.LAZY)", + "@JoinColumn(name = \"${1:other_id}\")", + "private ${2:OtherEntity} ${3:other};", + "$0" + ], + "description": "JPA ManyToOne association." + }, + "JPA: @OneToMany": { + "prefix": "jpao2m", + "body": [ + "@OneToMany(mappedBy = \"${1:owner}\", cascade = CascadeType.ALL, orphanRemoval = true)", + "private java.util.List<${2:ChildEntity}> ${3:children} = new java.util.ArrayList<>();", + "$0" + ], + "description": "JPA OneToMany association." + }, + + "Jakarta Validation: @Valid + @NotNull": { + "prefix": "jvalid", + "body": [ + "import jakarta.validation.Valid;", + "import jakarta.validation.constraints.NotNull;", + "", + "public ${1:void} ${2:method}(@Valid @NotNull ${3:Type} ${4:req}) {", + " $0", + "}", + "" + ], + "description": "Validation annotations template." + }, + + "Lombok: @Data class": { + "prefix": "ldata", + "body": [ + "import lombok.Data;", + "", + "@Data", + "public class ${1:Dto} {", + " private ${2:Type} ${3:field};", + " $0", + "}", + "" + ], + "description": "Lombok @Data class." + }, + "Lombok: @Builder": { + "prefix": "lbuilder", + "body": [ + "import lombok.Builder;", + "import lombok.Value;", + "", + "@Value", + "@Builder", + "public class ${1:ValueType} {", + " ${2:Type} ${3:field};", + " $0", + "}", + "" + ], + "description": "Lombok immutable + builder." + }, + "Pattern: Builder (manual)": { + "prefix": "jbuilder", + "body": [ + "public static class Builder {", + " private ${1:Type} ${2:field};", + "", + " public Builder ${2:field}(${1:Type} ${3:value}) {", + " this.${2:field} = ${3:value};", + " return this;", + " }", + "", + " public ${4:ClassName} build() {", + " return new ${4:ClassName}(this);", + " }", + "}", + "$0" + ], + "description": "Manual builder inner class." + }, + "Pattern: Singleton": { + "prefix": "jsingleton", + "body": [ + "public final class ${1:Singleton} {", + " private static final ${1:Singleton} INSTANCE = new ${1:Singleton}();", + "", + " private ${1:Singleton}() {}", + "", + " public static ${1:Singleton} getInstance() {", + " return INSTANCE;", + " }", + "}", + "" + ], + "description": "Eager singleton pattern." + }, + "Pattern: Factory method": { + "prefix": "jfactory", + "body": [ + "public static ${1:Type} ${2:create}(${3:Args}) {", + " return new ${1:Type}(${4:ctorArgs});", + "}", + "$0" + ], + "description": "Factory method template." + }, + + "Regex: Pattern/Matcher": { + "prefix": "jre", + "body": [ + "java.util.regex.Pattern p = java.util.regex.Pattern.compile(${1:\"\\\\\\\\d+\"});", + "java.util.regex.Matcher m = p.matcher(${2:input});", + "while (m.find()) {", + " $0", + "}" + ], + "description": "Regex Pattern/Matcher loop." + }, + + "DateTime: Instant.now": { + "prefix": "jnowi", + "body": ["java.time.Instant ${1:now} = java.time.Instant.now();", "$0"], + "description": "Instant.now()." + }, + "DateTime: LocalDate.now": { + "prefix": "jnowd", + "body": [ + "java.time.LocalDate ${1:today} = java.time.LocalDate.now();", + "$0" + ], + "description": "LocalDate.now()." + }, + "DateTime: DateTimeFormatter": { + "prefix": "jdtf", + "body": [ + "java.time.format.DateTimeFormatter ${1:fmt} = java.time.format.DateTimeFormatter.ofPattern(${2:\"yyyy-MM-dd\"});", + "String ${3:s} = ${4:date}.format(${1:fmt});", + "$0" + ], + "description": "DateTimeFormatter pattern + format." + } +} diff --git a/snippets/kotlin.json b/snippets/kotlin.json new file mode 100644 index 0000000..39c4257 --- /dev/null +++ b/snippets/kotlin.json @@ -0,0 +1,53 @@ +{ + "Gradle (KTS): Java library skeleton": { + "prefix": "kjava", + "body": [ + "plugins {", + " `java-library`", + "}", + "", + "group = \"${1:com.example}\"", + "version = \"${2:0.1.0}\"", + "", + "repositories {", + " mavenCentral()", + "}", + "", + "dependencies {", + " testImplementation(\"org.junit.jupiter:junit-jupiter:${3:5.10.2}\")", + " testImplementation(\"org.mockito:mockito-core:${4:5.12.0}\")", + " testImplementation(\"org.assertj:assertj-core:${5:3.26.3}\")", + "}", + "", + "tasks.test {", + " useJUnitPlatform()", + "}", + "" + ], + "description": "Gradle Kotlin DSL Java project template with JUnit/Mockito/AssertJ." + }, + "Gradle (KTS): Spring Boot skeleton": { + "prefix": "kspring", + "body": [ + "plugins {", + " java", + " id(\"org.springframework.boot\") version \"${1:3.3.5}\"", + " id(\"io.spring.dependency-management\") version \"${2:1.1.6}\"", + "}", + "", + "group = \"${3:com.example}\"", + "version = \"${4:0.1.0}\"", + "", + "repositories {", + " mavenCentral()", + "}", + "", + "dependencies {", + " implementation(\"org.springframework.boot:spring-boot-starter-web\")", + " testImplementation(\"org.springframework.boot:spring-boot-starter-test\")", + "}", + "" + ], + "description": "Gradle Kotlin DSL Spring Boot template." + } +} From 86a2211c94919ed0271c0982fb2c8c4b84699863 Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:24:25 +1000 Subject: [PATCH 12/13] feat: added snippets for maven for backwards compat Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- snippets/xml.json | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 snippets/xml.json diff --git a/snippets/xml.json b/snippets/xml.json new file mode 100644 index 0000000..7d2e604 --- /dev/null +++ b/snippets/xml.json @@ -0,0 +1,46 @@ +{ + "Maven: pom.xml (basic java + JUnit 5)": { + "prefix": "xpom", + "body": [ + "", + " 4.0.0", + "", + " ${1:com.example}", + " ${2:app}", + " ${3:0.1.0}", + "", + " ", + " ${4:17}", + " ${4:17}", + " ${5:5.10.2}", + " ", + "", + " ", + " ", + " org.junit.jupiter", + " junit-jupiter", + " ${5:5.10.2}", + " test", + " ", + " ", + "", + " ", + " ", + " ", + " org.apache.maven.plugins", + " maven-surefire-plugin", + " ${6:3.3.0}", + " ", + " false", + " ", + " ", + " ", + " ", + "", + "" + ], + "description": "Basic Maven pom.xml with Java 17 + JUnit5 + Surgefire." + } +} From 5fabae1fe37d00374affd9036c0c4f481d1e814b Mon Sep 17 00:00:00 2001 From: Keys <70819367+keys-i@users.noreply.github.com> Date: Mon, 22 Dec 2025 14:33:16 +1000 Subject: [PATCH 13/13] feat: snippets are in a folder now and properly connected Signed-off-by: Keys <70819367+keys-i@users.noreply.github.com> --- extension.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.toml b/extension.toml index 117b6e4..0ca538b 100644 --- a/extension.toml +++ b/extension.toml @@ -10,7 +10,7 @@ authors = [ ] description = "Java support." repository = "https://github.com/zed-extensions/java" -snippets = "snippets.json" +snippets = "./snippets/java.json" [grammars.java] repository = "https://github.com/tree-sitter/tree-sitter-java"