From 97a0b02cd35fa9207e79f31e5239354a7143c6a7 Mon Sep 17 00:00:00 2001 From: cdgeass Date: Thu, 2 Mar 2023 17:13:02 +0800 Subject: [PATCH] Fix do not use constructor injection error --- idea-plugin/build.gradle | 4 ++++ .../com/alibaba/p3c/idea/component/AliProjectComponent.kt | 5 +++-- .../src/main/kotlin/com/alibaba/p3c/idea/config/P3cConfig.kt | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/idea-plugin/build.gradle b/idea-plugin/build.gradle index 64aa3dbb7..5199079d2 100644 --- a/idea-plugin/build.gradle +++ b/idea-plugin/build.gradle @@ -34,5 +34,9 @@ allprojects { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" testCompile group: 'junit', name: 'junit', version: '4.11' } + + tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + kotlinOptions.jvmTarget = "1.8" + } } diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/component/AliProjectComponent.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/component/AliProjectComponent.kt index 4884ea5fb..4a7daf365 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/component/AliProjectComponent.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/component/AliProjectComponent.kt @@ -41,8 +41,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock * @date 2016/12/13 */ class AliProjectComponent( - private val project: Project, - val p3cConfig: P3cConfig + private val project: Project ) : AliBaseProjectComponent { private val listener: VirtualFileListener private val javaExtension = ".java" @@ -55,6 +54,7 @@ class AliProjectComponent( private val fileContexts = ConcurrentHashMap() init { + val p3cConfig = P3cConfig.getInstance() listener = object : VirtualFileAdapter() { override fun contentsChanged(event: VirtualFileEvent) { val path = getFilePath(event) ?: return @@ -98,6 +98,7 @@ class AliProjectComponent( } override fun initComponent() { + val p3cConfig = P3cConfig.getInstance() I18nResources.changeLanguage(p3cConfig.locale) val analyticsGroup = ActionManager.getInstance().getAction(analyticsGroupId) analyticsGroup.templatePresentation.text = P3cBundle.getMessage(analyticsGroupText) diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/config/P3cConfig.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/config/P3cConfig.kt index 3bbe6f77f..817999e2d 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/config/P3cConfig.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/config/P3cConfig.kt @@ -18,6 +18,7 @@ package com.alibaba.p3c.idea.config import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.components.State import com.intellij.openapi.components.Storage +import com.intellij.openapi.components.service import com.intellij.util.xmlb.XmlSerializerUtil import java.util.Locale @@ -64,5 +65,8 @@ class P3cConfig : PersistentStateComponent { companion object { val localeEn = Locale.ENGLISH.language!! val localeZh = Locale.CHINESE.language!! + + @JvmStatic + fun getInstance(): P3cConfig = service() } }