From 64f639be036f25c78681807cc445b4e5f0ef42bd Mon Sep 17 00:00:00 2001 From: Elena Lyulina Date: Wed, 23 Aug 2023 02:35:58 +0200 Subject: [PATCH] [devkit] IDEA-298703 fix wording, make EP impl internal GitOrigin-RevId: 7d7c0d2a1c1f81c1b69a0fd20e7b585cd76e8aeb --- .../ServiceInstances.kt | 14 ++++++-------- .../StaticProperties.kt | 2 +- .../WrapCompanionObjectPropertyInSupplier.kt | 2 +- .../messages/DevKitKotlinBundle.properties | 2 +- ...pServiceAsStaticFinalFieldOrPropertyProvider.kt | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/ServiceInstances.kt b/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/ServiceInstances.kt index 73e91b52aab0..a9e3029a5fbe 100644 --- a/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/ServiceInstances.kt +++ b/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/ServiceInstances.kt @@ -4,20 +4,18 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.Service import com.intellij.openapi.components.service -interface ServiceInterface +@Service(Service.Level.APP) +class LightApplicationService1 @Service(Service.Level.APP) -class LightApplicationService1 : ServiceInterface - -@Service(Service.Level.APP) -class LightApplicationService2 : ServiceInterface { +class LightApplicationService2 { companion object { - val instance1: LightApplicationService2 + val instance1: LightApplicationService2 get() = service() - val instance2 = service() + val instance2 = service() - val instance3 = ApplicationManager.getApplication().getService(LightApplicationService2::class.java) + val instance3 = ApplicationManager.getApplication().getService(LightApplicationService2::class.java) // not this service instance but still stores a service with a backing field val instance4 = service() diff --git a/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/StaticProperties.kt b/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/StaticProperties.kt index 1fd0ae6464cf..377bc84bd688 100644 --- a/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/StaticProperties.kt +++ b/plugins/devkit/devkit-kotlin-tests/testData/inspections/applicationServiceAsStaticFinalFieldOrProperty/StaticProperties.kt @@ -33,7 +33,7 @@ class AppService(val service3: RegisteredApplicationService = RegisteredApplicat val service6 = RegisteredApplicationService.getInstance() // static property without backing field, but being an instance - val service7: AppService + val service7: AppService get() = service() diff --git a/plugins/devkit/devkit-kotlin-tests/testData/inspections/wrapInSupplierFix/WrapCompanionObjectPropertyInSupplier.kt b/plugins/devkit/devkit-kotlin-tests/testData/inspections/wrapInSupplierFix/WrapCompanionObjectPropertyInSupplier.kt index 9da5b9e4c278..52e0f475f76f 100644 --- a/plugins/devkit/devkit-kotlin-tests/testData/inspections/wrapInSupplierFix/WrapCompanionObjectPropertyInSupplier.kt +++ b/plugins/devkit/devkit-kotlin-tests/testData/inspections/wrapInSupplierFix/WrapCompanionObjectPropertyInSupplier.kt @@ -13,7 +13,7 @@ class MyService { companion object { @MyAnnotation - val companionObjectAppService = ApplicationManager.getApplication().getService(MyService::class.java) + val companionObjectAppService = ApplicationManager.getApplication().getService(MyService::class.java) // to test naming conflicts diff --git a/plugins/devkit/intellij.kotlin.devkit/resources/messages/DevKitKotlinBundle.properties b/plugins/devkit/intellij.kotlin.devkit/resources/messages/DevKitKotlinBundle.properties index 5d9fe3fd57f1..092bcbea6b86 100644 --- a/plugins/devkit/intellij.kotlin.devkit/resources/messages/DevKitKotlinBundle.properties +++ b/plugins/devkit/intellij.kotlin.devkit/resources/messages/DevKitKotlinBundle.properties @@ -25,4 +25,4 @@ inspection.light.service.must.not.be.open.message=Light service must not be open inspection.extension.class.should.not.be.open.text=Extension class should not be open inspections.application.service.as.static.immutable.property.with.backing.field.message=Application service must not be assigned to a static immutable property with a backing field -inspections.an.explicit.method.should.be.used.to.retrieve.an.application.service.message=An explicit 'getInstance()' method should be used to retrieve an application service instead of a property +inspections.an.explicit.method.should.be.used.to.retrieve.an.application.service.message=Provide explicit 'getInstance()' method to access application service instead of a property diff --git a/plugins/devkit/intellij.kotlin.devkit/src/inspections/KtAppServiceAsStaticFinalFieldOrPropertyProvider.kt b/plugins/devkit/intellij.kotlin.devkit/src/inspections/KtAppServiceAsStaticFinalFieldOrPropertyProvider.kt index 19106e2e6f10..ccd4e5069fa2 100644 --- a/plugins/devkit/intellij.kotlin.devkit/src/inspections/KtAppServiceAsStaticFinalFieldOrPropertyProvider.kt +++ b/plugins/devkit/intellij.kotlin.devkit/src/inspections/KtAppServiceAsStaticFinalFieldOrPropertyProvider.kt @@ -40,7 +40,7 @@ import org.jetbrains.uast.toUElementOfType import java.util.function.Supplier -private class KtAppServiceAsStaticFinalFieldOrPropertyVisitorProvider : AppServiceAsStaticFinalFieldOrPropertyVisitorProvider { +internal class KtAppServiceAsStaticFinalFieldOrPropertyVisitorProvider : AppServiceAsStaticFinalFieldOrPropertyVisitorProvider { override fun getVisitor(holder: ProblemsHolder): PsiElementVisitor { return object : KtVisitorVoid() { @@ -66,7 +66,7 @@ private class KtAppServiceAsStaticFinalFieldOrPropertyVisitorProvider : AppServi val anchor = property.nameIdentifier ?: property // a property is used by service implementation to retrieve a service instance - // if it's inside a companion object and returns and instance of containing class + // if it's inside a companion object and returns an instance of containing class val isInstance = property.parentOfType()?.isCompanion() == true && property.containingClass() == typeClassElement