Properly calculate isConst for java properties
This commit is contained in:
+3
@@ -12,6 +12,9 @@ public class JClass {
|
||||
public final static char PrimitiveChar = 'K';
|
||||
public final static String Str = ":J";
|
||||
|
||||
@Nullable
|
||||
public final static String StrNullable = "nullable";
|
||||
|
||||
@NotNull
|
||||
public final static Integer BoxedInt = 9500;
|
||||
|
||||
|
||||
+10
-3
@@ -1,6 +1,9 @@
|
||||
object KoKobject {
|
||||
@JvmStatic
|
||||
@JvmField
|
||||
val JvmStatic: Int = 1
|
||||
|
||||
@JvmField
|
||||
val JvmStaticString: String? = "123"
|
||||
}
|
||||
|
||||
fun test() {
|
||||
@@ -20,10 +23,12 @@ fun test() {
|
||||
|
||||
JClass.BoxedInt
|
||||
JClass.NonFinal
|
||||
JClass.StrNullable
|
||||
|
||||
JClass().NonStatic
|
||||
|
||||
KoKobject.JvmStatic
|
||||
KoKobject.JvmStaticString
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
@@ -42,6 +47,8 @@ fun test() {
|
||||
// 1 GETSTATIC JClass.BoxedInt : Ljava/lang/Integer;
|
||||
// 1 GETSTATIC JClass.NonFinal : I
|
||||
// 1 GETFIELD JClass.NonStatic : I
|
||||
// 1 INVOKESTATIC KoKobject.getJvmStatic \(\)I
|
||||
// 1 LDC "nullable"
|
||||
// 1 GETSTATIC KoKobject.JvmStatic : I
|
||||
// 1 GETSTATIC KoKobject.JvmStaticString : Ljava/lang/String
|
||||
// 3 POP2
|
||||
// 16 POP
|
||||
// 18 POP
|
||||
+5
-1
@@ -18,11 +18,13 @@ package org.jetbrains.kotlin.load.java.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.load.java.typeEnhancement.TypeEnhancementKt;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
@@ -110,6 +112,8 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja
|
||||
|
||||
@Override
|
||||
public boolean isConst() {
|
||||
return isStaticFinal && ConstUtil.canBeUsedForConstVal(getType());
|
||||
KotlinType type = getType();
|
||||
return isStaticFinal && ConstUtil.canBeUsedForConstVal(type) &&
|
||||
(!TypeEnhancementKt.hasEnhancedNullability(type) || KotlinBuiltIns.isString(type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,10 @@ package org.jetbrains.kotlin.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
object ConstUtil {
|
||||
@JvmStatic fun canBeUsedForConstVal(type: KotlinType) = type.canBeUsedForConstVal()
|
||||
}
|
||||
|
||||
fun KotlinType.canBeUsedForConstVal() = KotlinBuiltIns.isPrimitiveType(this) || KotlinBuiltIns.isString(this)
|
||||
fun KotlinType.canBeUsedForConstVal() = KotlinBuiltIns.isPrimitiveType(this) && !TypeUtils.isNullableType(this) || KotlinBuiltIns.isString(this)
|
||||
|
||||
Reference in New Issue
Block a user