SLC: implement PsiVariable#computeConstantValue for light field
This commit is contained in:
committed by
Ilya Kirillov
parent
a58e0803fb
commit
fc1eb02590
+1
-1
@@ -38,7 +38,7 @@ internal abstract class SymbolLightField protected constructor(
|
||||
override fun getContainingFile(): PsiFile? = containingClass.containingFile
|
||||
override fun hasInitializer(): Boolean = initializer !== null
|
||||
|
||||
override fun computeConstantValue(): Any? = null //TODO _constantInitializer?.value
|
||||
override fun computeConstantValue(): Any? = null
|
||||
|
||||
override fun computeConstantValue(visitedVars: MutableSet<PsiVariable>?): Any? = computeConstantValue()
|
||||
|
||||
|
||||
+19
-4
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.light.classes.symbol.fields
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.KtConstantInitializerValue
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtConstantValue
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.isValid
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
|
||||
@@ -115,14 +114,30 @@ internal class SymbolLightFieldForProperty(
|
||||
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
private val _initializer by lazyPub {
|
||||
private val _initializerValue by lazyPub {
|
||||
if (propertySymbol !is KtKotlinPropertySymbol) return@lazyPub null
|
||||
val constInitializer = propertySymbol.initializer as? KtConstantInitializerValue ?: return@lazyPub null
|
||||
(constInitializer.constant as? KtConstantValue)?.createPsiLiteral(this)
|
||||
(propertySymbol.initializer as? KtConstantInitializerValue)?.constant
|
||||
}
|
||||
|
||||
private val _initializer by lazyPub {
|
||||
_initializerValue?.createPsiLiteral(this)
|
||||
}
|
||||
|
||||
override fun getInitializer(): PsiExpression? = _initializer
|
||||
|
||||
private val _constantValue by lazyPub {
|
||||
_initializerValue?.value?.takeIf {
|
||||
// val => final
|
||||
propertySymbol.isVal &&
|
||||
// NB: not as?, since _initializerValue already checks that
|
||||
(propertySymbol as KtKotlinPropertySymbol).isConst &&
|
||||
// javac rejects all non-primitive and non String constants
|
||||
(propertySymbol.returnType.isPrimitive || propertySymbol.returnType.isString)
|
||||
}
|
||||
}
|
||||
|
||||
override fun computeConstantValue(): Any? = _constantValue
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
this === other ||
|
||||
(other is SymbolLightFieldForProperty &&
|
||||
|
||||
+2
-2
@@ -3,12 +3,12 @@ public abstract interface TraitClassObjectField /* TraitClassObjectField*/ {
|
||||
public static final TraitClassObjectField.Companion Companion;
|
||||
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
public static final java.lang.String x = "" /* initializer type: java.lang.String */;
|
||||
public static final java.lang.String x = "" /* initializer type: java.lang.String */ /* constant value */;
|
||||
|
||||
|
||||
public static final class Companion /* TraitClassObjectField.Companion*/ {
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
private final java.lang.String x = "" /* initializer type: java.lang.String */;
|
||||
private final java.lang.String x = "" /* initializer type: java.lang.String */ /* constant value */;
|
||||
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
private final java.lang.String y;
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
public final class A /* pack.A*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private static java.lang.String v;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final java.lang.String cv = "A" /* initializer type: java.lang.String */;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final pack.A INSTANCE;
|
||||
|
||||
private static final int c;
|
||||
|
||||
public static final int cc = 1 /* initializer type: int */;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final java.lang.String getV();// getV()
|
||||
|
||||
private A();// .ctor()
|
||||
|
||||
public final int f();// f()
|
||||
|
||||
public final int getC();// getC()
|
||||
|
||||
public final void setV(@org.jetbrains.annotations.NotNull() java.lang.String);// setV(java.lang.String)
|
||||
|
||||
}
|
||||
+14
-14
@@ -121,19 +121,19 @@ public final class ConstContainer /* ConstContainer*/ {
|
||||
public static final ConstContainer INSTANCE;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final java.lang.String str = "one" /* initializer type: java.lang.String */;
|
||||
public static final java.lang.String str = "one" /* initializer type: java.lang.String */ /* constant value one */;
|
||||
|
||||
public static final double complexFloat = 5.118281745910645 /* initializer type: double */;
|
||||
public static final double complexFloat = 5.118281745910645 /* initializer type: double */ /* constant value 5.118281745910645 */;
|
||||
|
||||
public static final double e = 2.7182818284 /* initializer type: double */;
|
||||
public static final double e = 2.7182818284 /* initializer type: double */ /* constant value 2.7182818284 */;
|
||||
|
||||
public static final float eFloat = 2.7182817f /* initializer type: float */;
|
||||
public static final float eFloat = 2.7182817f /* initializer type: float */ /* constant value 2.7182817 */;
|
||||
|
||||
public static final int one = 1 /* initializer type: int */;
|
||||
public static final int one = 1 /* initializer type: int */ /* constant value 1 */;
|
||||
|
||||
public static final long complexLong = 2L /* initializer type: long */;
|
||||
public static final long complexLong = 2L /* initializer type: long */ /* constant value 2 */;
|
||||
|
||||
public static final long oneLong = 1L /* initializer type: long */;
|
||||
public static final long oneLong = 1L /* initializer type: long */ /* constant value 1 */;
|
||||
|
||||
private ConstContainer();// .ctor()
|
||||
|
||||
@@ -144,19 +144,19 @@ public final class ClassWithConstContainer /* ClassWithConstContainer*/ {
|
||||
public static final ClassWithConstContainer.Companion Companion;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final java.lang.String str = "one" /* initializer type: java.lang.String */;
|
||||
public static final java.lang.String str = "one" /* initializer type: java.lang.String */ /* constant value one */;
|
||||
|
||||
public static final double complexFloat = 5.118281745910645 /* initializer type: double */;
|
||||
public static final double complexFloat = 5.118281745910645 /* initializer type: double */ /* constant value 5.118281745910645 */;
|
||||
|
||||
public static final double e = 2.7182818284 /* initializer type: double */;
|
||||
public static final double e = 2.7182818284 /* initializer type: double */ /* constant value 2.7182818284 */;
|
||||
|
||||
public static final float eFloat = 2.7182817f /* initializer type: float */;
|
||||
public static final float eFloat = 2.7182817f /* initializer type: float */ /* constant value 2.7182817 */;
|
||||
|
||||
public static final int one = 1 /* initializer type: int */;
|
||||
public static final int one = 1 /* initializer type: int */ /* constant value 1 */;
|
||||
|
||||
public static final long complexLong = 2L /* initializer type: long */;
|
||||
public static final long complexLong = 2L /* initializer type: long */ /* constant value 2 */;
|
||||
|
||||
public static final long oneLong = 1L /* initializer type: long */;
|
||||
public static final long oneLong = 1L /* initializer type: long */ /* constant value 1 */;
|
||||
|
||||
public ClassWithConstContainer();// .ctor()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
public final class multifileFacade /* multifileFacade*/ {
|
||||
public static final int x1 = 42 /* initializer type: int */;
|
||||
public static final int x1 = 42 /* initializer type: int */ /* constant value 42 */;
|
||||
|
||||
public static final int foo();// foo()
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public final class PropertiesKt /* PropertiesKt*/ {
|
||||
private static java.lang.String x$1 = "" /* initializer type: java.lang.String */;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final java.lang.String SUBSYSTEM_DEPRECATED = "This subsystem is deprecated" /* initializer type: java.lang.String */;
|
||||
public static final java.lang.String SUBSYSTEM_DEPRECATED = "This subsystem is deprecated" /* initializer type: java.lang.String */ /* constant value This subsystem is deprecated */;
|
||||
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
private static java.lang.Boolean isEmptyMutable;
|
||||
|
||||
Reference in New Issue
Block a user