Fix "Non default constructors for extension class"

This commit is contained in:
Dmitry Gridin
2019-08-01 13:52:47 +03:00
parent 9ea2446ec0
commit 832c8e0e20
8 changed files with 61 additions and 96 deletions
@@ -1,32 +1,17 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * 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.
* 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.
*/ */
package org.jetbrains.kotlin.idea.compiler.configuration package org.jetbrains.kotlin.idea.compiler.configuration
import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.components.*
import com.intellij.openapi.components.State import com.intellij.openapi.project.Project
import com.intellij.openapi.components.Storage
import com.intellij.openapi.components.StoragePathMacros
import com.intellij.util.xmlb.XmlSerializerUtil import com.intellij.util.xmlb.XmlSerializerUtil
@State( @State(
name = "KotlinCompilerWorkspaceSettings", name = "KotlinCompilerWorkspaceSettings",
storages = arrayOf( storages = [Storage(file = StoragePathMacros.WORKSPACE_FILE)]
Storage(file = StoragePathMacros.WORKSPACE_FILE)
)
) )
class KotlinCompilerWorkspaceSettings : PersistentStateComponent<KotlinCompilerWorkspaceSettings> { class KotlinCompilerWorkspaceSettings : PersistentStateComponent<KotlinCompilerWorkspaceSettings> {
/** /**
@@ -44,4 +29,10 @@ class KotlinCompilerWorkspaceSettings : PersistentStateComponent<KotlinCompilerW
override fun loadState(state: KotlinCompilerWorkspaceSettings) { override fun loadState(state: KotlinCompilerWorkspaceSettings) {
XmlSerializerUtil.copyBean(state, this) XmlSerializerUtil.copyBean(state, this)
} }
companion object {
@JvmStatic
fun getInstance(project: Project): KotlinCompilerWorkspaceSettings =
ServiceManager.getService(project, KotlinCompilerWorkspaceSettings::class.java)
}
} }
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * 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.
* 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.
*/ */
package org.jetbrains.kotlin.idea.core.script package org.jetbrains.kotlin.idea.core.script
@@ -27,11 +16,10 @@ import org.jetbrains.kotlin.resolve.jvm.KotlinSafeClassFinder
class KotlinScriptDependenciesClassFinder( class KotlinScriptDependenciesClassFinder(
project: Project, private val project: Project
private val scriptDependenciesManager: ScriptDependenciesManager
) : NonClasspathClassFinder(project), KotlinSafeClassFinder { ) : NonClasspathClassFinder(project), KotlinSafeClassFinder {
override fun calcClassRoots(): List<VirtualFile> = ScriptDependenciesManager.getInstance(project)
override fun calcClassRoots(): List<VirtualFile> = scriptDependenciesManager.getAllScriptsDependenciesClassFiles().toList() .getAllScriptsDependenciesClassFiles().toList()
override fun findClass(qualifiedName: String, scope: GlobalSearchScope): PsiClass? { override fun findClass(qualifiedName: String, scope: GlobalSearchScope): PsiClass? {
tailrec fun findClassInner(parentQualifier: String, inners: List<String> = emptyList()): PsiClass? { tailrec fun findClassInner(parentQualifier: String, inners: List<String> = emptyList()): PsiClass? {
@@ -39,7 +27,7 @@ class KotlinScriptDependenciesClassFinder(
val parentClass = super.findClass(parentQualifier, scope) val parentClass = super.findClass(parentQualifier, scope)
if (parentClass != null) { if (parentClass != null) {
if (inners.isNotEmpty()) { if (inners.isNotEmpty()) {
val innerClass = inners.fold<String, PsiClass?>(parentClass) { c: PsiClass?, name: String -> val innerClass = inners.fold(parentClass) { c: PsiClass?, name: String ->
c?.findInnerClassByName(name, false) c?.findInnerClassByName(name, false)
} }
if (innerClass != null) return innerClass if (innerClass != null) return innerClass
@@ -1,31 +1,20 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * 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.
* 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.
*/ */
package org.jetbrains.kotlin.idea.compiler.configuration package org.jetbrains.kotlin.idea.compiler.configuration
import com.intellij.compiler.server.BuildProcessParametersProvider import com.intellij.compiler.server.BuildProcessParametersProvider
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.util.registry.Registry
import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.idea.PluginStartupComponent import org.jetbrains.kotlin.idea.PluginStartupComponent
class KotlinBuildProcessParametersProvider( class KotlinBuildProcessParametersProvider(private val project: Project) : BuildProcessParametersProvider() {
private val compilerWorkspaceSettings: KotlinCompilerWorkspaceSettings,
private val kotlinPluginStartupComponent: PluginStartupComponent
) : BuildProcessParametersProvider() {
override fun getVMArguments(): MutableList<String> { override fun getVMArguments(): MutableList<String> {
val compilerWorkspaceSettings = KotlinCompilerWorkspaceSettings.getInstance(project)
val res = arrayListOf<String>() val res = arrayListOf<String>()
if (compilerWorkspaceSettings.preciseIncrementalEnabled) { if (compilerWorkspaceSettings.preciseIncrementalEnabled) {
res.add("-D" + IncrementalCompilation.INCREMENTAL_COMPILATION_JVM_PROPERTY + "=true") res.add("-D" + IncrementalCompilation.INCREMENTAL_COMPILATION_JVM_PROPERTY + "=true")
@@ -39,7 +28,7 @@ class KotlinBuildProcessParametersProvider(
if (Registry.`is`("kotlin.jps.instrument.bytecode", false)) { if (Registry.`is`("kotlin.jps.instrument.bytecode", false)) {
res.add("-Dkotlin.jps.instrument.bytecode=true") res.add("-Dkotlin.jps.instrument.bytecode=true")
} }
kotlinPluginStartupComponent.aliveFlagPath.let { PluginStartupComponent.getInstance().aliveFlagPath.let {
if (!it.isBlank()) { if (!it.isBlank()) {
// TODO: consider taking the property name from compiler/daemon/common (check whether dependency will be not too heavy) // 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\"") res.add("-Dkotlin.daemon.client.alive.path=\"$it\"")
@@ -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. * 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.ModuleRootManager
import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService 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.JBPopupFactory
import com.intellij.openapi.ui.popup.ListPopup import com.intellij.openapi.ui.popup.ListPopup
import com.intellij.openapi.ui.popup.PopupStep 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.SuppressNotificationState
import org.jetbrains.kotlin.idea.versions.UnsupportedAbiVersionNotificationPanelProvider import org.jetbrains.kotlin.idea.versions.UnsupportedAbiVersionNotificationPanelProvider
import org.jetbrains.kotlin.idea.versions.createComponentActionLabel import org.jetbrains.kotlin.idea.versions.createComponentActionLabel
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.platform.jvm.isJvm import org.jetbrains.kotlin.platform.jvm.isJvm
import org.jetbrains.kotlin.psi.KtFile
// Code is partially copied from com.intellij.codeInsight.daemon.impl.SetupSDKNotificationProvider // Code is partially copied from com.intellij.codeInsight.daemon.impl.SetupSDKNotificationProvider
class KotlinSetupEnvironmentNotificationProvider( class KotlinSetupEnvironmentNotificationProvider(private val myProject: Project) : EditorNotifications.Provider<EditorNotificationPanel>(),
private val myProject: Project, StartupActivity {
notifications: EditorNotifications) : EditorNotifications.Provider<EditorNotificationPanel>() {
init { override fun runActivity(project: Project) {
myProject.messageBus.connect(myProject).subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener { val notifications = EditorNotifications.getInstance(project)
project.messageBus.connect(project).subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
override fun rootsChanged(event: ModuleRootEvent) { override fun rootsChanged(event: ModuleRootEvent) {
notifications.updateAllNotifications() notifications.updateAllNotifications()
} }
@@ -109,13 +110,12 @@ class KotlinSetupEnvironmentNotificationProvider(
return EditorNotificationPanel().apply { return EditorNotificationPanel().apply {
setText("Kotlin not configured") setText("Kotlin not configured")
val configurators = getAbleToRunConfigurators(module).toList() val configurators = getAbleToRunConfigurators(module).toList()
if (!configurators.isEmpty()) { if (configurators.isNotEmpty()) {
createComponentActionLabel("Configure") { label -> createComponentActionLabel("Configure") { label ->
val singleConfigurator = configurators.singleOrNull() val singleConfigurator = configurators.singleOrNull()
if (singleConfigurator != null) { if (singleConfigurator != null) {
singleConfigurator.apply(module.project) singleConfigurator.apply(module.project)
} } else {
else {
val configuratorsPopup = createConfiguratorsPopup(module.project, configurators) val configuratorsPopup = createConfiguratorsPopup(module.project, configurators)
configuratorsPopup.showUnderneathOf(label) configuratorsPopup.showUnderneathOf(label)
} }
@@ -53,10 +53,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KotlinLanguageInjector( class KotlinLanguageInjector(
private val configuration: Configuration, private val project: Project
private val project: Project,
private val temporaryPlacesRegistry: TemporaryPlacesRegistry
) : MultiHostInjector { ) : MultiHostInjector {
private val configuration get() = Configuration.getProjectInstance(project)
companion object { companion object {
private val STRING_LITERALS_REGEXP = "\"([^\"]*)\"".toRegex() private val STRING_LITERALS_REGEXP = "\"([^\"]*)\"".toRegex()
private val ABSENT_KOTLIN_INJECTION = BaseInjection("ABSENT_KOTLIN_BASE_INJECTION") private val ABSENT_KOTLIN_INJECTION = BaseInjection("ABSENT_KOTLIN_BASE_INJECTION")
@@ -143,7 +143,7 @@ class KotlinLanguageInjector(
): BaseInjection? { ): BaseInjection? {
val containingFile = ktHost.containingFile val containingFile = ktHost.containingFile
val tempInjectedLanguage = temporaryPlacesRegistry.getLanguageFor(ktHost, containingFile) val tempInjectedLanguage = TemporaryPlacesRegistry.getInstance(project).getLanguageFor(ktHost, containingFile)
if (tempInjectedLanguage != null) { if (tempInjectedLanguage != null) {
InjectorUtils.putInjectedFileUserData(registrar, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage) InjectorUtils.putInjectedFileUserData(registrar, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage)
return BaseInjection(support.id).apply { return BaseInjection(support.id).apply {
@@ -389,25 +389,18 @@ class KotlinLanguageInjector(
return InjectionInfo(id, prefix, suffix) return InjectionInfo(id, prefix, suffix)
} }
private val injectableTargetClassShortNames = CachedValuesManager.getManager(project) private fun createCachedValue(): CachedValueProvider.Result<HashSet<String>>? = with(configuration) {
.createCachedValue({ CachedValueProvider.Result.create(
CachedValueProvider.Result.create(HashSet<String>().apply { (getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID) + getInjections(KOTLIN_SUPPORT_ID))
for (injection in configuration.getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID)) { .asSequence()
for (injectionPlace in injection.injectionPlaces) { .flatMap { it.injectionPlaces.asSequence() }
for (targetClassFQN in retrieveJavaPlaceTargetClassesFQNs(injectionPlace)) { .flatMap { retrieveJavaPlaceTargetClassesFQNs(it).asSequence() + retrieveKotlinPlaceTargetClassesFQNs(it).asSequence() }
add(StringUtilRt.getShortName(targetClassFQN)) .map { StringUtilRt.getShortName(it) }
} .toHashSet()
} , this)
} }
for (injection in configuration.getInjections(KOTLIN_SUPPORT_ID)) {
for (injectionPlace in injection.injectionPlaces) { private val injectableTargetClassShortNames = CachedValuesManager.getManager(project).createCachedValue(::createCachedValue, false)
for (targetClassFQN in retrieveKotlinPlaceTargetClassesFQNs(injectionPlace)) {
add(StringUtilRt.getShortName(targetClassFQN))
}
}
}
}, configuration)
}, false)
private fun fastCheckInjectionsExists(annotationEntry: KtCallElement): Boolean { private fun fastCheckInjectionsExists(annotationEntry: KtCallElement): Boolean {
val referencedName = getNameReference(annotationEntry.calleeExpression)?.getReferencedName() ?: return false val referencedName = getNameReference(annotationEntry.calleeExpression)?.getReferencedName() ?: return false
@@ -9,6 +9,7 @@ import com.intellij.icons.AllIcons
import com.intellij.ide.highlighter.JavaFileType import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.util.Key import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileListener 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.findModule
import org.jetbrains.kotlin.idea.util.sourceRoots import org.jetbrains.kotlin.idea.util.sourceRoots
class JavaOutsideModuleDetector(private val project: Project, notifications: EditorNotifications) : class JavaOutsideModuleDetector(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>(), StartupActivity {
EditorNotifications.Provider<EditorNotificationPanel>() {
override fun getKey(): Key<EditorNotificationPanel> = KEY
init { override fun runActivity(project: Project) {
val notifications = EditorNotifications.getInstance(project)
VirtualFileManager.getInstance().addVirtualFileListener(object : VirtualFileListener { VirtualFileManager.getInstance().addVirtualFileListener(object : VirtualFileListener {
override fun fileMoved(event: VirtualFileMoveEvent) { override fun fileMoved(event: VirtualFileMoveEvent) {
if (event.file.fileType == JavaFileType.INSTANCE) notifications.updateNotifications(event.file) if (event.file.fileType == JavaFileType.INSTANCE) notifications.updateNotifications(event.file)
@@ -33,6 +33,8 @@ class JavaOutsideModuleDetector(private val project: Project, notifications: Edi
}, project) }, project)
} }
override fun getKey(): Key<EditorNotificationPanel> = KEY
override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? { override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? {
if (file.fileType != JavaFileType.INSTANCE) return null if (file.fileType != JavaFileType.INSTANCE) return null
val module = file.findModule(project) ?: return null val module = file.findModule(project) ?: return null
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ModuleRootEvent import com.intellij.openapi.roots.ModuleRootEvent
import com.intellij.openapi.roots.ModuleRootListener import com.intellij.openapi.roots.ModuleRootListener
import com.intellij.openapi.roots.libraries.Library 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.JBPopupFactory
import com.intellij.openapi.ui.popup.PopupStep import com.intellij.openapi.ui.popup.PopupStep
import com.intellij.openapi.ui.popup.util.BaseListPopupStep import com.intellij.openapi.ui.popup.util.BaseListPopupStep
@@ -48,9 +49,10 @@ import javax.swing.Icon
import javax.swing.JLabel import javax.swing.JLabel
import javax.swing.event.HyperlinkEvent import javax.swing.event.HyperlinkEvent
class UnsupportedAbiVersionNotificationPanelProvider(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>() { class UnsupportedAbiVersionNotificationPanelProvider(private val project: Project) :
EditorNotifications.Provider<EditorNotificationPanel>(), StartupActivity {
init { override fun runActivity(project: Project) {
val connection = project.messageBus.connect() val connection = project.messageBus.connect()
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener { connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
override fun rootsChanged(event: ModuleRootEvent) { override fun rootsChanged(event: ModuleRootEvent) {
@@ -184,7 +184,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
(K2JSCompilerArguments) Kotlin2JsCompilerArgumentsHolder.Companion.getInstance(project).getSettings().unfrozen(), (K2JSCompilerArguments) Kotlin2JsCompilerArgumentsHolder.Companion.getInstance(project).getSettings().unfrozen(),
(K2JVMCompilerArguments) Kotlin2JvmCompilerArgumentsHolder.Companion.getInstance(project).getSettings().unfrozen(), (K2JVMCompilerArguments) Kotlin2JvmCompilerArgumentsHolder.Companion.getInstance(project).getSettings().unfrozen(),
(CompilerSettings) KotlinCompilerSettings.Companion.getInstance(project).getSettings().unfrozen(), (CompilerSettings) KotlinCompilerSettings.Companion.getInstance(project).getSettings().unfrozen(),
ServiceManager.getService(project, KotlinCompilerWorkspaceSettings.class), KotlinCompilerWorkspaceSettings.getInstance(project),
true, true,
false); false);
} }