From a1efd90896b6ba7b85349c51183e049a07a21d95 Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Thu, 12 Feb 2026 14:56:46 +0100 Subject: [PATCH] feat: allow turning off automatic creation of class body when creating a new java file Signed-off-by: Fred Bricon --- README.md | 1 + package.json | 7 +++++++ src/fileEventHandler.ts | 3 +++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 86afdb001..4c168dea2 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,7 @@ The following settings are supported: * `java.hover.javadoc.enabled` : Enable/disable displaying Javadoc on hover. Defaults to `true`. New in 1.53.0 +* `java.templates.newFile.enabled` : Enable/disable automatic generation of class body and package declaration when creating a new Java file. Set to `false` to create empty Java files. Defaults to `true`. * `java.updateImportsOnPaste.enabled` : Enable/disable auto organize imports when pasting code. Defaults to `true`. Semantic Highlighting diff --git a/package.json b/package.json index b9a2e05c8..156ca9778 100644 --- a/package.json +++ b/package.json @@ -1191,6 +1191,13 @@ "title": "Code Generation", "order": 100, "properties": { + "java.templates.newFile.enabled": { + "type": "boolean", + "default": true, + "markdownDescription": "Enable/disable automatic generation of class body and package declaration when creating a new Java file. Set to `false` to create empty Java files. Defaults to `true`.", + "scope": "window", + "order": 5 + }, "java.templates.fileHeader": { "type": "array", "markdownDescription": "Specifies the file header comment for new Java file. Supports configuring multi-line comments with an array of strings, and using ${variable} to reference the [predefined variables](command:_java.templateVariables).", diff --git a/src/fileEventHandler.ts b/src/fileEventHandler.ts index 52b44ee58..03e950b5a 100644 --- a/src/fileEventHandler.ts +++ b/src/fileEventHandler.ts @@ -47,6 +47,9 @@ export function registerFileEventHandlers(client: LanguageClient, context: Exten } async function handleNewJavaFiles(e: FileCreateEvent) { + if (!getJavaConfiguration().get('templates.newFile.enabled', true)) { + return; + } const emptyFiles: Uri[] = []; const textDocuments: TextDocument[] = []; for (const uri of e.files) {