diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerWorkspaceSettings.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerWorkspaceSettings.kt index 3488617acb2..078a5edb101 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerWorkspaceSettings.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerWorkspaceSettings.kt @@ -1,32 +1,17 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.compiler.configuration -import com.intellij.openapi.components.PersistentStateComponent -import com.intellij.openapi.components.State -import com.intellij.openapi.components.Storage -import com.intellij.openapi.components.StoragePathMacros +import com.intellij.openapi.components.* +import com.intellij.openapi.project.Project import com.intellij.util.xmlb.XmlSerializerUtil @State( name = "KotlinCompilerWorkspaceSettings", - storages = arrayOf( - Storage(file = StoragePathMacros.WORKSPACE_FILE) - ) + storages = [Storage(file = StoragePathMacros.WORKSPACE_FILE)] ) class KotlinCompilerWorkspaceSettings : PersistentStateComponent { /** @@ -44,4 +29,10 @@ class KotlinCompilerWorkspaceSettings : PersistentStateComponent = scriptDependenciesManager.getAllScriptsDependenciesClassFiles().toList() + override fun calcClassRoots(): List = ScriptDependenciesManager.getInstance(project) + .getAllScriptsDependenciesClassFiles().toList() override fun findClass(qualifiedName: String, scope: GlobalSearchScope): PsiClass? { tailrec fun findClassInner(parentQualifier: String, inners: List = emptyList()): PsiClass? { @@ -39,7 +27,7 @@ class KotlinScriptDependenciesClassFinder( val parentClass = super.findClass(parentQualifier, scope) if (parentClass != null) { if (inners.isNotEmpty()) { - val innerClass = inners.fold(parentClass) { c: PsiClass?, name: String -> + val innerClass = inners.fold(parentClass) { c: PsiClass?, name: String -> c?.findInnerClassByName(name, false) } if (innerClass != null) return innerClass diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt index f96e3e67fb5..e3954f77d31 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinBuildProcessParametersProvider.kt @@ -1,31 +1,20 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.compiler.configuration import com.intellij.compiler.server.BuildProcessParametersProvider +import com.intellij.openapi.project.Project import com.intellij.openapi.util.registry.Registry import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.idea.PluginStartupComponent -class KotlinBuildProcessParametersProvider( - private val compilerWorkspaceSettings: KotlinCompilerWorkspaceSettings, - private val kotlinPluginStartupComponent: PluginStartupComponent -) : BuildProcessParametersProvider() { +class KotlinBuildProcessParametersProvider(private val project: Project) : BuildProcessParametersProvider() { override fun getVMArguments(): MutableList { + val compilerWorkspaceSettings = KotlinCompilerWorkspaceSettings.getInstance(project) + val res = arrayListOf() if (compilerWorkspaceSettings.preciseIncrementalEnabled) { res.add("-D" + IncrementalCompilation.INCREMENTAL_COMPILATION_JVM_PROPERTY + "=true") @@ -39,7 +28,7 @@ class KotlinBuildProcessParametersProvider( if (Registry.`is`("kotlin.jps.instrument.bytecode", false)) { res.add("-Dkotlin.jps.instrument.bytecode=true") } - kotlinPluginStartupComponent.aliveFlagPath.let { + PluginStartupComponent.getInstance().aliveFlagPath.let { if (!it.isBlank()) { // TODO: consider taking the property name from compiler/daemon/common (check whether dependency will be not too heavy) res.add("-Dkotlin.daemon.client.alive.path=\"$it\"") diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt index 37699b0517b..de416ef15ae 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinSetupEnvironmentNotificationProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2000-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -16,6 +16,7 @@ import com.intellij.openapi.roots.ModuleRootListener import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService +import com.intellij.openapi.startup.StartupActivity import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.openapi.ui.popup.ListPopup import com.intellij.openapi.ui.popup.PopupStep @@ -34,16 +35,16 @@ import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.versions.SuppressNotificationState import org.jetbrains.kotlin.idea.versions.UnsupportedAbiVersionNotificationPanelProvider import org.jetbrains.kotlin.idea.versions.createComponentActionLabel -import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.platform.jvm.isJvm +import org.jetbrains.kotlin.psi.KtFile // Code is partially copied from com.intellij.codeInsight.daemon.impl.SetupSDKNotificationProvider -class KotlinSetupEnvironmentNotificationProvider( - private val myProject: Project, - notifications: EditorNotifications) : EditorNotifications.Provider() { +class KotlinSetupEnvironmentNotificationProvider(private val myProject: Project) : EditorNotifications.Provider(), + StartupActivity { - init { - myProject.messageBus.connect(myProject).subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener { + override fun runActivity(project: Project) { + val notifications = EditorNotifications.getInstance(project) + project.messageBus.connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener { override fun rootsChanged(event: ModuleRootEvent) { notifications.updateAllNotifications() } @@ -109,13 +110,12 @@ class KotlinSetupEnvironmentNotificationProvider( return EditorNotificationPanel().apply { setText("Kotlin not configured") val configurators = getAbleToRunConfigurators(module).toList() - if (!configurators.isEmpty()) { + if (configurators.isNotEmpty()) { createComponentActionLabel("Configure") { label -> val singleConfigurator = configurators.singleOrNull() if (singleConfigurator != null) { singleConfigurator.apply(module.project) - } - else { + } else { val configuratorsPopup = createConfiguratorsPopup(module.project, configurators) configuratorsPopup.showUnderneathOf(label) } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjector.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjector.kt index 192ac2b7253..b2655ff3495 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjector.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/injection/KotlinLanguageInjector.kt @@ -53,10 +53,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs class KotlinLanguageInjector( - private val configuration: Configuration, - private val project: Project, - private val temporaryPlacesRegistry: TemporaryPlacesRegistry + private val project: Project ) : MultiHostInjector { + private val configuration get() = Configuration.getProjectInstance(project) + companion object { private val STRING_LITERALS_REGEXP = "\"([^\"]*)\"".toRegex() private val ABSENT_KOTLIN_INJECTION = BaseInjection("ABSENT_KOTLIN_BASE_INJECTION") @@ -143,7 +143,7 @@ class KotlinLanguageInjector( ): BaseInjection? { val containingFile = ktHost.containingFile - val tempInjectedLanguage = temporaryPlacesRegistry.getLanguageFor(ktHost, containingFile) + val tempInjectedLanguage = TemporaryPlacesRegistry.getInstance(project).getLanguageFor(ktHost, containingFile) if (tempInjectedLanguage != null) { InjectorUtils.putInjectedFileUserData(registrar, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage) return BaseInjection(support.id).apply { @@ -389,25 +389,18 @@ class KotlinLanguageInjector( return InjectionInfo(id, prefix, suffix) } - private val injectableTargetClassShortNames = CachedValuesManager.getManager(project) - .createCachedValue({ - CachedValueProvider.Result.create(HashSet().apply { - for (injection in configuration.getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID)) { - for (injectionPlace in injection.injectionPlaces) { - for (targetClassFQN in retrieveJavaPlaceTargetClassesFQNs(injectionPlace)) { - add(StringUtilRt.getShortName(targetClassFQN)) - } - } - } - for (injection in configuration.getInjections(KOTLIN_SUPPORT_ID)) { - for (injectionPlace in injection.injectionPlaces) { - for (targetClassFQN in retrieveKotlinPlaceTargetClassesFQNs(injectionPlace)) { - add(StringUtilRt.getShortName(targetClassFQN)) - } - } - } - }, configuration) - }, false) + private fun createCachedValue(): CachedValueProvider.Result>? = with(configuration) { + CachedValueProvider.Result.create( + (getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID) + getInjections(KOTLIN_SUPPORT_ID)) + .asSequence() + .flatMap { it.injectionPlaces.asSequence() } + .flatMap { retrieveJavaPlaceTargetClassesFQNs(it).asSequence() + retrieveKotlinPlaceTargetClassesFQNs(it).asSequence() } + .map { StringUtilRt.getShortName(it) } + .toHashSet() + , this) + } + + private val injectableTargetClassShortNames = CachedValuesManager.getManager(project).createCachedValue(::createCachedValue, false) private fun fastCheckInjectionsExists(annotationEntry: KtCallElement): Boolean { val referencedName = getNameReference(annotationEntry.calleeExpression)?.getReferencedName() ?: return false diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/JavaOutsideModuleDetector.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/JavaOutsideModuleDetector.kt index e213a789827..fb945f29111 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/JavaOutsideModuleDetector.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/inspections/JavaOutsideModuleDetector.kt @@ -9,6 +9,7 @@ import com.intellij.icons.AllIcons import com.intellij.ide.highlighter.JavaFileType import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.project.Project +import com.intellij.openapi.startup.StartupActivity import com.intellij.openapi.util.Key import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileListener @@ -21,11 +22,10 @@ import org.jetbrains.kotlin.idea.framework.isGradleModule import org.jetbrains.kotlin.idea.util.findModule import org.jetbrains.kotlin.idea.util.sourceRoots -class JavaOutsideModuleDetector(private val project: Project, notifications: EditorNotifications) : - EditorNotifications.Provider() { - override fun getKey(): Key = KEY +class JavaOutsideModuleDetector(private val project: Project) : EditorNotifications.Provider(), StartupActivity { - init { + override fun runActivity(project: Project) { + val notifications = EditorNotifications.getInstance(project) VirtualFileManager.getInstance().addVirtualFileListener(object : VirtualFileListener { override fun fileMoved(event: VirtualFileMoveEvent) { if (event.file.fileType == JavaFileType.INSTANCE) notifications.updateNotifications(event.file) @@ -33,6 +33,8 @@ class JavaOutsideModuleDetector(private val project: Project, notifications: Edi }, project) } + override fun getKey(): Key = KEY + override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? { if (file.fileType != JavaFileType.INSTANCE) return null val module = file.findModule(project) ?: return null diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt index 736eee2480c..30c2ab35aec 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ModuleRootEvent import com.intellij.openapi.roots.ModuleRootListener import com.intellij.openapi.roots.libraries.Library +import com.intellij.openapi.startup.StartupActivity import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.openapi.ui.popup.PopupStep import com.intellij.openapi.ui.popup.util.BaseListPopupStep @@ -48,9 +49,10 @@ import javax.swing.Icon import javax.swing.JLabel import javax.swing.event.HyperlinkEvent -class UnsupportedAbiVersionNotificationPanelProvider(private val project: Project) : EditorNotifications.Provider() { +class UnsupportedAbiVersionNotificationPanelProvider(private val project: Project) : + EditorNotifications.Provider(), StartupActivity { - init { + override fun runActivity(project: Project) { val connection = project.messageBus.connect() connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener { override fun rootsChanged(event: ModuleRootEvent) { diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java index 4a79fb7a5e7..64a713bbfcc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -184,7 +184,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co (K2JSCompilerArguments) Kotlin2JsCompilerArgumentsHolder.Companion.getInstance(project).getSettings().unfrozen(), (K2JVMCompilerArguments) Kotlin2JvmCompilerArgumentsHolder.Companion.getInstance(project).getSettings().unfrozen(), (CompilerSettings) KotlinCompilerSettings.Companion.getInstance(project).getSettings().unfrozen(), - ServiceManager.getService(project, KotlinCompilerWorkspaceSettings.class), + KotlinCompilerWorkspaceSettings.getInstance(project), true, false); }