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.
*
* 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<KotlinCompilerWorkspaceSettings> {
/**
@@ -44,4 +29,10 @@ class KotlinCompilerWorkspaceSettings : PersistentStateComponent<KotlinCompilerW
override fun loadState(state: KotlinCompilerWorkspaceSettings) {
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.
*
* 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.core.script
@@ -27,11 +16,10 @@ import org.jetbrains.kotlin.resolve.jvm.KotlinSafeClassFinder
class KotlinScriptDependenciesClassFinder(
project: Project,
private val scriptDependenciesManager: ScriptDependenciesManager
private val project: Project
) : NonClasspathClassFinder(project), KotlinSafeClassFinder {
override fun calcClassRoots(): List<VirtualFile> = scriptDependenciesManager.getAllScriptsDependenciesClassFiles().toList()
override fun calcClassRoots(): List<VirtualFile> = ScriptDependenciesManager.getInstance(project)
.getAllScriptsDependenciesClassFiles().toList()
override fun findClass(qualifiedName: String, scope: GlobalSearchScope): PsiClass? {
tailrec fun findClassInner(parentQualifier: String, inners: List<String> = emptyList()): PsiClass? {
@@ -39,7 +27,7 @@ class KotlinScriptDependenciesClassFinder(
val parentClass = super.findClass(parentQualifier, scope)
if (parentClass != null) {
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)
}
if (innerClass != null) return innerClass
@@ -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<String> {
val compilerWorkspaceSettings = KotlinCompilerWorkspaceSettings.getInstance(project)
val res = arrayListOf<String>()
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\"")
@@ -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<EditorNotificationPanel>() {
class KotlinSetupEnvironmentNotificationProvider(private val myProject: Project) : EditorNotifications.Provider<EditorNotificationPanel>(),
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)
}
@@ -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<String>().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<HashSet<String>>? = 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
@@ -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<EditorNotificationPanel>() {
override fun getKey(): Key<EditorNotificationPanel> = KEY
class JavaOutsideModuleDetector(private val project: Project) : EditorNotifications.Provider<EditorNotificationPanel>(), 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<EditorNotificationPanel> = KEY
override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor): EditorNotificationPanel? {
if (file.fileType != JavaFileType.INSTANCE) 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.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<EditorNotificationPanel>() {
class UnsupportedAbiVersionNotificationPanelProvider(private val project: Project) :
EditorNotifications.Provider<EditorNotificationPanel>(), StartupActivity {
init {
override fun runActivity(project: Project) {
val connection = project.messageBus.connect()
connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener {
override fun rootsChanged(event: ModuleRootEvent) {
@@ -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);
}