mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
Language Injection: JavaInjectionPerformer which support concatenation
GitOrigin-RevId: 99eaee46ccce0ec89169795752d30b6ef64bcab8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f3d294f06
commit
f4acfc2356
@@ -0,0 +1,60 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.plugins.intelliLang.inject.java
|
||||
|
||||
import com.intellij.lang.injection.MultiHostRegistrar
|
||||
import com.intellij.lang.injection.general.Injection
|
||||
import com.intellij.lang.injection.general.LanguageInjectionPerformer
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.openapi.util.Trinity
|
||||
import com.intellij.openapi.util.component1
|
||||
import com.intellij.openapi.util.component2
|
||||
import com.intellij.psi.ElementManipulators
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiLanguageInjectionHost
|
||||
import com.intellij.psi.impl.source.tree.injected.JavaConcatenationToInjectorAdapter
|
||||
import com.intellij.util.SmartList
|
||||
import org.intellij.plugins.intelliLang.inject.InjectedLanguage
|
||||
import org.intellij.plugins.intelliLang.inject.InjectorUtils
|
||||
|
||||
class JavaInjectionPerformer : LanguageInjectionPerformer {
|
||||
override fun isPrimary(): Boolean = true
|
||||
|
||||
override fun performInjection(registrar: MultiHostRegistrar, injection: Injection, context: PsiElement): Boolean {
|
||||
val injectorAdapter = JavaConcatenationToInjectorAdapter(context.project)
|
||||
val (_, operands) = injectorAdapter.computeAnchorAndOperands(context)
|
||||
|
||||
if (operands.isEmpty()) return false
|
||||
val containingFile = context.containingFile
|
||||
|
||||
val injectedLanguage = InjectedLanguage.create(injection.injectedLanguageId,
|
||||
injection.prefix,
|
||||
injection.suffix, false) ?: return false
|
||||
|
||||
val language = injectedLanguage.language ?: return false
|
||||
|
||||
val trinities = SmartList<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>>()
|
||||
var pendingPrefix = injectedLanguage.prefix
|
||||
for (operand in operands.slice(0 until operands.size - 1)) {
|
||||
if (operand !is PsiLanguageInjectionHost) continue
|
||||
val injectionPart = InjectedLanguage.create(injection.injectedLanguageId,
|
||||
pendingPrefix,
|
||||
null, false) ?: continue
|
||||
pendingPrefix = ""
|
||||
trinities.add(Trinity.create(operand, injectionPart, ElementManipulators.getValueTextRange(operand)))
|
||||
}
|
||||
|
||||
InjectedLanguage.create(injection.injectedLanguageId,
|
||||
pendingPrefix,
|
||||
injectedLanguage.suffix, false)?.let { injectionPart ->
|
||||
val operand = operands.last() as? PsiLanguageInjectionHost ?: return@let
|
||||
trinities.add(Trinity.create(operand, injectionPart, ElementManipulators.getValueTextRange(operand)))
|
||||
}
|
||||
|
||||
InjectorUtils.registerInjection(language, trinities, containingFile, registrar)
|
||||
|
||||
injection.supportId?.let { InjectorUtils.findInjectionSupport(it) }?.let {
|
||||
InjectorUtils.registerSupport(it, false, context, language)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<tipAndTrick file="InjectSQLLanguage.html" feature-id="db.console.run.intention"/>
|
||||
<compileServer.plugin classpath="java-langInjection-jps.jar"/>
|
||||
<languageInjectionPerformer language="JAVA"
|
||||
implementationClass="org.intellij.plugins.intelliLang.inject.java.JavaInjectionPerformer"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="org.intellij.intelliLang">
|
||||
|
||||
Reference in New Issue
Block a user