diff --git a/java/java-frontback-impl/resource/intellij.java.frontback.impl.xml b/java/java-frontback-impl/resource/intellij.java.frontback.impl.xml
index e6bd9db444b7..a518f2939700 100644
--- a/java/java-frontback-impl/resource/intellij.java.frontback.impl.xml
+++ b/java/java-frontback-impl/resource/intellij.java.frontback.impl.xml
@@ -78,5 +78,8 @@
+
+
+
diff --git a/java/java-frontback-impl/src/com/intellij/codeInsight/completion/method/DiamondInsertHandler.kt b/java/java-frontback-impl/src/com/intellij/codeInsight/completion/method/DiamondInsertHandler.kt
new file mode 100644
index 000000000000..cdf18e05e074
--- /dev/null
+++ b/java/java-frontback-impl/src/com/intellij/codeInsight/completion/method/DiamondInsertHandler.kt
@@ -0,0 +1,16 @@
+// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+package com.intellij.codeInsight.completion.method
+
+import com.intellij.codeInsight.completion.FrontendFriendlyInsertHandler
+import com.intellij.codeInsight.completion.InsertionContext
+import com.intellij.codeInsight.lookup.LookupElement
+import kotlinx.serialization.Serializable
+import org.jetbrains.annotations.ApiStatus
+
+@ApiStatus.Internal
+@Serializable
+class DiamondInsertHandler : FrontendFriendlyInsertHandler {
+ override fun handleInsert(context: InsertionContext, item: LookupElement) {
+ context.document.insertString(context.tailOffset, "<>")
+ }
+}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallInsertHandler.kt b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallInsertHandler.kt
index 37876a617b27..c938013ad68a 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallInsertHandler.kt
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaMethodCallInsertHandler.kt
@@ -69,7 +69,7 @@ public class JavaMethodCallInsertHandler(
*/
private val myHandlers: List> = listOfNotNull(
RefStartInsertHandler(),
- DiamondInsertHandler(),
+ createDiamondInsertHandler(item),
ParenthInsertHandler(),
beforeHandler,
ImportQualifyAndInsertTypeParametersHandler(needImportOrQualify, needExplicitTypeParameters),
@@ -178,12 +178,11 @@ private class RefStartInsertHandler : InsertHandler {
}
}
-private class DiamondInsertHandler : InsertHandler {
- override fun handleInsert(context: InsertionContext, item: JavaMethodCallElement) {
- val method = item.getObject().takeIf { it.isConstructor } ?: return
- if (method.containingClass?.typeParameters?.isNotEmpty() != true) return
- context.document.insertString(context.tailOffset, "<>")
- }
+private fun createDiamondInsertHandler(item: JavaMethodCallElement): InsertHandler? {
+ val method = item.getObject().takeIf { it.isConstructor } ?: return null
+ val containingClass = method.containingClass ?: return null
+ if (containingClass.typeParameters.isEmpty()) return null
+ return DiamondInsertHandler()
}
private class ParenthInsertHandler : InsertHandler {