Delete Kotlin IntelliJ IDEA plugin sources

Kotlin plugin sources were migrated to intellij-community:
https://github.com/JetBrains/intellij-community/tree/master/plugins/kotlin

Preserve `jps-plugin/testData/incremental`
because it's used in `compiler/incremental-compilation-impl/test`

Preserve `idea/testData/multiModuleHighlighting/multiplatform`
because it's used in `MppHighlightingTestDataWithGradleIT`
This commit is contained in:
Nikita Bobko
2021-07-19 18:33:33 +02:00
parent b8d74698f1
commit 39fa2b0baf
49333 changed files with 0 additions and 1160202 deletions
@@ -1,53 +0,0 @@
description = "Kotlinx Serialization IDEA Plugin"
plugins {
kotlin("jvm")
id("jps-compatible")
}
dependencies {
compileOnly(project(":js:js.translator"))
compile(project(":kotlinx-serialization-compiler-plugin"))
compile(project(":idea"))
compile(project(":idea:idea-gradle"))
compile(project(":idea:idea-maven"))
compile(project(":plugins:annotation-based-compiler-plugins-ide-support"))
compileOnly(intellijDep())
compileOnly(intellijPluginDep("java"))
excludeInAndroidStudio(rootProject) { compileOnly(intellijPluginDep("maven")) }
compileOnly(intellijPluginDep("gradle"))
testCompile(toolsJar())
testCompile(projectTests(":idea"))
testCompile(projectTests(":compiler:tests-common"))
testCompile(projectTests(":idea:idea-test-framework"))
testCompile(project(":kotlin-test:kotlin-test-junit"))
testCompile(commonDep("junit:junit"))
testCompile(projectTests(":idea:idea-frontend-independent"))
testImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0")
testRuntimeOnly(intellijCoreDep()) { includeJars("intellij-core") }
testRuntime(project(":allopen-ide-plugin"))
testRuntime(project(":plugins:parcelize:parcelize-ide"))
testRuntime(project(":sam-with-receiver-ide-plugin"))
testRuntime(project(":noarg-ide-plugin"))
testRuntime(project(":plugins:lombok:lombok-ide-plugin"))
testCompile(intellijDep())
testCompile(intellijPluginDep("java"))
}
sourceSets {
"main" { projectDefault() }
"test" { projectDefault() }
}
runtimeJar()
testsJar()
projectTest(parallel = true) {
workingDir = rootDir
}
@@ -1,2 +0,0 @@
extract.json.to.property=Extract Json format creation to property
replace.with.default.json.format=Replace with default Json format instance
@@ -1,96 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.compiler.diagnostic
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.callUtil.getReceiverExpression
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.unpackFunctionLiteral
import org.jetbrains.kotlin.resolve.BindingContext
class JsonFormatRedundantDiagnostic : CallChecker {
private val jsonFqName = FqName("kotlinx.serialization.json.Json")
private val jsonDefaultFqName = FqName("kotlinx.serialization.json.Json.Default")
private val parameterNameFrom = Name.identifier("from")
private val parameterNameBuilderAction = Name.identifier("builderAction")
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
val functionDescriptor = resolvedCall.resultingDescriptor as? SimpleFunctionDescriptor ?: return
val bindingContext = context.trace.bindingContext
if (isJsonFormatCreation(functionDescriptor)) {
if (isDefaultFormat(resolvedCall, bindingContext)) {
context.trace.report(SerializationErrors.JSON_FORMAT_REDUNDANT_DEFAULT.on(resolvedCall.call.callElement))
}
return
}
val receiverExpression = resolvedCall.getReceiverExpression() ?: return
val receiverResolvedCall = receiverExpression.getResolvedCall(bindingContext) ?: return
val receiverFunctionDescriptor = receiverResolvedCall.resultingDescriptor as? SimpleFunctionDescriptor ?: return
if (isJsonFormatCreation(receiverFunctionDescriptor) && !isDefaultFormat(receiverResolvedCall, bindingContext)) {
context.trace.report(SerializationErrors.JSON_FORMAT_REDUNDANT.on(receiverExpression.originalElement))
}
}
private fun isJsonFormatCreation(descriptor: SimpleFunctionDescriptor): Boolean {
return descriptor.importableFqName == jsonFqName
}
private fun isDefaultFormat(resolvedCall: ResolvedCall<*>, context: BindingContext): Boolean {
var defaultFrom = false
var emptyBuilder = false
resolvedCall.valueArguments.forEach { (paramDesc, arg) ->
when (paramDesc.name) {
parameterNameFrom -> defaultFrom = isDefaultFormatArgument(arg, context)
parameterNameBuilderAction -> emptyBuilder = isEmptyFunctionArgument(arg)
}
}
return defaultFrom && emptyBuilder
}
private fun isDefaultFormatArgument(arg: ResolvedValueArgument, context: BindingContext): Boolean {
if (arg is DefaultValueArgument) return true
if (arg !is ExpressionValueArgument) return false
val expression = arg.valueArgument?.getArgumentExpression() ?: return false
val fqName = context[BindingContext.EXPRESSION_TYPE_INFO, expression]?.type?.fqName ?: return false
return fqName == jsonDefaultFqName
}
private fun isEmptyFunctionArgument(arg: ResolvedValueArgument): Boolean {
if (arg !is ExpressionValueArgument) {
return false
}
val argumentExpression = arg.valueArgument?.getArgumentExpression() ?: return false
val blockExpression = if (argumentExpression is KtNamedFunction) {
// anonymous functions
argumentExpression.bodyBlockExpression ?: return true
} else {
// function literal
argumentExpression.unpackFunctionLiteral()?.bodyExpression
}
return blockExpression?.statements?.isEmpty() ?: false
}
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2020 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.kotlinx.serialization.compiler.diagnostic
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlinx.serialization.idea.getIfEnabledOn
class SerializationPluginIDEDeclarationChecker : SerializationPluginDeclarationChecker() {
override fun serializationPluginEnabledOn(descriptor: ClassDescriptor): Boolean {
// In the IDE, plugin is always in the classpath, but enabled only if corresponding compiler settings
// were imported into project model from Gradle.
return getIfEnabledOn(descriptor) { true } == true
}
override val isIde: Boolean
get() = true
}
@@ -1,42 +0,0 @@
/*
* Copyright 2010-2020 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.kotlinx.serialization.compiler.extensions
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.js.translate.context.TranslationContext
import org.jetbrains.kotlin.js.translate.declaration.DeclarationBodyVisitor
import org.jetbrains.kotlin.psi.KtPureClassOrObject
import org.jetbrains.kotlinx.serialization.idea.runIfEnabledIn
import org.jetbrains.kotlinx.serialization.idea.runIfEnabledOn
class SerializationIDECodegenExtension : SerializationCodegenExtension() {
override fun generateClassSyntheticParts(codegen: ImplementationBodyCodegen) =
runIfEnabledOn(codegen.descriptor) { super.generateClassSyntheticParts(codegen) }
}
class SerializationIDEJsExtension : SerializationJsExtension() {
override fun generateClassSyntheticParts(
declaration: KtPureClassOrObject,
descriptor: ClassDescriptor,
translator: DeclarationBodyVisitor,
context: TranslationContext
) = runIfEnabledOn(descriptor) {
super.generateClassSyntheticParts(declaration, descriptor, translator, context)
}
}
class SerializationIDEIrExtension : SerializationLoweringExtension() {
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
runIfEnabledIn(pluginContext.moduleDescriptor) {
super.generate(moduleFragment, pluginContext)
}
}
}
@@ -1,25 +0,0 @@
/*
* 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.kotlinx.serialization.compiler.extensions
import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useInstance
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.JsonFormatRedundantDiagnostic
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.SerializationPluginIDEDeclarationChecker
class SerializationIDEContainerContributor : StorageComponentContainerContributor {
override fun registerModuleComponents(
container: StorageComponentContainer,
platform: TargetPlatform,
moduleDescriptor: ModuleDescriptor
) {
container.useInstance(SerializationPluginIDEDeclarationChecker())
container.useInstance(JsonFormatRedundantDiagnostic())
}
}
@@ -1,73 +0,0 @@
/*
* Copyright 2010-2018 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.kotlinx.serialization.compiler.extensions
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlinx.serialization.idea.getIfEnabledOn
import org.jetbrains.kotlinx.serialization.idea.runIfEnabledOn
import java.util.*
class SerializationIDEResolveExtension : SerializationResolveExtension() {
override fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> =
getIfEnabledOn(thisDescriptor) { super.getSyntheticNestedClassNames(thisDescriptor) } ?: emptyList()
override fun getPossibleSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name>? {
val enabled = getIfEnabledOn(thisDescriptor) { true } ?: false
return if (enabled) super.getPossibleSyntheticNestedClassNames(thisDescriptor)
else emptyList()
}
override fun getSyntheticFunctionNames(thisDescriptor: ClassDescriptor): List<Name> =
getIfEnabledOn(thisDescriptor) { super.getSyntheticFunctionNames(thisDescriptor) } ?: emptyList()
override fun generateSyntheticClasses(
thisDescriptor: ClassDescriptor,
name: Name,
ctx: LazyClassContext,
declarationProvider: ClassMemberDeclarationProvider,
result: MutableSet<ClassDescriptor>
) = runIfEnabledOn(thisDescriptor) {
super.generateSyntheticClasses(thisDescriptor, name, ctx, declarationProvider, result)
}
override fun getSyntheticCompanionObjectNameIfNeeded(thisDescriptor: ClassDescriptor): Name? = getIfEnabledOn(thisDescriptor) {
super.getSyntheticCompanionObjectNameIfNeeded(thisDescriptor)
}
override fun addSyntheticSupertypes(thisDescriptor: ClassDescriptor, supertypes: MutableList<KotlinType>) =
runIfEnabledOn(thisDescriptor) {
super.addSyntheticSupertypes(thisDescriptor, supertypes)
}
override fun generateSyntheticMethods(
thisDescriptor: ClassDescriptor,
name: Name,
bindingContext: BindingContext,
fromSupertypes: List<SimpleFunctionDescriptor>,
result: MutableCollection<SimpleFunctionDescriptor>
) = runIfEnabledOn(thisDescriptor) {
super.generateSyntheticMethods(thisDescriptor, name, bindingContext, fromSupertypes, result)
}
override fun generateSyntheticProperties(
thisDescriptor: ClassDescriptor,
name: Name,
bindingContext: BindingContext,
fromSupertypes: ArrayList<PropertyDescriptor>,
result: MutableSet<PropertyDescriptor>
) = runIfEnabledOn(thisDescriptor) {
super.generateSyntheticProperties(thisDescriptor, name, bindingContext, fromSupertypes, result)
}
}
@@ -1,22 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import org.jetbrains.kotlin.util.AbstractKotlinBundle
@NonNls
private const val BUNDLE = "messages.KotlinSerializationBundle"
object KotlinSerializationBundle : AbstractKotlinBundle(BUNDLE) {
@JvmStatic
fun message(@NonNls @PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String = getMessage(key, *params)
@JvmStatic
fun htmlMessage(@NonNls @PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String =
getMessage(key, *params).withHtml()
}
@@ -1,24 +0,0 @@
/*
* Copyright 2010-2018 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.kotlinx.serialization.idea
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.project.ModuleData
import org.jetbrains.kotlin.idea.configuration.GradleProjectImportHandler
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
class KotlinSerializationGradleImportHandler : GradleProjectImportHandler {
override fun importBySourceSet(facet: KotlinFacet, sourceSetNode: DataNode<GradleSourceSetData>) {
KotlinSerializationImportHandler.modifyCompilerArguments(facet, PLUGIN_GRADLE_JAR)
}
override fun importByModule(facet: KotlinFacet, moduleNode: DataNode<ModuleData>) {
KotlinSerializationImportHandler.modifyCompilerArguments(facet, PLUGIN_GRADLE_JAR)
}
private val PLUGIN_GRADLE_JAR = "kotlin-serialization"
}
@@ -1,53 +0,0 @@
/*
* Copyright 2010-2017 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.
*/
package org.jetbrains.kotlinx.serialization.idea
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
internal object KotlinSerializationImportHandler {
private const val pluginJpsJarName = "kotlinx-serialization-compiler-plugin.jar"
val PLUGIN_JPS_JAR: String
get() = File(PathUtil.kotlinPathsForIdeaPlugin.libPath, pluginJpsJarName).absolutePath
fun isPluginJarPath(path: String): Boolean {
return path.endsWith(pluginJpsJarName)
}
fun modifyCompilerArguments(facet: KotlinFacet, buildSystemPluginJar: String) {
val facetSettings = facet.configuration.settings
val commonArguments = facetSettings.compilerArguments ?: CommonCompilerArguments.DummyImpl()
var pluginWasEnabled = false
val oldPluginClasspaths = (commonArguments.pluginClasspaths ?: emptyArray()).filterTo(mutableListOf()) {
val lastIndexOfFile = it.lastIndexOfAny(charArrayOf('/', File.separatorChar))
if (lastIndexOfFile < 0) {
return@filterTo true
}
val match = it.drop(lastIndexOfFile + 1).matches("$buildSystemPluginJar-.*\\.jar".toRegex())
if (match) pluginWasEnabled = true
!match
}
val newPluginClasspaths = if (pluginWasEnabled) oldPluginClasspaths + PLUGIN_JPS_JAR else oldPluginClasspaths
commonArguments.pluginClasspaths = newPluginClasspaths.toTypedArray()
facetSettings.compilerArguments = commonArguments
}
}
@@ -1,23 +0,0 @@
/*
* Copyright 2010-2018 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.kotlinx.serialization.idea
import org.jetbrains.kotlin.plugin.ide.AbstractMavenImportHandler
import org.jetbrains.kotlin.plugin.ide.CompilerPluginSetup
import java.io.File
class KotlinSerializationMavenImportHandler : AbstractMavenImportHandler() {
override val compilerPluginId: String = "org.jetbrains.kotlinx.serialization"
override val pluginName: String = "serialization"
override val pluginJarFileFromIdea: File
get() = File(KotlinSerializationImportHandler.PLUGIN_JPS_JAR)
override fun getOptions(
enabledCompilerPlugins: List<String>,
compilerPluginOptions: List<String>
): List<CompilerPluginSetup.PluginOption>? =
if ("kotlinx-serialization" in enabledCompilerPlugins) emptyList() else null
}
@@ -1,29 +0,0 @@
/*
* Copyright 2010-2020 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.kotlinx.serialization.idea
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.core.unwrapModuleSourceInfo
import org.jetbrains.kotlin.idea.facet.KotlinFacet
import org.jetbrains.kotlin.resolve.descriptorUtil.module
private fun isEnabledIn(moduleDescriptor: ModuleDescriptor): Boolean {
val module = moduleDescriptor.getCapability(ModuleInfo.Capability)?.unwrapModuleSourceInfo()?.module ?: return false
val facet = KotlinFacet.get(module) ?: return false
val pluginClasspath = facet.configuration.settings.compilerArguments?.pluginClasspaths ?: return false
if (pluginClasspath.none(KotlinSerializationImportHandler::isPluginJarPath)) return false
return true
}
fun <T> getIfEnabledOn(clazz: ClassDescriptor, body: () -> T): T? {
return if (isEnabledIn(clazz.module)) body() else null
}
fun runIfEnabledOn(clazz: ClassDescriptor, body: () -> Unit) { getIfEnabledOn<Unit>(clazz, body) }
fun runIfEnabledIn(moduleDescriptor: ModuleDescriptor, block: () -> Unit) { if (isEnabledIn(moduleDescriptor)) block() }
@@ -1,42 +0,0 @@
/*
* Copyright 2010-2020 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.kotlinx.serialization.idea.quickfixes
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.util.ImportInsertHelperImpl
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.SerializationErrors
import org.jetbrains.kotlinx.serialization.compiler.resolve.SerializationAnnotations
internal class AddKotlinxSerializationTransientImportQuickFix(expression: PsiElement) :
KotlinQuickFixAction<PsiElement>(expression) {
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
// Do not use Helper itself because it does not insert import on conflict;
// so it will always fail because k.jvm.Transient is always in auto-import
ImportInsertHelperImpl.addImport(project, file, SerializationAnnotations.serialTransientFqName, allUnder = false)
}
override fun getFamilyName(): String = text
override fun getText(): String = "Import ${SerializationAnnotations.serialTransientFqName}"
object Factory : KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
if (diagnostic.factory != SerializationErrors.INCORRECT_TRANSIENT) return null
val castedDiagnostic = SerializationErrors.INCORRECT_TRANSIENT.cast(diagnostic)
val element = castedDiagnostic.psiElement
return AddKotlinxSerializationTransientImportQuickFix(element)
}
}
}
@@ -1,39 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea.quickfixes
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.SerializationErrors
import org.jetbrains.kotlinx.serialization.idea.KotlinSerializationBundle
internal class JsonRedundantDefaultQuickFix(expression: KtCallExpression) : KotlinQuickFixAction<KtCallExpression>(expression) {
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val element = element ?: return
val call = element as? KtCallExpression ?: return
val callee = call.calleeExpression ?: return
call.replace(callee)
}
override fun getFamilyName(): String = text
override fun getText(): String = KotlinSerializationBundle.message("replace.with.default.json.format")
object Factory : KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
if (diagnostic.factory != SerializationErrors.JSON_FORMAT_REDUNDANT_DEFAULT) return null
val castedDiagnostic = SerializationErrors.JSON_FORMAT_REDUNDANT_DEFAULT.cast(diagnostic)
val element: KtCallExpression = castedDiagnostic.psiElement as? KtCallExpression ?: return null
return JsonRedundantDefaultQuickFix(element)
}
}
}
@@ -1,79 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea.quickfixes
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ScrollType
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory
import org.jetbrains.kotlin.idea.refactoring.chooseContainerElementIfNecessary
import org.jetbrains.kotlin.idea.refactoring.getExtractionContainers
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceProperty.KotlinIntroducePropertyHandler
import org.jetbrains.kotlin.idea.refactoring.introduce.showErrorHintByKey
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getOutermostParentContainedIn
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.SerializationErrors
import org.jetbrains.kotlinx.serialization.idea.KotlinSerializationBundle
internal class JsonRedundantQuickFix(expression: KtCallExpression) : KotlinQuickFixAction<KtCallExpression>(expression) {
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
editor ?: return
val element = element ?: return
selectContainer(element, project, editor) {
editor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
val outermostParent = element.getOutermostParentContainedIn(it)
if (outermostParent == null) {
showErrorHintByKey(project, editor, "cannot.refactor.no.container", text)
return@selectContainer
}
KotlinIntroducePropertyHandler().doInvoke(project, editor, file, listOf(element), outermostParent)
}
}
override fun getFamilyName(): String = text
override fun getText(): String = KotlinSerializationBundle.message("extract.json.to.property")
object Factory : KotlinSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
if (diagnostic.factory != SerializationErrors.JSON_FORMAT_REDUNDANT) return null
val castedDiagnostic = SerializationErrors.JSON_FORMAT_REDUNDANT.cast(diagnostic)
val element: KtCallExpression = castedDiagnostic.psiElement as? KtCallExpression ?: return null
return JsonRedundantQuickFix(element)
}
}
private fun selectContainer(element: PsiElement, project: Project, editor: Editor, onSelect: (PsiElement) -> Unit) {
val parent = element.parent ?: throw AssertionError("Should have at least one parent")
val containers = parent.getExtractionContainers(strict = true, includeAll = true)
.filter { it is KtClassBody || (it is KtFile && !it.isScript()) }
if (containers.isEmpty()) {
showErrorHintByKey(project, editor, "cannot.refactor.no.container", text)
return
}
chooseContainerElementIfNecessary(
containers,
editor,
KotlinBundle.message("title.select.target.code.block"),
true,
{ it },
{ onSelect(it) }
)
}
}
@@ -1,18 +0,0 @@
/*
* Copyright 2010-2020 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.kotlinx.serialization.idea.quickfixes
import org.jetbrains.kotlin.idea.quickfix.QuickFixContributor
import org.jetbrains.kotlin.idea.quickfix.QuickFixes
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.SerializationErrors
class SerializationQuickFixContributor : QuickFixContributor {
override fun registerQuickFixes(quickFixes: QuickFixes) {
quickFixes.register(SerializationErrors.INCORRECT_TRANSIENT, AddKotlinxSerializationTransientImportQuickFix.Factory)
quickFixes.register(SerializationErrors.JSON_FORMAT_REDUNDANT_DEFAULT, JsonRedundantDefaultQuickFix.Factory)
quickFixes.register(SerializationErrors.JSON_FORMAT_REDUNDANT, JsonRedundantQuickFix.Factory)
}
}
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea
import org.jetbrains.kotlin.ObsoleteTestInfrastructure
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationIDEContainerContributor
@OptIn(ObsoleteTestInfrastructure::class)
abstract class AbstractSerializationPluginIdeDiagnosticTest : AbstractDiagnosticsTest() {
private val coreLibraryPath = getSerializationCoreLibraryJar()!!
private val jsonLibraryPath = getSerializationJsonLibraryJar()!!
override fun setupEnvironment(environment: KotlinCoreEnvironment) {
if (!StorageComponentContainerContributor.getInstances(project).any { it is SerializationIDEContainerContributor }) {
StorageComponentContainerContributor.registerExtension(project, SerializationIDEContainerContributor())
}
environment.updateClasspath(listOf(JvmClasspathRoot(coreLibraryPath), JvmClasspathRoot(jsonLibraryPath)))
}
}
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea
import org.jetbrains.kotlin.idea.quickfix.AbstractQuickFixTest
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
abstract class AbstractSerializationQuickFixTest : AbstractQuickFixTest() {
override fun setUp() {
super.setUp()
val coreJar = getSerializationCoreLibraryJar()!!
val jsonJar = getSerializationJsonLibraryJar()!!
ConfigLibraryUtil.addLibrary(module, "Serialization core", coreJar.parentFile.absolutePath, arrayOf(coreJar.name))
ConfigLibraryUtil.addLibrary(module, "Serialization JSON", jsonJar.parentFile.absolutePath, arrayOf(jsonJar.name))
}
override fun tearDown() {
ConfigLibraryUtil.removeLibrary(module, "Serialization JSON")
ConfigLibraryUtil.removeLibrary(module, "Serialization core")
super.tearDown()
}
}
@@ -1,18 +0,0 @@
/*
* Copyright 2010-2018 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.kotlinx.serialization.idea
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.caches.lightClasses.annotations.KOTLINX_SERIALIZABLE_FQ_NAME
import org.jetbrains.kotlin.idea.caches.lightClasses.annotations.KOTLINX_SERIALIZER_FQ_NAME
import org.jetbrains.kotlinx.serialization.compiler.resolve.SerializationAnnotations
class AnnotationNamesConsistencyTest : TestCase() {
fun testConsistency() {
assertEquals(KOTLINX_SERIALIZABLE_FQ_NAME, SerializationAnnotations.serializableAnnotationFqName)
assertEquals(KOTLINX_SERIALIZER_FQ_NAME, SerializationAnnotations.serializerAnnotationFqName)
}
}
@@ -1,44 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea
import junit.framework.TestCase
import org.jetbrains.kotlin.utils.PathUtil
import org.jetbrains.kotlinx.serialization.compiler.diagnostic.VersionReader
import org.junit.Test
import java.io.File
import kotlin.test.assertTrue
class RuntimeLibraryInClasspathTest {
private val runtimeLibraryPath = getSerializationCoreLibraryJar()
@Test
fun testRuntimeLibraryExists() {
TestCase.assertNotNull(
"kotlinx-serialization runtime library is not found. Make sure it is present in test classpath",
runtimeLibraryPath
)
}
@Test
fun testRuntimeHasSufficientVersion() {
val version = VersionReader.getVersionsFromManifest(runtimeLibraryPath!!)
assertTrue(version.currentCompilerMatchRequired(), "Runtime version too high")
assertTrue(version.implementationVersionMatchSupported(), "Runtime version too low")
}
}
internal fun getSerializationCoreLibraryJar(): File? = try {
PathUtil.getResourcePathForClass(Class.forName("kotlinx.serialization.KSerializer"))
} catch (e: ClassNotFoundException) {
null
}
internal fun getSerializationJsonLibraryJar(): File? = try {
PathUtil.getResourcePathForClass(Class.forName("kotlinx.serialization.json.Json"))
} catch (e: ClassNotFoundException) {
null
}
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("plugins/kotlin-serialization/kotlin-serialization-ide/testData/diagnostics")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class SerializationPluginIdeDiagnosticTestGenerated extends AbstractSerializationPluginIdeDiagnosticTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInDiagnostics() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/kotlin-serialization/kotlin-serialization-ide/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("JsonRedundantFormat.kt")
public void testJsonRedundantFormat() throws Exception {
runTest("plugins/kotlin-serialization/kotlin-serialization-ide/testData/diagnostics/JsonRedundantFormat.kt");
}
}
@@ -1,41 +0,0 @@
/*
* Copyright 2010-2021 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.kotlinx.serialization.idea;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("plugins/kotlin-serialization/kotlin-serialization-ide/testData/quickfix")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class SerializationQuickFixTestGenerated extends AbstractSerializationQuickFixTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInQuickfix() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/kotlin-serialization/kotlin-serialization-ide/testData/quickfix"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
}
@TestMetadata("DefaultFormat.kt")
public void testDefaultFormat() throws Exception {
runTest("plugins/kotlin-serialization/kotlin-serialization-ide/testData/quickfix/DefaultFormat.kt");
}
@TestMetadata("DefaultFormatWithAlias.kt")
public void testDefaultFormatWithAlias() throws Exception {
runTest("plugins/kotlin-serialization/kotlin-serialization-ide/testData/quickfix/DefaultFormatWithAlias.kt");
}
}
@@ -1,82 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE,-EXPERIMENTAL_API_USAGE
// SKIP_TXT
// FILE: test.kt
import kotlinx.serialization.*
import kotlinx.serialization.json.*
object Instance
val defaultWarn = <!JSON_FORMAT_REDUNDANT_DEFAULT!>Json {}<!>
val receiverWarn = <!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.encodeToString(Instance)
val noWarnFormat = Json {encodeDefaults = true}
val receiverNoWarn = noWarnFormat.encodeToString(Instance)
val defaultNoWarn = Json.encodeToString(Instance)
class SomeContainerClass {
val memberDefaultWarn = <!JSON_FORMAT_REDUNDANT_DEFAULT!>Json {}<!>
val memberReceiverWarn = <!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.encodeToString(Instance)
val memberNoWarnFormat = Json {encodeDefaults = true}
val memberReceiverNoWarn = noWarnFormat.encodeToString(Instance)
val memberDefaultNoWarn = Json.encodeToString(Instance)
fun testDefaultWarnings() {
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json {}<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json() {}<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json {}<!>.encodeToString(Any())
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json {}<!>.encodeToString(Instance)
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json { /*some comment*/ }<!>.encodeToString(Instance)
val localDefaultFormat = <!JSON_FORMAT_REDUNDANT_DEFAULT!>Json {}<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json(Json.Default) {}<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json(Json) {}<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json(Json.Default, {})<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json(builderAction = {})<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json(builderAction = fun JsonBuilder.() {})<!>
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json(builderAction = fun JsonBuilder.() = Unit)<!>
"{}".let {
<!JSON_FORMAT_REDUNDANT_DEFAULT!>Json {}<!>.decodeFromString<Any>(it)
}
}
fun testReceiverWarnings() {
<!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.encodeToString(Instance)
val encoded = <!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.encodeToString(Instance)
<!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.decodeFromString<Any>("{}")
<!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.hashCode()
<!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.toString()
<!JSON_FORMAT_REDUNDANT!>Json(noWarnFormat) {encodeDefaults = true}<!>.encodeToString(Instance)
<!JSON_FORMAT_REDUNDANT!>Json(builderAction = {encodeDefaults = true})<!>.encodeToString(Instance)
<!JSON_FORMAT_REDUNDANT!>Json(noWarnFormat, {encodeDefaults = true})<!>.encodeToString(Instance)
<!JSON_FORMAT_REDUNDANT!>Json(builderAction = fun JsonBuilder.() {encodeDefaults = true})<!>.encodeToString(Instance)
"{}".let {
<!JSON_FORMAT_REDUNDANT!>Json {encodeDefaults = true}<!>.decodeFromString<Any>(it)
}
}
fun testReceiverNoWarnings() {
val localFormat = Json {encodeDefaults = true}
localFormat.encodeToString(Instance)
localFormat.decodeFromString<Any>("{}")
localFormat.hashCode()
localFormat.toString()
}
fun testDefaultNoWarnings() {
val localDefault = Json
Json.encodeToString(Instance)
Json.decodeFromString<Any>("{}")
Json.hashCode()
Json.toString()
Json(builderAction = this::builder)
Json(Json.Default, this::builder)
}
private fun builder(builder: JsonBuilder) {
//now its empty builder
}
}
@@ -1,7 +0,0 @@
// "Replace with default Json format instance" "true"
import kotlinx.serialization.*
import kotlinx.serialization.json.*
fun foo() {
<caret>Json {}.encodeToString(Any())
}
@@ -1,7 +0,0 @@
// "Replace with default Json format instance" "true"
import kotlinx.serialization.*
import kotlinx.serialization.json.*
fun foo() {
Json.encodeToString(Any())
}
@@ -1,8 +0,0 @@
// "Replace with default Json format instance" "true"
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.json.Json as Alias
fun foo() {
<caret>Alias {}
}
@@ -1,8 +0,0 @@
// "Replace with default Json format instance" "true"
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.json.Json as Alias
fun foo() {
Alias
}