Add default values to KotlinTypeMapper constructor, remove them from call sites

~
This commit is contained in:
Mikhael Bogdanov
2019-03-05 12:00:55 +01:00
parent cc0c3b1592
commit 20da778046
13 changed files with 33 additions and 53 deletions
@@ -160,7 +160,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
if (!state.classBuilderMode.generateBodies) {
FunctionCodegen.generateLocalVariablesForParameters(
mv, signature, functionDescriptor, null, Label(), Label(), remainingParameters, isStatic, typeMapper
mv, signature, functionDescriptor, null, Label(), Label(), remainingParameters, isStatic, state
)
mv.visitEnd()
return
@@ -245,7 +245,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
mv.visitLabel(methodEnd)
FunctionCodegen.generateLocalVariablesForParameters(
mv, signature, functionDescriptor, null, methodBegin, methodEnd, remainingParameters, isStatic, typeMapper
mv, signature, functionDescriptor, null, methodBegin, methodEnd, remainingParameters, isStatic, state
)
FunctionCodegen.endVisit(mv, null, methodElement)
@@ -459,7 +459,7 @@ public class FunctionCodegen {
new Label(),
new Label(),
contextKind,
typeMapper,
state,
Collections.emptyList(),
0);
@@ -695,7 +695,7 @@ public class FunctionCodegen {
}
generateLocalVariableTable(
mv, signature, functionDescriptor, thisType, methodBegin, methodEnd, context.getContextKind(), typeMapper,
mv, signature, functionDescriptor, thisType, methodBegin, methodEnd, context.getContextKind(), parentCodegen.state,
destructuredParametersForSuspendLambda, (functionFakeIndex >= 0 ? 1 : 0) + (lambdaFakeIndex >= 0 ? 1 : 0)
);
@@ -756,7 +756,7 @@ public class FunctionCodegen {
@NotNull Label methodBegin,
@NotNull Label methodEnd,
@NotNull OwnerKind ownerKind,
@NotNull KotlinTypeMapper typeMapper,
@NotNull GenerationState state,
@NotNull List<ValueParameterDescriptor> destructuredParametersForSuspendLambda,
int shiftForDestructuringVariables
) {
@@ -776,7 +776,7 @@ public class FunctionCodegen {
)
),
unwrapped,
thisType, methodBegin, methodEnd, ownerKind, typeMapper, destructuredParametersForSuspendLambda,
thisType, methodBegin, methodEnd, ownerKind, state, destructuredParametersForSuspendLambda,
shiftForDestructuringVariables
);
return;
@@ -787,7 +787,7 @@ public class FunctionCodegen {
jvmMethodSignature, functionDescriptor,
thisType, methodBegin, methodEnd, functionDescriptor.getValueParameters(),
destructuredParametersForSuspendLambda,
AsmUtil.isStaticMethod(ownerKind, functionDescriptor), typeMapper, shiftForDestructuringVariables
AsmUtil.isStaticMethod(ownerKind, functionDescriptor), state, shiftForDestructuringVariables
);
}
@@ -800,11 +800,11 @@ public class FunctionCodegen {
@NotNull Label methodEnd,
Collection<ValueParameterDescriptor> valueParameters,
boolean isStatic,
KotlinTypeMapper typeMapper
@NotNull GenerationState state
) {
generateLocalVariablesForParameters(
mv, jvmMethodSignature, functionDescriptor,
thisType, methodBegin, methodEnd, valueParameters, Collections.emptyList(), isStatic, typeMapper,
thisType, methodBegin, methodEnd, valueParameters, Collections.emptyList(), isStatic, state,
0);
}
@@ -818,7 +818,7 @@ public class FunctionCodegen {
Collection<ValueParameterDescriptor> valueParameters,
@NotNull List<ValueParameterDescriptor> destructuredParametersForSuspendLambda,
boolean isStatic,
KotlinTypeMapper typeMapper,
@NotNull GenerationState state,
int shiftForDestructuringVariables
) {
Iterator<ValueParameterDescriptor> valueParameterIterator = valueParameters.iterator();
@@ -836,6 +836,7 @@ public class FunctionCodegen {
shift++;
}
KotlinTypeMapper typeMapper = state.getTypeMapper();
for (int i = 0; i < params.size(); i++) {
JvmMethodParameterSignature param = params.get(i);
JvmMethodParameterKind kind = param.getKind();
@@ -852,7 +853,7 @@ public class FunctionCodegen {
}
else if (kind == JvmMethodParameterKind.RECEIVER) {
parameterName = AsmUtil.getNameForReceiverParameter(
functionDescriptor, typeMapper.getBindingContext(), typeMapper.getLanguageVersionSettings());
functionDescriptor, typeMapper.getBindingContext(), state.getLanguageVersionSettings());
}
else {
String lowercaseKind = kind.name().toLowerCase();
@@ -6,9 +6,7 @@
package org.jetbrains.kotlin.codegen.signature
import org.jetbrains.kotlin.codegen.ClassBuilderMode
import org.jetbrains.kotlin.codegen.state.IncompatibleClassTracker
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.resolve.BindingContext
@@ -18,8 +16,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.LANGUAGE_VERSION_SETTINGS_DEFAULT // TODO use proper LanguageVersionSettings
JvmAbi.DEFAULT_MODULE_NAME,
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT// TODO use proper LanguageVersionSettings
)
override fun mapToJvmMethodSignature(function: FunctionDescriptor) = typeMapper.mapAsmMethod(function)
@@ -10,7 +10,6 @@ import com.intellij.util.containers.MultiMap
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
@@ -56,8 +55,8 @@ 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,
languageVersionSettings, isIrBackend
bindingContext, ClassBuilderMode.LIGHT_CLASSES, moduleName, languageVersionSettings,
isIrBackend = isIrBackend
)
private val reportDiagnosticsTasks = ArrayList<() -> Unit>()
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.psi.KtScript
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.deprecation.CoroutineCompatibilitySupport
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
import org.jetbrains.kotlin.resolve.deprecation.DeprecationSettings
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
@@ -192,10 +191,10 @@ class GenerationState private constructor(
val typeMapper: KotlinTypeMapper = KotlinTypeMapper(
this.bindingContext,
classBuilderMode,
IncompatibleClassTrackerImpl(extraJvmDiagnosticsTrace),
this.moduleName,
target,
languageVersionSettings,
IncompatibleClassTrackerImpl(extraJvmDiagnosticsTrace),
target,
isIrBackend
)
val intrinsics: IntrinsicMethods = run {
@@ -78,12 +78,12 @@ import kotlin.collections.*
class KotlinTypeMapper @JvmOverloads constructor(
val bindingContext: BindingContext,
val classBuilderMode: ClassBuilderMode,
private val incompatibleClassTracker: IncompatibleClassTracker,
private val moduleName: String,
val jvmTarget: JvmTarget,
private val languageVersionSettings: LanguageVersionSettings,
private val incompatibleClassTracker: IncompatibleClassTracker = IncompatibleClassTracker.DoNothing,
val jvmTarget: JvmTarget = JvmTarget.DEFAULT,
private val isIrBackend: Boolean = false,
private val typePreprocessor: Function1<KotlinType, KotlinType?>? = null
private val typePreprocessor: ((KotlinType) -> KotlinType?)? = null
) {
private val isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
@@ -116,10 +116,6 @@ class KotlinTypeMapper @JvmOverloads constructor(
}
}
fun getLanguageVersionSettings(): LanguageVersionSettings {
return languageVersionSettings
}
fun mapOwner(descriptor: DeclarationDescriptor): Type {
return mapOwner(descriptor, true)
}
@@ -134,11 +134,9 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
override val typeMapper: KotlinTypeMapper by lazyPub {
KotlinTypeMapper(
BindingContext.EMPTY, ClassBuilderMode.LIGHT_CLASSES,
IncompatibleClassTracker.DoNothing, moduleName,
JvmTarget.JVM_1_8,
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT, // TODO use proper LanguageVersionSettings
false,
KotlinType::cleanFromAnonymousTypes
moduleName, KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT, // TODO use proper LanguageVersionSettings
jvmTarget = JvmTarget.JVM_1_8,
typePreprocessor = KotlinType::cleanFromAnonymousTypes
)
}
})
@@ -10,9 +10,7 @@ import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.psi.PsiElement
import com.sun.jdi.*
import org.jetbrains.kotlin.codegen.ClassBuilderMode
import org.jetbrains.kotlin.codegen.state.IncompatibleClassTracker
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -344,7 +342,9 @@ 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,
bindingContext,
ClassBuilderMode.LIGHT_CLASSES,
"debugger",
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT // TODO use proper LanguageVersionSettings
)
}
@@ -12,9 +12,7 @@ import org.jetbrains.kotlin.android.synthetic.diagnostic.DefaultErrorMessagesAnd
import org.jetbrains.kotlin.android.synthetic.diagnostic.ErrorsAndroid
import org.jetbrains.kotlin.codegen.ClassBuilderMode
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
@@ -181,9 +179,7 @@ class ParcelableDeclarationChecker : DeclarationChecker {
val typeMapper = KotlinTypeMapper(
bindingContext,
ClassBuilderMode.FULL,
IncompatibleClassTracker.DoNothing,
descriptor.module.name.asString(),
JvmTarget.DEFAULT,
languageVersionSettings
)
@@ -23,9 +23,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.CachedValueProvider.Result
import com.intellij.psi.util.CachedValuesManager
import org.jetbrains.kotlin.codegen.ClassBuilderMode
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.DeclarationDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -48,8 +46,7 @@ class IdeaKotlinUastResolveProviderService : KotlinUastResolveProviderService {
override fun getTypeMapper(element: KtElement): KotlinTypeMapper? {
return KotlinTypeMapper(
getBindingContext(element), ClassBuilderMode.LIGHT_CLASSES,
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT,
element.languageVersionSettings
JvmAbi.DEFAULT_MODULE_NAME, element.languageVersionSettings
)
}
@@ -44,9 +44,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,
element.languageVersionSettings,
false
JvmAbi.DEFAULT_MODULE_NAME,
element.languageVersionSettings
)
}
@@ -4,9 +4,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.codegen.ClassBuilderMode
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.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.container.ComponentProvider
@@ -61,7 +59,7 @@ class UastAnalysisHandlerExtension : AnalysisHandlerExtension {
val typeMapper = KotlinTypeMapper(
bindingContext, ClassBuilderMode.LIGHT_CLASSES,
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT,
JvmAbi.DEFAULT_MODULE_NAME,
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT // TODO use proper LanguageVersionSettings
)
this.typeMapper = typeMapper
@@ -57,9 +57,8 @@ class UastAnalysisHandlerExtension : AnalysisHandlerExtension {
val typeMapper = KotlinTypeMapper(
bindingContext, ClassBuilderMode.LIGHT_CLASSES,
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, JvmTarget.DEFAULT,
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT, // TODO use proper LanguageVersionSettings
false
JvmAbi.DEFAULT_MODULE_NAME,
KotlinTypeMapper.LANGUAGE_VERSION_SETTINGS_DEFAULT // TODO use proper LanguageVersionSettings
)
this.typeMapper = typeMapper
return typeMapper