Support declarations returning object literals in ultra-light classes

This commit is contained in:
Denis Zharkov
2018-11-20 12:24:26 +03:00
parent 28f20a97f8
commit 7de8b4de4e
8 changed files with 250 additions and 46 deletions
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiElement;
import kotlin.Pair;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment;
@@ -89,6 +90,8 @@ public class KotlinTypeMapper {
private final LanguageVersionSettings languageVersionSettings;
private final boolean isReleaseCoroutines;
private final boolean isIrBackend;
@Nullable
private final Function1<KotlinType, KotlinType> typePreprocessor;
private final TypeMappingConfiguration<Type> typeMappingConfiguration = new TypeMappingConfiguration<Type>() {
@NotNull
@@ -121,6 +124,13 @@ public class KotlinTypeMapper {
public boolean releaseCoroutines() {
return isReleaseCoroutines;
}
@Nullable
@Override
public KotlinType preprocessType(@NotNull KotlinType kotlinType) {
if (typePreprocessor == null) return null;
return typePreprocessor.invoke(kotlinType);
}
};
private static final TypeMappingConfiguration<Type> staticTypeMappingConfiguration = new TypeMappingConfiguration<Type>() {
@@ -151,8 +161,35 @@ public class KotlinTypeMapper {
public boolean releaseCoroutines() {
return false;
}
@Nullable
@Override
public KotlinType preprocessType(@NotNull KotlinType kotlinType) {
return null;
}
};
public KotlinTypeMapper(
@NotNull BindingContext bindingContext,
@NotNull ClassBuilderMode classBuilderMode,
@NotNull IncompatibleClassTracker incompatibleClassTracker,
@NotNull String moduleName,
@NotNull JvmTarget jvmTarget,
@NotNull LanguageVersionSettings languageVersionSettings,
boolean isIrBackend,
@Nullable Function1<KotlinType, KotlinType> typePreprocessor
) {
this.bindingContext = bindingContext;
this.classBuilderMode = classBuilderMode;
this.incompatibleClassTracker = incompatibleClassTracker;
this.moduleName = moduleName;
this.jvmTarget = jvmTarget;
this.languageVersionSettings = languageVersionSettings;
this.isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines);
this.isIrBackend = isIrBackend;
this.typePreprocessor = typePreprocessor;
}
public KotlinTypeMapper(
@NotNull BindingContext bindingContext,
@NotNull ClassBuilderMode classBuilderMode,
@@ -162,14 +199,7 @@ public class KotlinTypeMapper {
@NotNull LanguageVersionSettings languageVersionSettings,
boolean isIrBackend
) {
this.bindingContext = bindingContext;
this.classBuilderMode = classBuilderMode;
this.incompatibleClassTracker = incompatibleClassTracker;
this.moduleName = moduleName;
this.jvmTarget = jvmTarget;
this.languageVersionSettings = languageVersionSettings;
this.isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines);
this.isIrBackend = isIrBackend;
this(bindingContext, classBuilderMode, incompatibleClassTracker, moduleName, jvmTarget, languageVersionSettings, isIrBackend, null);
}
/**