SpringKotlinAutowiringInspection: workaround for nameless property (EA-104960)
This commit is contained in:
committed by
asedunov
parent
f7a1c71b54
commit
1b2e28d467
+9
-8
@@ -69,7 +69,7 @@ class SpringKotlinAutowiringInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||||
val modifierListOwner = elementPointer.element ?: return
|
val modifierListOwner = elementPointer.element ?: return
|
||||||
if(!FileModificationService.getInstance().preparePsiElementForWrite(modifierListOwner)) return
|
if (!FileModificationService.getInstance().preparePsiElementForWrite(modifierListOwner)) return
|
||||||
if (beanPointers.isEmpty()) return
|
if (beanPointers.isEmpty()) return
|
||||||
|
|
||||||
val defaultBeanName = with(beanPointers.first().name) { if (isNullOrBlank()) "Unknown" else this }
|
val defaultBeanName = with(beanPointers.first().name) { if (isNullOrBlank()) "Unknown" else this }
|
||||||
@@ -129,13 +129,13 @@ class SpringKotlinAutowiringInspection : AbstractKotlinInspection() {
|
|||||||
?: return@registerWithElementsUnwrapped qf
|
?: return@registerWithElementsUnwrapped qf
|
||||||
AddQualifierFix(modifierListOwner, beanPointers, annotationFqName)
|
AddQualifierFix(modifierListOwner, beanPointers, annotationFqName)
|
||||||
}
|
}
|
||||||
catch(e: Exception) {
|
catch (e: Exception) {
|
||||||
return@registerWithElementsUnwrapped null
|
return@registerWithElementsUnwrapped null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T: PsiMember> T.processLightMember(
|
private fun <T : PsiMember> T.processLightMember(
|
||||||
action: T.(holder: ProblemsHolder, model: CommonSpringModel, required: Boolean) -> Unit
|
action: T.(holder: ProblemsHolder, model: CommonSpringModel, required: Boolean) -> Unit
|
||||||
) {
|
) {
|
||||||
val model = SpringAutowireUtil.getProcessingSpringModel(containingClass) ?: return
|
val model = SpringAutowireUtil.getProcessingSpringModel(containingClass) ?: return
|
||||||
@@ -166,12 +166,13 @@ class SpringKotlinAutowiringInspection : AbstractKotlinInspection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitProperty(property: KtProperty) {
|
override fun visitProperty(property: KtProperty) {
|
||||||
for (lightElement in property.toLightElements()) {
|
if (property.name != null) // It is here because `lightElement.name` returns `<no name provided>` instead of `null` suddenly
|
||||||
when (lightElement) {
|
for (lightElement in property.toLightElements()) {
|
||||||
is KtLightMethod -> lightElement.processLightMethod()
|
when (lightElement) {
|
||||||
is KtLightField -> lightElement.processLightField()
|
is KtLightMethod -> lightElement.processLightMethod()
|
||||||
|
is KtLightField -> lightElement.processLightField()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassOrObject(classOrObject: KtClassOrObject) {
|
override fun visitClassOrObject(classOrObject: KtClassOrObject) {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import org.springframework.context.annotation.ComponentScan
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan
|
||||||
|
open class InvalidAutowiredByTypeQualifiers
|
||||||
|
|
||||||
|
abstract class AbstractBarBean
|
||||||
|
@Component
|
||||||
|
open class BarBean1 : AbstractBarBean()
|
||||||
|
@Component
|
||||||
|
open class BarBean2 : AbstractBarBean()
|
||||||
|
|
||||||
|
@Component
|
||||||
|
open class IncompleteClassAutowiring() {
|
||||||
|
@Autowired
|
||||||
|
lateinit var : String
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user