diff --git a/ChangeLog.md b/ChangeLog.md index 759faa60ff3..4c234fb0645 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -61,6 +61,7 @@ Issues fixed: - [KT-12148](https://youtrack.jetbrains.com/issue/KT-12148) Warn about object declarations annotated with Spring `@Configuration`/`@Component`/etc. - [KT-12143](https://youtrack.jetbrains.com/issue/KT-12143) Fixed "Spring Facet Code Configuration (Kotlin)" inspection description - [KT-12384](https://youtrack.jetbrains.com/issue/KT-12384) Fixed bean references in factory method calls +- [KT-12120](https://youtrack.jetbrains.com/issue/KT-12120) Show autowiring candidates line markers for @Autowired-annotated constructors and constructor parameters #### Debugger diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt index 231b0b2625e..0116b56c732 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt @@ -25,7 +25,9 @@ import com.intellij.psi.util.CachedValuesManager import com.intellij.psi.util.PsiModificationTracker import com.intellij.util.ArrayUtil import org.jetbrains.annotations.NonNls +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.idea.KotlinLanguage +import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.psi.KtAnnotationEntry import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe @@ -93,9 +95,16 @@ internal fun computeAnnotations(lightElement: PsiModifierList, val cacheManager = CachedValuesManager.getManager(lightElement.project) return cacheManager.createCachedValue>( { - val declaration = (lightElement.parent as? KtLightElement<*, *>)?.kotlinOrigin as? KtDeclaration + val lightOwner = lightElement.parent as? KtLightElement<*, *> + val declaration = lightOwner?.kotlinOrigin as? KtDeclaration val descriptor = declaration?.let { LightClassGenerationSupport.getInstance(lightElement.project).resolveToDescriptor(it) } - val ktAnnotations = descriptor?.annotations?.getAllAnnotations() ?: emptyList() + val annotatedDescriptor = when { + descriptor !is PropertyDescriptor || lightOwner !is KtLightMethod -> descriptor + JvmAbi.isGetterName(lightOwner.name) -> descriptor.getter + JvmAbi.isSetterName(lightOwner.name) -> descriptor.setter + else -> descriptor + } + val ktAnnotations = annotatedDescriptor?.annotations?.getAllAnnotations() ?: emptyList() var nextIndex = 0 val result = delegate.annotations .map { clsAnnotation -> diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java index fde3a881564..aeefd18d03f 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java @@ -100,6 +100,9 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati else if (declaration instanceof KtProperty) { setter = ((KtProperty) declaration).getSetter(); } + else if (declaration instanceof KtParameter) { + return (KtParameter) declaration; + } return setter != null ? setter.getParameter() : null; } diff --git a/ultimate/src/org/jetbrains/kotlin/idea/spring/lineMarking/KotlinSpringClassAnnotator.kt b/ultimate/src/org/jetbrains/kotlin/idea/spring/lineMarking/KotlinSpringClassAnnotator.kt index d608c13e223..9ebb8550345 100644 --- a/ultimate/src/org/jetbrains/kotlin/idea/spring/lineMarking/KotlinSpringClassAnnotator.kt +++ b/ultimate/src/org/jetbrains/kotlin/idea/spring/lineMarking/KotlinSpringClassAnnotator.kt @@ -50,7 +50,11 @@ class KotlinSpringClassAnnotator : SpringClassAnnotator() { } return classForLightMethod?.toLightClass()?.methods?.firstOrNull { (it as? KtLightMethod)?.kotlinOrigin == function } } + psiElement.getParentOfTypeAndBranch> { getConstructorKeyword() ?: getValueParameterList() }?.let { + return it.toLightMethods().firstOrNull() + } psiElement.getParentOfTypeAndBranch { nameIdentifier }?.let { return it } + psiElement.getParentOfTypeAndBranch { nameIdentifier }?.let { if (it.valOrVarKeyword != null) return it } psiElement.getParentOfTypeAndBranch { (typeReference?.typeElement as? KtUserType)?.referenceExpression?.getReferencedNameElement() }?.let { return it.toLightAnnotation() } @@ -58,8 +62,8 @@ class KotlinSpringClassAnnotator : SpringClassAnnotator() { } private fun doCollectMarkers(psiElement: PsiElement, result: MutableCollection>?) { - if (psiElement is KtProperty) { - for (it in psiElement.toLightElements()) { + if (psiElement is KtProperty || psiElement is KtParameter) { + for (it in (psiElement as KtDeclaration).toLightElements()) { val nameIdentifier = (it as? PsiNameIdentifierOwner)?.nameIdentifier ?: continue super.collectNavigationMarkers(nameIdentifier, result) }