Spring Support: Support @Transactional annotation in "Make annotated declaration open" inspection
This commit is contained in:
+6
-1
@@ -27,6 +27,7 @@ import com.intellij.psi.PsiElementVisitor
|
|||||||
import com.intellij.spring.constants.SpringAnnotationsConstants
|
import com.intellij.spring.constants.SpringAnnotationsConstants
|
||||||
import com.intellij.spring.model.jam.stereotype.SpringComponent
|
import com.intellij.spring.model.jam.stereotype.SpringComponent
|
||||||
import com.intellij.spring.model.jam.stereotype.SpringConfiguration
|
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.toLightClass
|
||||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||||
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
|
import org.jetbrains.kotlin.idea.inspections.AbstractKotlinInspection
|
||||||
@@ -58,12 +59,16 @@ class KotlinFinalClassOrFunSpringInspection : AbstractKotlinInspection() {
|
|||||||
when {
|
when {
|
||||||
SpringConfiguration.META.getJamElement(lightClass) != null -> return "@Configuration class should be declared open"
|
SpringConfiguration.META.getJamElement(lightClass) != null -> return "@Configuration class should be declared open"
|
||||||
SpringComponent.META.getJamElement(lightClass) != null -> return "@Component class should be declared open"
|
SpringComponent.META.getJamElement(lightClass) != null -> return "@Component class should be declared open"
|
||||||
|
SpringTransactionalComponent.META.getJamElement(lightClass) != null -> return "@Transactional class should be declared open"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is KtNamedFunction -> {
|
is KtNamedFunction -> {
|
||||||
val lightMethod = declaration.toLightMethods().firstOrNull() ?: return null
|
val lightMethod = declaration.toLightMethods().firstOrNull() ?: return null
|
||||||
if (lightMethod.isAnnotatedWith(SpringAnnotationsConstants.JAVA_SPRING_BEAN)) return "@Bean function should be declared open"
|
when {
|
||||||
|
lightMethod.isAnnotatedWith(SpringAnnotationsConstants.JAVA_SPRING_BEAN) -> return "@Bean function should be declared open"
|
||||||
|
lightMethod.isAnnotatedWith(SpringAnnotationsConstants.TRANSACTIONAL) -> return "@Transactional function should be declared open"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|||||||
Vendored
+65
-9
@@ -1,7 +1,7 @@
|
|||||||
<problems>
|
<problems>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>18</line>
|
<line>22</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>21</line>
|
<line>25</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>32</line>
|
<line>36</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>41</line>
|
<line>45</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>44</line>
|
<line>48</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>47</line>
|
<line>51</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>50</line>
|
<line>54</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>55</line>
|
<line>59</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Final Kotlin class or function with Spring annotation</problem_class>
|
||||||
@@ -65,10 +65,66 @@
|
|||||||
</problem>
|
</problem>
|
||||||
<problem>
|
<problem>
|
||||||
<file>test.kt</file>
|
<file>test.kt</file>
|
||||||
<line>58</line>
|
<line>62</line>
|
||||||
<module>light_idea_test_case</module>
|
<module>light_idea_test_case</module>
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
<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>
|
<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>
|
<description>@Bean function should be declared open</description>
|
||||||
</problem>
|
</problem>
|
||||||
|
<problem>
|
||||||
|
<file>test.kt</file>
|
||||||
|
<line>74</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 class should be declared open</description>
|
||||||
|
</problem>
|
||||||
|
<problem>
|
||||||
|
<file>test.kt</file>
|
||||||
|
<line>76</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>79</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>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>
|
||||||
|
<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>94</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>
|
||||||
</problems>
|
</problems>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Bean
|
|||||||
import org.springframework.context.annotation.ComponentScan
|
import org.springframework.context.annotation.ComponentScan
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
annotation class MyConfiguration
|
annotation class MyConfiguration
|
||||||
@@ -12,6 +13,9 @@ annotation class MyConfiguration
|
|||||||
@Bean
|
@Bean
|
||||||
annotation class MyBean
|
annotation class MyBean
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
annotation class MyTransactional
|
||||||
|
|
||||||
// @Configuration
|
// @Configuration
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -62,4 +66,36 @@ open class Utils2 {
|
|||||||
|
|
||||||
@MyBean
|
@MyBean
|
||||||
open fun foo4() = Component4()
|
open fun foo4() = Component4()
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Transactional
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
class Trans1 {
|
||||||
|
@Transactional
|
||||||
|
fun foo1() = Component1()
|
||||||
|
|
||||||
|
@MyTransactional
|
||||||
|
fun foo2() = Component2()
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
open fun foo3() = Component3()
|
||||||
|
|
||||||
|
@MyTransactional
|
||||||
|
open fun foo4() = Component4()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
open class Trans2 {
|
||||||
|
@Transactional
|
||||||
|
fun foo1() = Component1()
|
||||||
|
|
||||||
|
@MyTransactional
|
||||||
|
fun foo2() = Component2()
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
open fun foo3() = Component3()
|
||||||
|
|
||||||
|
@MyTransactional
|
||||||
|
open fun foo4() = Component4()
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ class SpringTestFixtureExtension() : TestFixtureExtension {
|
|||||||
enum class SpringFramework(val version: String, vararg val artifactIds: String) {
|
enum class SpringFramework(val version: String, vararg val artifactIds: String) {
|
||||||
FRAMEWORK_4_2_0(
|
FRAMEWORK_4_2_0(
|
||||||
"4.2.0.RELEASE",
|
"4.2.0.RELEASE",
|
||||||
"core", "beans", "context"
|
"core", "beans", "context", "tx"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
<get-spring-library lib="spring-core" version="4.2.0.RELEASE"/>
|
<get-spring-library lib="spring-core" version="4.2.0.RELEASE"/>
|
||||||
<get-spring-library lib="spring-beans" version="4.2.0.RELEASE"/>
|
<get-spring-library lib="spring-beans" version="4.2.0.RELEASE"/>
|
||||||
<get-spring-library lib="spring-context" version="4.2.0.RELEASE"/>
|
<get-spring-library lib="spring-context" version="4.2.0.RELEASE"/>
|
||||||
|
<get-spring-library lib="spring-tx" version="4.2.0.RELEASE"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<!-- Override fetch-third-party from the main buildfile -->
|
<!-- Override fetch-third-party from the main buildfile -->
|
||||||
|
|||||||
Reference in New Issue
Block a user