Generate @JvmDefault for property accessors in LIGHT_CLASS MODE

This commit is contained in:
Mikhael Bogdanov
2018-05-22 11:07:26 +02:00
parent 402ceefe60
commit f826a253e3
2 changed files with 19 additions and 6 deletions
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter
import org.jetbrains.kotlin.resolve.AnnotationChecker import org.jetbrains.kotlin.resolve.AnnotationChecker
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.annotations.JVM_DEFAULT_FQ_NAME
import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.resolve.source.getPsi
abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(protected val owner: T) abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, PsiModifierListOwner>>(protected val owner: T)
@@ -138,9 +139,18 @@ private fun getAnnotationDescriptors(declaration: KtDeclaration, annotatedLightE
else -> descriptor else -> descriptor
} ?: return emptyList() } ?: return emptyList()
return annotatedDescriptor.annotations.getAllAnnotations() val annotations = annotatedDescriptor.annotations.getAllAnnotations()
.filter { it.matches(annotatedLightElement) } .filter { it.matches(annotatedLightElement) }
.map { it.annotation } .map { it.annotation }
if (descriptor is PropertyDescriptor) {
val jvmDefault = descriptor.annotations.findAnnotation(JVM_DEFAULT_FQ_NAME)
if (jvmDefault != null) {
return annotations + jvmDefault
}
}
return annotations
} }
private fun hasAnnotationsInSource(declaration: KtDeclaration): Boolean { private fun hasAnnotationsInSource(declaration: KtDeclaration): Boolean {
@@ -6,9 +6,12 @@ interface KotlinInterface {
} }
// @JvmDefault @JvmDefault
// val foo: String var foo: String
// get() = "123" get() = "123"
set(field) {
}
} }