mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Uast: UastEmptyExpression is not a singleton object anymore
This commit is contained in:
@@ -93,7 +93,7 @@ interface UastLanguagePlugin {
|
||||
|
||||
fun getInitializerBody(element: PsiClassInitializer): UExpression {
|
||||
if (element is UClassInitializer) return element.uastBody
|
||||
return (convertElementWithParent(element, null) as? UClassInitializer)?.uastBody ?: UastEmptyExpression
|
||||
return (convertElementWithParent(element, null) as? UClassInitializer)?.uastBody ?: UastEmptyExpression(null)
|
||||
}
|
||||
|
||||
fun getInitializerBody(element: PsiVariable): UExpression? {
|
||||
|
||||
@@ -84,9 +84,7 @@ interface ULabeled : UElement {
|
||||
*
|
||||
* Use [UastEmptyExpression] in this case.
|
||||
*/
|
||||
object UastEmptyExpression : UExpression, JvmDeclarationUElement {
|
||||
override val uastParent: UElement?
|
||||
get() = null
|
||||
open class UastEmptyExpression(override val uastParent: UElement?) : UExpression, JvmDeclarationUElement {
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
@@ -95,4 +93,17 @@ object UastEmptyExpression : UExpression, JvmDeclarationUElement {
|
||||
get() = null
|
||||
|
||||
override fun asLogString() = log()
|
||||
|
||||
override fun hashCode(): Int = uastParent?.hashCode() ?: super.hashCode()
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
if (other is UastEmptyExpression) other.uastParent == uastParent
|
||||
else false
|
||||
|
||||
@Deprecated("create class instance instead")
|
||||
companion object : UastEmptyExpression(null) {
|
||||
@JvmField
|
||||
val INSTANCE: UastEmptyExpression = this
|
||||
}
|
||||
|
||||
}
|
||||
@@ -75,7 +75,7 @@ interface UMethod : UDeclaration, PsiMethod {
|
||||
val body = uastBody
|
||||
append(when (body) {
|
||||
is UBlockExpression -> " " + body.asRenderString()
|
||||
else -> " = " + ((body ?: UastEmptyExpression).asRenderString())
|
||||
else -> " = " + ((body ?: UastEmptyExpression(this@UMethod)).asRenderString())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ internal object JavaConverter {
|
||||
is PsiThrowStatement -> expr<UThrowExpression>(build(::JavaUThrowExpression))
|
||||
is PsiSynchronizedStatement -> expr<UBlockExpression>(build(::JavaUSynchronizedExpression))
|
||||
is PsiTryStatement -> expr<UTryExpression>(build(::JavaUTryExpression))
|
||||
is PsiEmptyStatement -> expr<UExpression> { UastEmptyExpression }
|
||||
is PsiEmptyStatement -> expr<UExpression> { UastEmptyExpression(el.parent?.toUElement()) }
|
||||
is PsiSwitchLabelStatement -> expr<UExpression> {
|
||||
when {
|
||||
givenParent is UExpressionList && givenParent.kind == JavaSpecialExpressionKinds.SWITCH -> findUSwitchEntry(givenParent, el)
|
||||
@@ -335,11 +335,11 @@ internal object JavaConverter {
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(statement: PsiStatement?, parent: UElement?): UExpression {
|
||||
return statement?.let { convertStatement(it, parent, null) } ?: UastEmptyExpression
|
||||
return statement?.let { convertStatement(it, parent, null) } ?: UastEmptyExpression(parent)
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(expression: PsiExpression?, parent: UElement?): UExpression {
|
||||
return expression?.let { convertExpression(it, parent) } ?: UastEmptyExpression
|
||||
return expression?.let { convertExpression(it, parent) } ?: UastEmptyExpression(parent)
|
||||
}
|
||||
|
||||
internal fun convertOrNull(expression: PsiExpression?, parent: UElement?): UExpression? {
|
||||
@@ -347,6 +347,6 @@ internal object JavaConverter {
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(block: PsiCodeBlock?, parent: UElement?): UExpression {
|
||||
return if (block != null) convertBlock(block, parent) else UastEmptyExpression
|
||||
return if (block != null) convertBlock(block, parent) else UastEmptyExpression(parent)
|
||||
}
|
||||
}
|
||||
@@ -38,13 +38,13 @@ class JavaUAnnotation(
|
||||
override fun findAttributeValue(name: String?): UExpression? {
|
||||
val context = getUastContext()
|
||||
val attributeValue = psi.findAttributeValue(name) ?: return null
|
||||
return context.convertElement(attributeValue, this, null) as? UExpression ?: UastEmptyExpression
|
||||
return context.convertElement(attributeValue, this, null) as? UExpression ?: UastEmptyExpression(this)
|
||||
}
|
||||
|
||||
override fun findDeclaredAttributeValue(name: String?): UExpression? {
|
||||
val context = getUastContext()
|
||||
val attributeValue = psi.findDeclaredAttributeValue(name) ?: return null
|
||||
return context.convertElement(attributeValue, this, null) as? UExpression ?: UastEmptyExpression
|
||||
return context.convertElement(attributeValue, this, null) as? UExpression ?: UastEmptyExpression(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -33,7 +33,7 @@ class JavaUClassInitializer(
|
||||
get() = null
|
||||
|
||||
override val uastBody by lz {
|
||||
getLanguagePlugin().convertElement(psi.body, this, null) as? UExpression ?: UastEmptyExpression
|
||||
getLanguagePlugin().convertElement(psi.body, this, null) as? UExpression ?: UastEmptyExpression(this)
|
||||
}
|
||||
|
||||
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
|
||||
|
||||
@@ -134,7 +134,7 @@ open class JavaUEnumConstant(
|
||||
|
||||
override val valueArguments by lz {
|
||||
psi.argumentList?.expressions?.map {
|
||||
getLanguagePlugin().convertElement(it, this) as? UExpression ?: UastEmptyExpression
|
||||
getLanguagePlugin().convertElement(it, this) as? UExpression ?: UastEmptyExpression(this)
|
||||
} ?: emptyList()
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class JavaULambdaExpression(
|
||||
when (b) {
|
||||
is PsiCodeBlock -> JavaConverter.convertBlock(b, this)
|
||||
is PsiExpression -> JavaConverter.convertOrEmpty(b, this)
|
||||
else -> UastEmptyExpression
|
||||
else -> UastEmptyExpression(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,6 @@ class JavaUNamedExpression(
|
||||
get() = psi.name
|
||||
|
||||
override val expression: UExpression by lz {
|
||||
psi.value?.let { value -> JavaConverter.convertPsiElement(value, this) } as? UExpression ?: UastEmptyExpression
|
||||
psi.value?.let { value -> JavaConverter.convertPsiElement(value, this) } as? UExpression ?: UastEmptyExpression(this)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ class JavaUQualifiedReferenceExpression(
|
||||
givenParent: UElement?
|
||||
) : JavaAbstractUExpression(givenParent), UQualifiedReferenceExpression {
|
||||
override val receiver by lz {
|
||||
psi.qualifier?.let { JavaConverter.convertPsiElement(it, this) as? UExpression } ?: UastEmptyExpression
|
||||
psi.qualifier?.let { JavaConverter.convertPsiElement(it, this) as? UExpression } ?: UastEmptyExpression(this)
|
||||
}
|
||||
|
||||
override val selector by lz {
|
||||
|
||||
@@ -22,7 +22,7 @@ UFile (package = ) [public class DoWhile {...]
|
||||
UBlockExpression [{...}] = (var count = Undetermined)
|
||||
UPostfixExpression (operator = ++) [count++] = (var count = Undetermined)
|
||||
USimpleNameReferenceExpression (identifier = count) [count] = (var count = Undetermined)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UBinaryExpression (operator = =) [number = number / 10] = Undetermined (depending on: (var number = Undetermined))
|
||||
USimpleNameReferenceExpression (identifier = number) [number] = (var number = Undetermined)
|
||||
UBinaryExpression (operator = /) [number / 10] = Undetermined (depending on: (var number = Undetermined))
|
||||
|
||||
@@ -22,6 +22,6 @@ UFile (package = ) [public class DoWhileInfinite {...]
|
||||
UBlockExpression [{...}] = (var count = 0)
|
||||
UPostfixExpression (operator = ++) [count++] = (var count = 0)
|
||||
USimpleNameReferenceExpression (identifier = count) [count] = (var count = 0)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UReturnExpression [return count] = Nothing
|
||||
USimpleNameReferenceExpression (identifier = count) [count] = (var count = 0)
|
||||
|
||||
@@ -19,7 +19,7 @@ UFile (package = ) [public class DoWhileWithReturn {...]
|
||||
ULiteralExpression (value = 0) [0] = 0
|
||||
UReturnExpression [return count] = Nothing
|
||||
USimpleNameReferenceExpression (identifier = count) [count] = (var count = 0)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UPostfixExpression (operator = ++) [count++] = Undetermined
|
||||
USimpleNameReferenceExpression (identifier = count) [count] = Undetermined
|
||||
UPostfixExpression (operator = --) [number--] = Undetermined
|
||||
|
||||
@@ -32,7 +32,7 @@ UFile (package = ) [public final enum EnumSwitchConditionalBreak {...]
|
||||
UPostfixExpression (operator = ++) [counter++] = (var counter = 0)
|
||||
USimpleNameReferenceExpression (identifier = counter) [counter] = (var counter = 0)
|
||||
UBreakExpression (label = null) [break] = Nothing(break)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UPostfixExpression (operator = ++) [counter++] = (var counter = 0)
|
||||
USimpleNameReferenceExpression (identifier = counter) [counter] = (var counter = 0)
|
||||
USwitchClauseExpressionWithBody [else -> {...] = Undetermined
|
||||
|
||||
@@ -20,6 +20,6 @@ UFile (package = ) [public class Labeled {...]
|
||||
USimpleNameReferenceExpression (identifier = first) [first] = (var first = 1)
|
||||
ULiteralExpression (value = 0) [0] = 0
|
||||
UBreakExpression (label = labeled) [break@labeled] = Nothing(break)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UReturnExpression [return second] = Nothing
|
||||
USimpleNameReferenceExpression (identifier = second) [second] = (var second = 3)
|
||||
|
||||
@@ -29,7 +29,7 @@ UFile (package = ) [public class LabeledOuter {...]
|
||||
USimpleNameReferenceExpression (identifier = first) [first] = (var first = 1)
|
||||
ULiteralExpression (value = 0) [0] = 0
|
||||
UBreakExpression (label = labeled) [break@labeled] = Nothing(break)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UBinaryExpression (operator = =) [second = 4] = 4
|
||||
USimpleNameReferenceExpression (identifier = second) [second] = Undetermined
|
||||
ULiteralExpression (value = 4) [4] = 4
|
||||
|
||||
@@ -24,7 +24,7 @@ UFile (package = ) [public class WhileWithContinue {...]
|
||||
USimpleNameReferenceExpression (identifier = first) [first] = (var first = 1)
|
||||
ULiteralExpression (value = 0) [0] = 0
|
||||
UContinueExpression (label = null) [continue] = Nothing(continue)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UBinaryExpression (operator = =) [second = 4] = 4
|
||||
USimpleNameReferenceExpression (identifier = second) [second] = Undetermined
|
||||
ULiteralExpression (value = 4) [4] = 4
|
||||
@@ -52,7 +52,7 @@ UFile (package = ) [public class WhileWithContinue {...]
|
||||
USimpleNameReferenceExpression (identifier = first) [first] = (var first = Undetermined)
|
||||
ULiteralExpression (value = 0) [0] = 0
|
||||
UContinueExpression (label = null) [continue] = Nothing(continue)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UBinaryExpression (operator = =) [second = 4] = 4
|
||||
USimpleNameReferenceExpression (identifier = second) [second] = (var second = 3)
|
||||
ULiteralExpression (value = 4) [4] = 4
|
||||
|
||||
@@ -17,6 +17,6 @@ UFile (package = ) [public class WhileWithIncrement {...]
|
||||
ULiteralExpression (value = 42) [42] = 42
|
||||
ULiteralExpression (value = 0) [0] = 0
|
||||
UBreakExpression (label = null) [break] = Nothing(break)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UReturnExpression [return i] = Nothing
|
||||
USimpleNameReferenceExpression (identifier = i) [i] = (var i = Undetermined)
|
||||
|
||||
@@ -22,6 +22,6 @@ UFile (package = ) [public class WhileWithReturn {...]
|
||||
ULiteralExpression (value = 0) [0] = 0
|
||||
UReturnExpression [return second] = Nothing
|
||||
USimpleNameReferenceExpression (identifier = second) [second] = (var second = 3)
|
||||
UastEmptyExpression [UastEmptyExpression] = NON-EVALUATED
|
||||
UastEmptyExpression [UastEmptyExpression] = Undetermined
|
||||
UReturnExpression [return second] = Nothing
|
||||
USimpleNameReferenceExpression (identifier = second) [second] = Undetermined
|
||||
|
||||
@@ -53,7 +53,6 @@ abstract class AbstractJavaRenderLogTest : AbstractJavaUastTest(), RenderLogTest
|
||||
private val parentStack = Stack<UElement>()
|
||||
|
||||
override fun visitElement(node: UElement): Boolean {
|
||||
if (node is UastEmptyExpression) return true // skip UastEmptyExpression they do not have parents (but why?)
|
||||
|
||||
val parent = node.uastParent
|
||||
if (parent == null) {
|
||||
@@ -74,7 +73,6 @@ abstract class AbstractJavaRenderLogTest : AbstractJavaUastTest(), RenderLogTest
|
||||
}
|
||||
|
||||
override fun afterVisitElement(node: UElement) {
|
||||
if (node is UastEmptyExpression) return // skip UastEmptyExpression they do not have parents (but why?)
|
||||
super.afterVisitElement(node)
|
||||
parentStack.pop()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user