KT-35536: Fix enum constants in KAPT
Enum constants are Pair, so make sure to unpack them correctly.
This commit is contained in:
committed by
Yan Zhulanow
parent
62924ddcd4
commit
eab6864269
+17
@@ -47,7 +47,9 @@ import org.jetbrains.kotlin.kapt3.stubs.ErrorTypeCorrector.TypeKind.METHOD_PARAM
|
||||
import org.jetbrains.kotlin.kapt3.stubs.ErrorTypeCorrector.TypeKind.RETURN_TYPE
|
||||
import org.jetbrains.kotlin.kapt3.util.*
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace
|
||||
@@ -1194,6 +1196,21 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
||||
|
||||
treeMaker.Select(treeMaker.Type(enumType), treeMaker.name(valueName))
|
||||
}
|
||||
is Pair<*, *> -> {
|
||||
assert(value.first is ClassId)
|
||||
assert(value.second is Name)
|
||||
val valueName = with((value.second as Name).identifier) {
|
||||
if (isValidIdentifier(this)) {
|
||||
this
|
||||
} else {
|
||||
kaptContext.compiler.log.report(kaptContext.kaptError("'$this' is an invalid Java enum value name"))
|
||||
"InvalidFieldName"
|
||||
}
|
||||
}
|
||||
val asSingleFqName = (value.first as ClassId).asSingleFqName()
|
||||
|
||||
treeMaker.Select(treeMaker.FqName(asSingleFqName), treeMaker.name(value.second.toString()))
|
||||
}
|
||||
is List<*> -> treeMaker.NewArray(null, JavacList.nil(), mapJList(value) { convertLiteralExpression(it) })
|
||||
|
||||
is Type -> treeMaker.Select(treeMaker.Type(value), treeMaker.name("class"))
|
||||
|
||||
@@ -21,4 +21,13 @@ object Foo {
|
||||
object Boo {
|
||||
val z = foo()
|
||||
fun foo() = "abc"
|
||||
}
|
||||
|
||||
class HavingState {
|
||||
val state = State.START
|
||||
}
|
||||
|
||||
enum class State {
|
||||
START,
|
||||
FINISH,
|
||||
}
|
||||
+34
@@ -116,3 +116,37 @@ public final class Foo {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class HavingState {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private final State state = State.START;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final State getState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public HavingState() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public enum State {
|
||||
/*public static final*/ START /* = new State() */,
|
||||
/*public static final*/ FINISH /* = new State() */;
|
||||
|
||||
State() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user