iFrankWang
08/04/2020, 2:24 AMKtNamedFunction
's return type in form like "`xxx.xxx.TestClass`"? I've only managed to get the short class name as "`TestClass`" with code like this:
ktNamedFunction.getTypeReference().getText()
And here's Mapstruct plugin in Github: https://github.com/mapstruct/mapstruct-ideashikasd
08/04/2020, 1:04 PMBindingContext
to retrieve function descriptor and get the KotlinType
from there.
Then you can use it to retrieve class descriptor which contains fqName field you need :)
I am away from the laptop now, but can provide more info later, if needed :)iFrankWang
08/05/2020, 6:55 AMBindingContext
in PsiReferenceProvider
? Here's example code:
public class MappingTargetReferenceProviderKotlin extends PsiReferenceProvider {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
KtNamedFunction ktNamedFunction = PsiTreeUtil.getParentOfType(element, KtNamedFunction.class)
KtTypeReference ktTypeReference = ktNamedFunction.getTypeReference();
// TODO get BindingContext here
}
}
iFrankWang
08/05/2020, 9:50 AMUnresolvedType
from following code, what have i missed?
KtNamedFunction ktFun = PsiTreeUtil.getParentOfType(element, KtNamedFunction.class)
BindingContext bindingContext = ResolutionUtils.analyze(ktFun, BodyResolveMode.FULL);
KotlinType type = bindingContext.get(BindingContext.FUNCTION, ktFun).getReturnType();
shikasd
08/08/2020, 4:15 PMshikasd
08/08/2020, 5:03 PMBodyResolveMode
)shikasd
08/08/2020, 5:10 PMKtNamedFunction.resolveToDescriptorIfAny
, which seems to do similar things, but maybe it works better ¯\_(ツ)_/¯iFrankWang
08/11/2020, 2:25 AMiFrankWang
08/11/2020, 6:09 AMUnresolvedType
because the return type isn't exactly a KotlinType
, it's a Java type. But how can I get a Java return type from KtNamedFunction
? Any idea @shikasd?shikasd
08/11/2020, 6:59 AMiFrankWang
08/11/2020, 7:57 AMPsiMethod
approach), and either Java class or Kotlin class is resolved correctly.