Add LanguageVersionSettings to KotlinTypeMapper
KotlinTypeMapper clients should use proper LanguageVersionSettings when possible.
This commit is contained in:
+2
-1
@@ -18,7 +18,8 @@ class KotlinToJvmSignatureMapperImpl : KotlinToJvmSignatureMapper {
|
||||
// We use empty BindingContext, because it is only used by KotlinTypeMapper for purposes irrelevant to the needs of this class
|
||||
private val typeMapper = KotlinTypeMapper(
|
||||
BindingContext.EMPTY, ClassBuilderMode.LIGHT_CLASSES,
|
||||
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT, KotlinTypeMapper.RELEASE_COROUTINES_DEFAULT,
|
||||
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT,
|
||||
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT, // TODO use proper LanguageVersionSettings
|
||||
false
|
||||
)
|
||||
|
||||
|
||||
+3
-2
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.codegen.ClassBuilderFactory
|
||||
import org.jetbrains.kotlin.codegen.ClassBuilderMode
|
||||
import org.jetbrains.kotlin.codegen.SignatureCollectingClassBuilderFactory
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DELEGATION
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
@@ -48,7 +49,7 @@ class BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||
bindingContext: BindingContext,
|
||||
private val diagnostics: DiagnosticSink,
|
||||
moduleName: String,
|
||||
isReleaseCoroutines: Boolean,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
shouldGenerate: (JvmDeclarationOrigin) -> Boolean,
|
||||
isIrBackend: Boolean
|
||||
) : SignatureCollectingClassBuilderFactory(builderFactory, shouldGenerate) {
|
||||
@@ -56,7 +57,7 @@ class BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||
// Avoid errors when some classes are not loaded for some reason
|
||||
private val typeMapper = KotlinTypeMapper(
|
||||
bindingContext, ClassBuilderMode.LIGHT_CLASSES, IncompatibleClassTracker.DoNothing, moduleName, JvmTarget.DEFAULT,
|
||||
isReleaseCoroutines, isIrBackend
|
||||
languageVersionSettings, isIrBackend
|
||||
)
|
||||
private val reportDiagnosticsTasks = ArrayList<() -> Unit>()
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ class GenerationState private constructor(
|
||||
IncompatibleClassTrackerImpl(extraJvmDiagnosticsTrace),
|
||||
this.moduleName,
|
||||
target,
|
||||
configuration.languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines),
|
||||
languageVersionSettings,
|
||||
isIrBackend
|
||||
)
|
||||
val intrinsics: IntrinsicMethods = run {
|
||||
@@ -260,8 +260,7 @@ class GenerationState private constructor(
|
||||
},
|
||||
{
|
||||
BuilderFactoryForDuplicateSignatureDiagnostics(
|
||||
it, this.bindingContext, diagnostics, this.moduleName,
|
||||
isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines),
|
||||
it, this.bindingContext, diagnostics, this.moduleName, this.languageVersionSettings,
|
||||
shouldGenerate = { !shouldOnlyCollectSignatures(it) },
|
||||
isIrBackend = isIrBackend
|
||||
).apply { duplicateSignatureFactory = this }
|
||||
|
||||
@@ -25,6 +25,9 @@ import org.jetbrains.kotlin.codegen.signature.AsmTypeFactory;
|
||||
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
|
||||
import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter;
|
||||
import org.jetbrains.kotlin.config.JvmTarget;
|
||||
import org.jetbrains.kotlin.config.LanguageFeature;
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings;
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableAccessorDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||
@@ -84,6 +87,7 @@ public class KotlinTypeMapper {
|
||||
private final IncompatibleClassTracker incompatibleClassTracker;
|
||||
private final String moduleName;
|
||||
private final JvmTarget jvmTarget;
|
||||
private final LanguageVersionSettings languageVersionSettings;
|
||||
private final boolean isReleaseCoroutines;
|
||||
private final boolean isIrBackend;
|
||||
|
||||
@@ -156,7 +160,7 @@ public class KotlinTypeMapper {
|
||||
@NotNull IncompatibleClassTracker incompatibleClassTracker,
|
||||
@NotNull String moduleName,
|
||||
@NotNull JvmTarget jvmTarget,
|
||||
boolean isReleaseCoroutines,
|
||||
@NotNull LanguageVersionSettings languageVersionSettings,
|
||||
boolean isIrBackend
|
||||
) {
|
||||
this.bindingContext = bindingContext;
|
||||
@@ -164,11 +168,15 @@ public class KotlinTypeMapper {
|
||||
this.incompatibleClassTracker = incompatibleClassTracker;
|
||||
this.moduleName = moduleName;
|
||||
this.jvmTarget = jvmTarget;
|
||||
this.isReleaseCoroutines = isReleaseCoroutines;
|
||||
this.languageVersionSettings = languageVersionSettings;
|
||||
this.isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines);
|
||||
this.isIrBackend = isIrBackend;
|
||||
}
|
||||
|
||||
public static final boolean RELEASE_COROUTINES_DEFAULT = false;
|
||||
/**
|
||||
* Use proper LanguageVersionSettings where possible.
|
||||
*/
|
||||
public static final LanguageVersionSettings LANGUAGE_VERSION_SETTINGS_DEFAULT = LanguageVersionSettingsImpl.DEFAULT;
|
||||
|
||||
@NotNull
|
||||
public BindingContext getBindingContext() {
|
||||
|
||||
@@ -104,5 +104,6 @@ internal fun typeMapper(support: UltraLightSupport): KotlinTypeMapper = KotlinTy
|
||||
BindingContext.EMPTY, ClassBuilderMode.LIGHT_CLASSES,
|
||||
IncompatibleClassTracker.DoNothing, support.moduleName,
|
||||
JvmTarget.JVM_1_8,
|
||||
true, false
|
||||
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT, // TODO use proper LanguageVersionSettings
|
||||
false
|
||||
)
|
||||
|
||||
@@ -345,7 +345,8 @@ abstract class FileRankingCalculator(private val checkClassFqName: Boolean = tru
|
||||
private fun makeTypeMapper(bindingContext: BindingContext): KotlinTypeMapper {
|
||||
return KotlinTypeMapper(
|
||||
bindingContext, ClassBuilderMode.LIGHT_CLASSES, IncompatibleClassTracker.DoNothing, "debugger", JvmTarget.DEFAULT,
|
||||
KotlinTypeMapper.RELEASE_COROUTINES_DEFAULT, false
|
||||
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT, // TODO use proper LanguageVersionSettings
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.codegen.FrameMap
|
||||
import org.jetbrains.kotlin.codegen.state.IncompatibleClassTracker
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
@@ -46,7 +47,8 @@ class ParcelableDeclarationChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
val trace = context.trace
|
||||
when (descriptor) {
|
||||
is ClassDescriptor -> checkParcelableClass(descriptor, declaration, trace, trace.bindingContext)
|
||||
is ClassDescriptor ->
|
||||
checkParcelableClass(descriptor, declaration, trace, trace.bindingContext, context.languageVersionSettings)
|
||||
is SimpleFunctionDescriptor -> {
|
||||
val containingClass = descriptor.containingDeclaration as? ClassDescriptor
|
||||
val ktFunction = declaration as? KtFunction
|
||||
@@ -113,7 +115,8 @@ class ParcelableDeclarationChecker : DeclarationChecker {
|
||||
descriptor: ClassDescriptor,
|
||||
declaration: KtDeclaration,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
bindingContext: BindingContext,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
if (!descriptor.isParcelize) return
|
||||
|
||||
@@ -181,7 +184,7 @@ class ParcelableDeclarationChecker : DeclarationChecker {
|
||||
IncompatibleClassTracker.DoNothing,
|
||||
descriptor.module.name.asString(),
|
||||
JvmTarget.DEFAULT,
|
||||
KotlinTypeMapper.RELEASE_COROUTINES_DEFAULT,
|
||||
languageVersionSettings,
|
||||
false
|
||||
)
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ class IdeaKotlinUastResolveProviderService : KotlinUastResolveProviderService {
|
||||
override fun getTypeMapper(element: KtElement): KotlinTypeMapper? {
|
||||
return KotlinTypeMapper(
|
||||
getBindingContext(element), ClassBuilderMode.LIGHT_CLASSES,
|
||||
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT, KotlinTypeMapper.RELEASE_COROUTINES_DEFAULT,
|
||||
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT,
|
||||
element.languageVersionSettings,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
+2
-1
@@ -57,7 +57,8 @@ class UastAnalysisHandlerExtension : AnalysisHandlerExtension {
|
||||
|
||||
val typeMapper = KotlinTypeMapper(
|
||||
bindingContext, ClassBuilderMode.LIGHT_CLASSES,
|
||||
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT, KotlinTypeMapper.RELEASE_COROUTINES_DEFAULT,
|
||||
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT,
|
||||
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT, // TODO use proper LanguageVersionSettings
|
||||
false
|
||||
)
|
||||
this.typeMapper = typeMapper
|
||||
|
||||
Reference in New Issue
Block a user