data class OrderRequest(
val orderType: OrderType,
)
expect enum class OrderType {
ASC,
DESC,
}
When parse OrderRequest using PSI API, PsiUtil.resolveClassInClassTypeOnly(type) return null, but when I remove the keywords expect as the following ,it do not return null.
enum class OrderType {
ASC,
DESC,
}
so when I get the PsiType for the field, how I can judge it is enum.
when I use ((PsiClassType) psiType).resolve().isEnum() it return false.
It seems that you deal with kotlin code through java API. That’s possible generally because of java-kotlin interop which is based on “light classes”. But this interop works for jvm projects and it doesn’t exists in kmp by default. “expect” means that you probably inside common code though. Could you please provide more details about your project and how do you parse/get type to call PsiUtil’s method.
I have no demo, but you can get new kt class like mine. And use PSI api to get psiClass of OrderRequest and then use psiClass.getAllFields() to get the type of property. Then use code ((PsiClassType) psiType).resolve().isEnum()
Do you call KtFile#getClasses then or how do you retrieve PsiClass from kotlin file? Is your project KMP project? And where do you place your kotlin file with expect keyword?
// how to get PsiClass
//PsiType psiType
PsiClassReferenceType t = (PsiClassReferenceType) PsiUtil.extractIterableTypeParameter(psiType,false);
PsiClass psiClass = t.resolve();