mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[uast] UInjectionHost introduced (KT-27283)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.uast.expressions
|
||||
|
||||
import com.intellij.psi.PsiLanguageInjectionHost
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.uast.UExpression
|
||||
|
||||
/**
|
||||
* Represents a "string-like" elements in the host language (String literals, interpolated strings, comments)
|
||||
* where other languages could be injected by [com.intellij.psi.LanguageInjector]
|
||||
* or references contributed by [com.intellij.psi.PsiReferenceProvider]
|
||||
*
|
||||
* @see com.intellij.psi.UastReferenceProvider
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
interface UInjectionHost : UExpression {
|
||||
|
||||
val isString: Boolean
|
||||
get() = evaluateToString() != null
|
||||
|
||||
fun evaluateToString(): String? = evaluate() as? String
|
||||
|
||||
val psiLanguageInjectionHost: PsiLanguageInjectionHost
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.java.expressions.JavaUAnnotationCallExpression
|
||||
@@ -241,7 +242,7 @@ internal object JavaConverter {
|
||||
is PsiParenthesizedExpression -> expr<UParenthesizedExpression>(build(::JavaUParenthesizedExpression))
|
||||
is PsiPrefixExpression -> expr<UPrefixExpression>(build(::JavaUPrefixExpression))
|
||||
is PsiPostfixExpression -> expr<UPostfixExpression>(build(::JavaUPostfixExpression))
|
||||
is PsiLiteralExpression -> expr<ULiteralExpression>(build(::JavaULiteralExpression))
|
||||
is PsiLiteralExpressionImpl -> expr<ULiteralExpression>(build(::JavaULiteralExpression))
|
||||
is PsiMethodReferenceExpression -> expr<UCallableReferenceExpression>(build(::JavaUCallableReferenceExpression))
|
||||
is PsiReferenceExpression -> convertReference(el, givenParent, requiredType)
|
||||
is PsiThisExpression -> expr<UThisExpression>(build(::JavaUThisExpression))
|
||||
|
||||
@@ -15,14 +15,23 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiLiteralExpression
|
||||
import com.intellij.psi.PsiLanguageInjectionHost
|
||||
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULiteralExpression
|
||||
import org.jetbrains.uast.expressions.UInjectionHost
|
||||
|
||||
class JavaULiteralExpression(
|
||||
override val psi: PsiLiteralExpression,
|
||||
override val psi: PsiLiteralExpressionImpl,
|
||||
givenParent: UElement?
|
||||
) : JavaAbstractUExpression(givenParent), ULiteralExpression {
|
||||
) : JavaAbstractUExpression(givenParent), ULiteralExpression, UInjectionHost {
|
||||
override fun evaluate(): Any? = psi.value
|
||||
override val value: Any? by lz { evaluate() }
|
||||
|
||||
override val isString: Boolean
|
||||
get() = super<UInjectionHost>.isString
|
||||
|
||||
override val psiLanguageInjectionHost: PsiLanguageInjectionHost
|
||||
get() = psi
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user