Spring Support: Consider declaration open if it's supplemented with a preconfigured annotation in corresponding compiler plugin
#KT-15444 Fixed
This commit is contained in:
@@ -892,6 +892,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
||||
- [`KT-15635`](https://youtrack.jetbrains.com/issue/KT-15635) Extract Superclass/Interface: Fix bogus visibility warning inside a member when it's being moved as abstract
|
||||
- [`KT-15598`](https://youtrack.jetbrains.com/issue/KT-15598) Extract Interface: Red-highlight members inherited from a super-interface when that interface reference itself is not extracted
|
||||
- [`KT-15674`](https://youtrack.jetbrains.com/issue/KT-15674) Extract Superclass: Drop inapplicable modifiers when converting property-parameter to ordinary parameter
|
||||
- [`KT-15444`](https://youtrack.jetbrains.com/issue/KT-15444) Spring Support: Consider declaration open if it's supplemented with a preconfigured annotation in corresponding compiler plugin
|
||||
|
||||
#### Intention actions, inspections and quickfixes
|
||||
|
||||
|
||||
+16
-6
@@ -30,6 +30,9 @@ import com.intellij.spring.model.jam.stereotype.SpringConfiguration
|
||||
import com.intellij.spring.model.jam.transaction.SpringTransactionalComponent
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
|
||||
import org.jetbrains.kotlin.idea.spring.isAnnotatedWith
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -37,6 +40,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isInheritable
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isOverridable
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
class KotlinFinalClassOrFunSpringInspection : AbstractKotlinInspection() {
|
||||
class QuickFix<T: KtModifierListOwner>(private val element: T) : LocalQuickFix {
|
||||
@@ -78,14 +82,20 @@ class KotlinFinalClassOrFunSpringInspection : AbstractKotlinInspection() {
|
||||
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
||||
return object: KtVisitorVoid() {
|
||||
override fun visitNamedDeclaration(declaration: KtNamedDeclaration) {
|
||||
when (declaration) {
|
||||
is KtClass -> if (declaration.isInheritable()) return
|
||||
is KtObjectDeclaration -> {}
|
||||
is KtNamedFunction -> if (declaration.isOverridable()) return
|
||||
else -> return
|
||||
private fun KtNamedDeclaration.isOpen(): Boolean {
|
||||
when (this) {
|
||||
is KtClass -> if (isInheritable()) return true
|
||||
is KtObjectDeclaration -> return false
|
||||
is KtNamedFunction -> if (isOverridable()) return true
|
||||
}
|
||||
|
||||
val descriptor = resolveToDescriptor(BodyResolveMode.PARTIAL) as? MemberDescriptor
|
||||
return descriptor?.modality != Modality.FINAL
|
||||
}
|
||||
|
||||
override fun visitNamedDeclaration(declaration: KtNamedDeclaration) {
|
||||
if (declaration.isOpen()) return
|
||||
|
||||
val message = getMessage(declaration) ?: return
|
||||
|
||||
val fixes = if (declaration !is KtObjectDeclaration) arrayOf(QuickFix(declaration)) else LocalQuickFix.EMPTY_ARRAY
|
||||
|
||||
Vendored
-32
@@ -39,22 +39,6 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||
<description>@Bean function should be declared open</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>51</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||
<description>@Bean function should be declared open</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>54</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||
<description>@Bean function should be declared open</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>59</line>
|
||||
@@ -95,22 +79,6 @@
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||
<description>@Transactional function should be declared open</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>82</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||
<description>@Transactional function should be declared open</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>85</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||
<description>@Transactional function should be declared open</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>91</line>
|
||||
|
||||
Reference in New Issue
Block a user