mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java, completion] IJPL-207762 DiamondInsertHandler is frontend friendly
GitOrigin-RevId: 0ce6ddcf00b66bc2ec7069d33ccd75c5c11072bb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e43e76db71
commit
30c00f792c
@@ -78,5 +78,8 @@
|
||||
<registryKey key="java.formatter.chained.calls.pre212.compatibility"
|
||||
defaultValue="false"
|
||||
description="Format chained calls as in versions prior to 2021.2"/>
|
||||
|
||||
<completion.frontendFriendlyInsertHandler implementationClass="com.intellij.codeInsight.completion.method.DiamondInsertHandler"/>
|
||||
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
+16
@@ -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, "<>")
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -69,7 +69,7 @@ public class JavaMethodCallInsertHandler(
|
||||
*/
|
||||
private val myHandlers: List<InsertHandler<in JavaMethodCallElement>> = listOfNotNull(
|
||||
RefStartInsertHandler(),
|
||||
DiamondInsertHandler(),
|
||||
createDiamondInsertHandler(item),
|
||||
ParenthInsertHandler(),
|
||||
beforeHandler,
|
||||
ImportQualifyAndInsertTypeParametersHandler(needImportOrQualify, needExplicitTypeParameters),
|
||||
@@ -178,12 +178,11 @@ private class RefStartInsertHandler : InsertHandler<LookupElement> {
|
||||
}
|
||||
}
|
||||
|
||||
private class DiamondInsertHandler : InsertHandler<JavaMethodCallElement> {
|
||||
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<LookupElement>? {
|
||||
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<JavaMethodCallElement> {
|
||||
|
||||
Reference in New Issue
Block a user