Fixed loading integral constants from compiled classes.
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
package constants
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention
|
||||||
|
import java.lang.annotation.RetentionPolicy
|
||||||
|
|
||||||
|
public val b: Byte = 100
|
||||||
|
public val s: Short = 20000
|
||||||
|
public val i: Int = 2000000
|
||||||
|
public val l: Long = 2000000000000L
|
||||||
|
public val f: Float = 3.14f
|
||||||
|
public val d: Double = 3.14
|
||||||
|
public val bb: Boolean = true
|
||||||
|
public val c: Char = '\u03c0' // pi symbol
|
||||||
|
|
||||||
|
public val str: String = ":)"
|
||||||
|
|
||||||
|
[Retention(RetentionPolicy.RUNTIME)]
|
||||||
|
public annotation class AnnotationClass(public val value: String)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import constants.*
|
||||||
|
|
||||||
|
AnnotationClass("$b $s $i $l $f $d $bb $c $str")
|
||||||
|
class DummyClass()
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val klass = javaClass<DummyClass>()!!
|
||||||
|
val annotationClass = javaClass<AnnotationClass>()
|
||||||
|
val annotation = klass.getAnnotation(annotationClass)!!
|
||||||
|
val value = annotation.value
|
||||||
|
require(value == "100 20000 2000000 2000000000000 3.14 3.14 true \u03c0 :)", "Annotation value: $value")
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
//ALLOW_AST_ACCESS
|
||||||
|
package test
|
||||||
|
|
||||||
|
val b: Byte = 100
|
||||||
|
val b1: Byte = 1
|
||||||
|
val s: Short = 20000
|
||||||
|
val s1: Short = 1
|
||||||
|
val i: Int = 2000000
|
||||||
|
val i1: Short = 1
|
||||||
|
val l: Long = 2000000000000L
|
||||||
|
val l1: Long = 1
|
||||||
|
val f: Float = 3.14f
|
||||||
|
val d: Double = 3.14
|
||||||
|
val bb: Boolean = true
|
||||||
|
val c: Char = '\u03c0' // pi symbol
|
||||||
|
|
||||||
|
val str: String = ":)"
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
internal val b: kotlin.Byte = 100.toByte()
|
||||||
|
internal fun <get-b>(): kotlin.Byte
|
||||||
|
internal val b1: kotlin.Byte = 1.toByte()
|
||||||
|
internal fun <get-b1>(): kotlin.Byte
|
||||||
|
internal val bb: kotlin.Boolean = true
|
||||||
|
internal fun <get-bb>(): kotlin.Boolean
|
||||||
|
internal val c: kotlin.Char = #960(π)
|
||||||
|
internal fun <get-c>(): kotlin.Char
|
||||||
|
internal val d: kotlin.Double = 3.14.toDouble()
|
||||||
|
internal fun <get-d>(): kotlin.Double
|
||||||
|
internal val f: kotlin.Float = 3.14.toFloat()
|
||||||
|
internal fun <get-f>(): kotlin.Float
|
||||||
|
internal val i: kotlin.Int = 2000000
|
||||||
|
internal fun <get-i>(): kotlin.Int
|
||||||
|
internal val i1: kotlin.Short = 1.toShort()
|
||||||
|
internal fun <get-i1>(): kotlin.Short
|
||||||
|
internal val l: kotlin.Long = 2000000000000.toLong()
|
||||||
|
internal fun <get-l>(): kotlin.Long
|
||||||
|
internal val l1: kotlin.Long = 1.toLong()
|
||||||
|
internal fun <get-l1>(): kotlin.Long
|
||||||
|
internal val s: kotlin.Short = 20000.toShort()
|
||||||
|
internal fun <get-s>(): kotlin.Short
|
||||||
|
internal val s1: kotlin.Short = 1.toShort()
|
||||||
|
internal fun <get-s1>(): kotlin.Short
|
||||||
|
internal val str: kotlin.String = ":)"
|
||||||
|
internal fun <get-str>(): kotlin.String
|
||||||
+5
@@ -66,6 +66,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
|
|||||||
doTest("compiler/testData/compileKotlinAgainstKotlin/ImportObject.A.kt");
|
doTest("compiler/testData/compileKotlinAgainstKotlin/ImportObject.A.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InlinedConstants.A.kt")
|
||||||
|
public void testInlinedConstants() throws Exception {
|
||||||
|
doTest("compiler/testData/compileKotlinAgainstKotlin/InlinedConstants.A.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InnerClass.A.kt")
|
@TestMetadata("InnerClass.A.kt")
|
||||||
public void testInnerClass() throws Exception {
|
public void testInnerClass() throws Exception {
|
||||||
doTest("compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt");
|
doTest("compiler/testData/compileKotlinAgainstKotlin/InnerClass.A.kt");
|
||||||
|
|||||||
@@ -2593,6 +2593,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
|||||||
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/prop/CollectionSize.kt");
|
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/prop/CollectionSize.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Constants.kt")
|
||||||
|
public void testConstants() throws Exception {
|
||||||
|
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/prop/Constants.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ExtValClass.kt")
|
@TestMetadata("ExtValClass.kt")
|
||||||
public void testExtValClass() throws Exception {
|
public void testExtValClass() throws Exception {
|
||||||
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/prop/ExtValClass.kt");
|
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/prop/ExtValClass.kt");
|
||||||
|
|||||||
+5
@@ -1061,6 +1061,11 @@ public class LazyResolveRecursiveComparingTestGenerated extends AbstractLazyReso
|
|||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/CollectionSize.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/CollectionSize.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Constants.kt")
|
||||||
|
public void testConstants() throws Exception {
|
||||||
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/Constants.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ExtValClass.kt")
|
@TestMetadata("ExtValClass.kt")
|
||||||
public void testExtValClass() throws Exception {
|
public void testExtValClass() throws Exception {
|
||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/ExtValClass.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/ExtValClass.kt");
|
||||||
|
|||||||
+30
-1
@@ -87,9 +87,38 @@ public class DescriptorDeserializersStorage {
|
|||||||
@Override
|
@Override
|
||||||
public KotlinJvmBinaryClass.AnnotationVisitor visitField(@NotNull Name name, @NotNull String desc, @Nullable Object initializer) {
|
public KotlinJvmBinaryClass.AnnotationVisitor visitField(@NotNull Name name, @NotNull String desc, @Nullable Object initializer) {
|
||||||
MemberSignature signature = MemberSignature.fromFieldNameAndDesc(name, desc);
|
MemberSignature signature = MemberSignature.fromFieldNameAndDesc(name, desc);
|
||||||
|
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
|
Object normalizedValue;
|
||||||
|
if ("ZBCS".contains(desc)) {
|
||||||
|
int intValue = ((Integer) initializer).intValue();
|
||||||
|
if ("Z".equals(desc)) {
|
||||||
|
normalizedValue = intValue != 0;
|
||||||
|
}
|
||||||
|
else if ("B".equals(desc)) {
|
||||||
|
normalizedValue = ((byte) intValue);
|
||||||
|
}
|
||||||
|
else if ("C".equals(desc)) {
|
||||||
|
normalizedValue = ((char) intValue);
|
||||||
|
}
|
||||||
|
else if ("S".equals(desc)) {
|
||||||
|
normalizedValue = ((short) intValue);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new AssertionError(desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
normalizedValue = initializer;
|
||||||
|
}
|
||||||
|
|
||||||
propertyConstants.put(signature, ConstantsPackage.createCompileTimeConstant(
|
propertyConstants.put(signature, ConstantsPackage.createCompileTimeConstant(
|
||||||
initializer, /* canBeUsedInAnnotation */ true, /* isPureIntConstant */ true, /* usesVariableAsConstant */ true, /* expectedType */ null));
|
normalizedValue,
|
||||||
|
/* canBeUsedInAnnotation */ true,
|
||||||
|
/* isPureIntConstant */ true,
|
||||||
|
/* usesVariableAsConstant */ true,
|
||||||
|
/* expectedType */ null
|
||||||
|
));
|
||||||
}
|
}
|
||||||
return new MemberAnnotationVisitor(signature);
|
return new MemberAnnotationVisitor(signature);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1061,6 +1061,11 @@ public class LazyResolveByStubTestGenerated extends AbstractLazyResolveByStubTes
|
|||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/CollectionSize.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/CollectionSize.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Constants.kt")
|
||||||
|
public void testConstants() throws Exception {
|
||||||
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/Constants.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ExtValClass.kt")
|
@TestMetadata("ExtValClass.kt")
|
||||||
public void testExtValClass() throws Exception {
|
public void testExtValClass() throws Exception {
|
||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/ExtValClass.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/ExtValClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user