Extract JvmNames, JvmFieldApplicabilityProblem to compiler.common
This commit is contained in:
committed by
TeamCityServer
parent
d4746903c8
commit
e3805c9b98
@@ -25,6 +25,10 @@ import org.jetbrains.kotlin.load.java.descriptors.getImplClassNameForDeserialize
|
|||||||
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_MULTIFILE_CLASS_SHORT
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_NAME_SHORT
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_PACKAGE_NAME_SHORT
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.MULTIFILE_PART_NAME_DELIMITER
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
@@ -36,14 +40,6 @@ object JvmFileClassUtil {
|
|||||||
val JVM_NAME: FqName = FqName("kotlin.jvm.JvmName")
|
val JVM_NAME: FqName = FqName("kotlin.jvm.JvmName")
|
||||||
val JVM_NAME_SHORT: String = JVM_NAME.shortName().asString()
|
val JVM_NAME_SHORT: String = JVM_NAME.shortName().asString()
|
||||||
|
|
||||||
val JVM_MULTIFILE_CLASS: FqName = FqName("kotlin.jvm.JvmMultifileClass")
|
|
||||||
val JVM_MULTIFILE_CLASS_SHORT = JVM_MULTIFILE_CLASS.shortName().asString()
|
|
||||||
|
|
||||||
val JVM_PACKAGE_NAME: FqName = FqName("kotlin.jvm.JvmPackageName")
|
|
||||||
private val JVM_PACKAGE_NAME_SHORT = JVM_PACKAGE_NAME.shortName().asString()
|
|
||||||
|
|
||||||
private const val MULTIFILE_PART_NAME_DELIMITER = "__"
|
|
||||||
|
|
||||||
fun getPartFqNameForDeserialized(descriptor: DeserializedMemberDescriptor): FqName =
|
fun getPartFqNameForDeserialized(descriptor: DeserializedMemberDescriptor): FqName =
|
||||||
descriptor.getImplClassNameForDeserialized()?.fqNameForTopLevelClassMaybeWithDollars
|
descriptor.getImplClassNameForDeserialized()?.fqNameForTopLevelClassMaybeWithDollars
|
||||||
?: error("No implClassName for $descriptor")
|
?: error("No implClassName for $descriptor")
|
||||||
@@ -138,7 +134,7 @@ val KtFile.javaFileFacadeFqName: FqName
|
|||||||
private val LOG = Logger.getInstance("JvmFileClassUtil")
|
private val LOG = Logger.getInstance("JvmFileClassUtil")
|
||||||
|
|
||||||
fun KtDeclaration.isInsideJvmMultifileClassFile() =
|
fun KtDeclaration.isInsideJvmMultifileClassFile() =
|
||||||
JvmFileClassUtil.findAnnotationEntryOnFileNoResolve(containingKtFile, JvmFileClassUtil.JVM_MULTIFILE_CLASS_SHORT) != null
|
JvmFileClassUtil.findAnnotationEntryOnFileNoResolve(containingKtFile, JVM_MULTIFILE_CLASS_SHORT) != null
|
||||||
|
|
||||||
fun DeclarationDescriptor.isTopLevelInJvmMultifileClass(): Boolean {
|
fun DeclarationDescriptor.isTopLevelInJvmMultifileClass(): Boolean {
|
||||||
if (containingDeclaration !is PackageFragmentDescriptor) return false
|
if (containingDeclaration !is PackageFragmentDescriptor) return false
|
||||||
|
|||||||
+6
-4
@@ -21,7 +21,9 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
|
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
import org.jetbrains.kotlin.name.JvmNames.JVM_MULTIFILE_CLASS
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_NAME
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_PACKAGE_NAME
|
||||||
import org.jetbrains.kotlin.name.isValidJavaFqName
|
import org.jetbrains.kotlin.name.isValidJavaFqName
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.AdditionalAnnotationChecker
|
import org.jetbrains.kotlin.resolve.AdditionalAnnotationChecker
|
||||||
@@ -35,7 +37,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
|||||||
|
|
||||||
object FileClassAnnotationsChecker : AdditionalAnnotationChecker {
|
object FileClassAnnotationsChecker : AdditionalAnnotationChecker {
|
||||||
// JvmName & JvmMultifileClass annotations are applicable to multi-file class parts regardless of their retention.
|
// JvmName & JvmMultifileClass annotations are applicable to multi-file class parts regardless of their retention.
|
||||||
private val alwaysApplicable = hashSetOf(JvmFileClassUtil.JVM_NAME, JvmFileClassUtil.JVM_MULTIFILE_CLASS)
|
private val alwaysApplicable = hashSetOf(JVM_NAME, JVM_MULTIFILE_CLASS)
|
||||||
|
|
||||||
override fun checkEntries(
|
override fun checkEntries(
|
||||||
entries: List<KtAnnotationEntry>,
|
entries: List<KtAnnotationEntry>,
|
||||||
@@ -55,7 +57,7 @@ object FileClassAnnotationsChecker : AdditionalAnnotationChecker {
|
|||||||
fileAnnotationsToCheck.add(Pair(entry, classDescriptor))
|
fileAnnotationsToCheck.add(Pair(entry, classDescriptor))
|
||||||
}
|
}
|
||||||
|
|
||||||
val isMultifileClass = fileAnnotationsToCheck.any { it.second.fqNameSafe == JvmFileClassUtil.JVM_MULTIFILE_CLASS }
|
val isMultifileClass = fileAnnotationsToCheck.any { it.second.fqNameSafe == JVM_MULTIFILE_CLASS }
|
||||||
|
|
||||||
if (isMultifileClass) {
|
if (isMultifileClass) {
|
||||||
for ((entry, classDescriptor) in fileAnnotationsToCheck) {
|
for ((entry, classDescriptor) in fileAnnotationsToCheck) {
|
||||||
@@ -67,7 +69,7 @@ object FileClassAnnotationsChecker : AdditionalAnnotationChecker {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for ((entry, classDescriptor) in fileAnnotationsToCheck) {
|
for ((entry, classDescriptor) in fileAnnotationsToCheck) {
|
||||||
if (classDescriptor.fqNameSafe != JvmFileClassUtil.JVM_PACKAGE_NAME) continue
|
if (classDescriptor.fqNameSafe != JVM_PACKAGE_NAME) continue
|
||||||
|
|
||||||
val argumentExpression = entry.valueArguments.firstOrNull()?.getArgumentExpression() ?: continue
|
val argumentExpression = entry.valueArguments.firstOrNull()?.getArgumentExpression() ?: continue
|
||||||
val stringTemplateEntries = (argumentExpression as? KtStringTemplateExpression)?.entries ?: continue
|
val stringTemplateEntries = (argumentExpression as? KtStringTemplateExpression)?.entries ?: continue
|
||||||
|
|||||||
+1
-16
@@ -32,28 +32,13 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
|
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
|
||||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
||||||
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmFieldAnnotation
|
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmFieldAnnotation
|
||||||
import org.jetbrains.kotlin.resolve.jvm.checkers.JvmFieldApplicabilityChecker.Problem.*
|
import org.jetbrains.kotlin.jvm.JvmFieldApplicabilityProblem.*
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
import org.jetbrains.kotlin.resolve.jvm.isInlineClassThatRequiresMangling
|
import org.jetbrains.kotlin.resolve.jvm.isInlineClassThatRequiresMangling
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
|
||||||
class JvmFieldApplicabilityChecker : DeclarationChecker {
|
class JvmFieldApplicabilityChecker : DeclarationChecker {
|
||||||
|
|
||||||
internal enum class Problem(val errorMessage: String) {
|
|
||||||
NOT_FINAL("JvmField can only be applied to final property"),
|
|
||||||
PRIVATE("JvmField has no effect on a private property"),
|
|
||||||
CUSTOM_ACCESSOR("JvmField cannot be applied to a property with a custom accessor"),
|
|
||||||
OVERRIDES("JvmField cannot be applied to a property that overrides some other property"),
|
|
||||||
LATEINIT("JvmField cannot be applied to lateinit property"),
|
|
||||||
CONST("JvmField cannot be applied to const property"),
|
|
||||||
INSIDE_COMPANION_OF_INTERFACE("JvmField cannot be applied to a property defined in companion object of interface"),
|
|
||||||
NOT_PUBLIC_VAL_WITH_JVMFIELD("JvmField could be applied only if all interface companion properties are 'public final val' with '@JvmField' annotation"),
|
|
||||||
TOP_LEVEL_PROPERTY_OF_MULTIFILE_FACADE("JvmField cannot be applied to top level property of a file annotated with ${JvmFileClassUtil.JVM_MULTIFILE_CLASS_SHORT}"),
|
|
||||||
DELEGATE("JvmField cannot be applied to delegated property"),
|
|
||||||
RETURN_TYPE_IS_INLINE_CLASS("JvmField cannot be applied to a property of an inline class type")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||||
if (descriptor !is PropertyDescriptor || (declaration !is KtProperty && declaration !is KtParameter)) return
|
if (descriptor !is PropertyDescriptor || (declaration !is KtProperty && declaration !is KtParameter)) return
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.idea.KotlinLanguage
|
|||||||
import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind
|
import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_NAME_SHORT
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
@@ -140,7 +141,7 @@ open class KtLightClassForFacadeImpl constructor(
|
|||||||
|
|
||||||
override fun setName(name: String): PsiElement? {
|
override fun setName(name: String): PsiElement? {
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
val jvmNameEntry = JvmFileClassUtil.findAnnotationEntryOnFileNoResolve(file, JvmFileClassUtil.JVM_NAME_SHORT)
|
val jvmNameEntry = JvmFileClassUtil.findAnnotationEntryOnFileNoResolve(file, JVM_NAME_SHORT)
|
||||||
|
|
||||||
if (PackagePartClassUtils.getFilePartShortName(file.name) == name) {
|
if (PackagePartClassUtils.getFilePartShortName(file.name) == name) {
|
||||||
jvmNameEntry?.delete()
|
jvmNameEntry?.delete()
|
||||||
@@ -156,7 +157,7 @@ open class KtLightClassForFacadeImpl constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val psiFactory = KtPsiFactory(this)
|
val psiFactory = KtPsiFactory(this)
|
||||||
val annotationText = "${JvmFileClassUtil.JVM_NAME_SHORT}(\"$name\")"
|
val annotationText = "${JVM_NAME_SHORT}(\"$name\")"
|
||||||
val newFileAnnotationList = psiFactory.createFileAnnotationListWithAnnotation(annotationText)
|
val newFileAnnotationList = psiFactory.createFileAnnotationListWithAnnotation(annotationText)
|
||||||
val annotationList = file.fileAnnotationList
|
val annotationList = file.fileAnnotationList
|
||||||
if (annotationList != null) {
|
if (annotationList != null) {
|
||||||
|
|||||||
+3
-3
@@ -12,12 +12,12 @@ import com.intellij.psi.util.CachedValue
|
|||||||
import org.jetbrains.kotlin.asJava.builder.LightClassData
|
import org.jetbrains.kotlin.asJava.builder.LightClassData
|
||||||
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolder
|
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolder
|
||||||
import org.jetbrains.kotlin.asJava.elements.*
|
import org.jetbrains.kotlin.asJava.elements.*
|
||||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
|
||||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil.JVM_MULTIFILE_CLASS_SHORT
|
|
||||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil.findAnnotationEntryOnFileNoResolve
|
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil.findAnnotationEntryOnFileNoResolve
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_MULTIFILE_CLASS
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_MULTIFILE_CLASS_SHORT
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
import org.jetbrains.kotlin.psi.KtProperty
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
@@ -127,7 +127,7 @@ class KtUltraLightClassForFacade(
|
|||||||
|
|
||||||
private val multiFileClass: Boolean by lazyPub {
|
private val multiFileClass: Boolean by lazyPub {
|
||||||
filesWithSupports.any {
|
filesWithSupports.any {
|
||||||
it.second.findAnnotation(it.first, JvmFileClassUtil.JVM_MULTIFILE_CLASS) != null
|
it.second.findAnnotation(it.first, JVM_MULTIFILE_CLASS) != null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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.kotlin.jvm
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.name.JvmNames.JVM_MULTIFILE_CLASS_SHORT
|
||||||
|
|
||||||
|
enum class JvmFieldApplicabilityProblem(val errorMessage: String) {
|
||||||
|
NOT_FINAL("JvmField can only be applied to final property"),
|
||||||
|
PRIVATE("JvmField has no effect on a private property"),
|
||||||
|
CUSTOM_ACCESSOR("JvmField cannot be applied to a property with a custom accessor"),
|
||||||
|
OVERRIDES("JvmField cannot be applied to a property that overrides some other property"),
|
||||||
|
LATEINIT("JvmField cannot be applied to lateinit property"),
|
||||||
|
CONST("JvmField cannot be applied to const property"),
|
||||||
|
INSIDE_COMPANION_OF_INTERFACE("JvmField cannot be applied to a property defined in companion object of interface"),
|
||||||
|
NOT_PUBLIC_VAL_WITH_JVMFIELD("JvmField could be applied only if all interface companion properties are 'public final val' with '@JvmField' annotation"),
|
||||||
|
TOP_LEVEL_PROPERTY_OF_MULTIFILE_FACADE("JvmField cannot be applied to top level property of a file annotated with ${JVM_MULTIFILE_CLASS_SHORT}"),
|
||||||
|
DELEGATE("JvmField cannot be applied to delegated property"),
|
||||||
|
RETURN_TYPE_IS_INLINE_CLASS("JvmField cannot be applied to a property of an inline class type")
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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.kotlin.name
|
||||||
|
|
||||||
|
object JvmNames {
|
||||||
|
val JVM_NAME: FqName = FqName("kotlin.jvm.JvmName")
|
||||||
|
val JVM_NAME_SHORT: String = JVM_NAME.shortName().asString()
|
||||||
|
|
||||||
|
val JVM_MULTIFILE_CLASS: FqName = FqName("kotlin.jvm.JvmMultifileClass")
|
||||||
|
val JVM_MULTIFILE_CLASS_SHORT = JVM_MULTIFILE_CLASS.shortName().asString()
|
||||||
|
|
||||||
|
val JVM_PACKAGE_NAME: FqName = FqName("kotlin.jvm.JvmPackageName")
|
||||||
|
val JVM_PACKAGE_NAME_SHORT = JVM_PACKAGE_NAME.shortName().asString()
|
||||||
|
|
||||||
|
const val MULTIFILE_PART_NAME_DELIMITER = "__"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user