Spring Support: Show autowiring candidates line markers for @Autowired-annotated constructors and constructor parameters
#KT-12120 Fixed
This commit is contained in:
@@ -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-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-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-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
|
#### Debugger
|
||||||
|
|
||||||
|
|||||||
+11
-2
@@ -25,7 +25,9 @@ import com.intellij.psi.util.CachedValuesManager
|
|||||||
import com.intellij.psi.util.PsiModificationTracker
|
import com.intellij.psi.util.PsiModificationTracker
|
||||||
import com.intellij.util.ArrayUtil
|
import com.intellij.util.ArrayUtil
|
||||||
import org.jetbrains.annotations.NonNls
|
import org.jetbrains.annotations.NonNls
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||||
@@ -93,9 +95,16 @@ internal fun computeAnnotations(lightElement: PsiModifierList,
|
|||||||
val cacheManager = CachedValuesManager.getManager(lightElement.project)
|
val cacheManager = CachedValuesManager.getManager(lightElement.project)
|
||||||
return cacheManager.createCachedValue<Array<out PsiAnnotation>>(
|
return cacheManager.createCachedValue<Array<out PsiAnnotation>>(
|
||||||
{
|
{
|
||||||
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 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
|
var nextIndex = 0
|
||||||
val result = delegate.annotations
|
val result = delegate.annotations
|
||||||
.map { clsAnnotation ->
|
.map { clsAnnotation ->
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
else if (declaration instanceof KtProperty) {
|
else if (declaration instanceof KtProperty) {
|
||||||
setter = ((KtProperty) declaration).getSetter();
|
setter = ((KtProperty) declaration).getSetter();
|
||||||
}
|
}
|
||||||
|
else if (declaration instanceof KtParameter) {
|
||||||
|
return (KtParameter) declaration;
|
||||||
|
}
|
||||||
|
|
||||||
return setter != null ? setter.getParameter() : null;
|
return setter != null ? setter.getParameter() : null;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -50,7 +50,11 @@ class KotlinSpringClassAnnotator : SpringClassAnnotator() {
|
|||||||
}
|
}
|
||||||
return classForLightMethod?.toLightClass()?.methods?.firstOrNull { (it as? KtLightMethod)?.kotlinOrigin == function }
|
return classForLightMethod?.toLightClass()?.methods?.firstOrNull { (it as? KtLightMethod)?.kotlinOrigin == function }
|
||||||
}
|
}
|
||||||
|
psiElement.getParentOfTypeAndBranch<KtConstructor<*>> { getConstructorKeyword() ?: getValueParameterList() }?.let {
|
||||||
|
return it.toLightMethods().firstOrNull()
|
||||||
|
}
|
||||||
psiElement.getParentOfTypeAndBranch<KtProperty> { nameIdentifier }?.let { return it }
|
psiElement.getParentOfTypeAndBranch<KtProperty> { nameIdentifier }?.let { return it }
|
||||||
|
psiElement.getParentOfTypeAndBranch<KtParameter> { nameIdentifier }?.let { if (it.valOrVarKeyword != null) return it }
|
||||||
psiElement.getParentOfTypeAndBranch<KtAnnotationEntry> {
|
psiElement.getParentOfTypeAndBranch<KtAnnotationEntry> {
|
||||||
(typeReference?.typeElement as? KtUserType)?.referenceExpression?.getReferencedNameElement()
|
(typeReference?.typeElement as? KtUserType)?.referenceExpression?.getReferencedNameElement()
|
||||||
}?.let { return it.toLightAnnotation() }
|
}?.let { return it.toLightAnnotation() }
|
||||||
@@ -58,8 +62,8 @@ class KotlinSpringClassAnnotator : SpringClassAnnotator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun doCollectMarkers(psiElement: PsiElement, result: MutableCollection<in RelatedItemLineMarkerInfo<PsiElement>>?) {
|
private fun doCollectMarkers(psiElement: PsiElement, result: MutableCollection<in RelatedItemLineMarkerInfo<PsiElement>>?) {
|
||||||
if (psiElement is KtProperty) {
|
if (psiElement is KtProperty || psiElement is KtParameter) {
|
||||||
for (it in psiElement.toLightElements()) {
|
for (it in (psiElement as KtDeclaration).toLightElements()) {
|
||||||
val nameIdentifier = (it as? PsiNameIdentifierOwner)?.nameIdentifier ?: continue
|
val nameIdentifier = (it as? PsiNameIdentifierOwner)?.nameIdentifier ?: continue
|
||||||
super.collectNavigationMarkers(nameIdentifier, result)
|
super.collectNavigationMarkers(nameIdentifier, result)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user