Get rid of some KotlinBuiltIns#getBuiltInsModule usages
There will be no separate module for built-ins soon, they will be resolved as normal dependencies
This commit is contained in:
@@ -26,22 +26,24 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||
import org.jetbrains.kotlin.container.ComponentProvider;
|
||||
import org.jetbrains.kotlin.container.DslKt;
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||
import org.jetbrains.kotlin.psi.KtTypeProjection;
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference;
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.kotlin.tests.di.InjectionKt;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -49,7 +51,7 @@ import java.util.Set;
|
||||
public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
private Set<TypeConstructor> variables;
|
||||
|
||||
private KotlinBuiltIns builtIns;
|
||||
private ModuleDescriptor module;
|
||||
private ImportingScope builtinsImportingScope;
|
||||
private TypeResolver typeResolver;
|
||||
private TypeParameterDescriptor x;
|
||||
@@ -64,17 +66,17 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ModuleDescriptorImpl module = KotlinTestUtils.createEmptyModule();
|
||||
builtIns = module.getBuiltIns();
|
||||
ComponentProvider container = JvmResolveUtil.createContainer(getEnvironment());
|
||||
module = DslKt.getService(container, ModuleDescriptor.class);
|
||||
|
||||
builtinsImportingScope = ScopeUtilsKt.chainImportingScopes(
|
||||
// builtIns.builtinsPackageFragments.map { it.memberScope.memberScopeAsImportingScope() }
|
||||
CollectionsKt.map(builtIns.getBuiltInsPackageFragments(), new Function1<PackageFragmentDescriptor, ImportingScope>() {
|
||||
CollectionsKt.map(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAMES, new Function1<FqName, ImportingScope>() {
|
||||
@Override
|
||||
public ImportingScope invoke(PackageFragmentDescriptor packageFragment) {
|
||||
return ScopeUtilsKt.memberScopeAsImportingScope(packageFragment.getMemberScope());
|
||||
public ImportingScope invoke(FqName fqName) {
|
||||
return ScopeUtilsKt.memberScopeAsImportingScope(module.getPackage(fqName).getMemberScope());
|
||||
}
|
||||
}), null);
|
||||
typeResolver = InjectionKt.createContainerForTests(getProject(), module).getTypeResolver();
|
||||
typeResolver = DslKt.getService(container, TypeResolver.class);
|
||||
x = createTypeVariable("X");
|
||||
y = createTypeVariable("Y");
|
||||
variables = Sets.newHashSet(x.getTypeConstructor(), y.getTypeConstructor());
|
||||
@@ -82,8 +84,8 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
|
||||
private TypeParameterDescriptor createTypeVariable(String name) {
|
||||
return TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
builtIns.getBuiltInsModule(), Annotations.Companion.getEMPTY(), false, Variance.INVARIANT,
|
||||
Name.identifier(name), 0);
|
||||
module, Annotations.Companion.getEMPTY(), false, Variance.INVARIANT, Name.identifier(name), 0
|
||||
);
|
||||
}
|
||||
|
||||
public void testNoVariables() throws Exception {
|
||||
@@ -207,16 +209,18 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
|
||||
private TypeProjection makeType(String typeStr) {
|
||||
LexicalScope withX = new LexicalScopeImpl(builtinsImportingScope, builtIns.getBuiltInsModule(),
|
||||
false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addClassifierDescriptor(x);
|
||||
handler.addClassifierDescriptor(y);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
LexicalScope withX = new LexicalScopeImpl(
|
||||
builtinsImportingScope, module,
|
||||
false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addClassifierDescriptor(x);
|
||||
handler.addClassifierDescriptor(y);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
KtTypeProjection projection = KtPsiFactoryKt
|
||||
.KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0);
|
||||
|
||||
+5
-11
@@ -238,17 +238,11 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
scope: LexicalScope,
|
||||
resolutionFacade: ResolutionFacade
|
||||
): BindingContext {
|
||||
val traceContext = BindingTraceContext()
|
||||
val frontendService = if (module.builtIns.builtInsModule == module) {
|
||||
// TODO: doubtful place, do we require this module or not? Built-ins module doesn't have some necessary components...
|
||||
resolutionFacade.getFrontendService(ExpressionTypingServices::class.java)
|
||||
}
|
||||
else {
|
||||
resolutionFacade.getFrontendService(module, ExpressionTypingServices::class.java)
|
||||
}
|
||||
PreliminaryDeclarationVisitor.createForExpression(expression, traceContext)
|
||||
frontendService.getTypeInfo(scope, expression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, traceContext, false)
|
||||
return traceContext.bindingContext
|
||||
val trace = BindingTraceContext()
|
||||
val expressionTypingServices = resolutionFacade.getFrontendService(module, ExpressionTypingServices::class.java)
|
||||
PreliminaryDeclarationVisitor.createForExpression(expression, trace)
|
||||
expressionTypingServices.getTypeInfo(scope, expression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, trace, false)
|
||||
return trace.bindingContext
|
||||
}
|
||||
|
||||
private fun getResolutionScope(descriptor: DeclarationDescriptor, ownerDescriptor: DeclarationDescriptor, additionalScopes: Collection<ImportingScope>): LexicalScope? {
|
||||
|
||||
+2
-3
@@ -29,6 +29,7 @@ import com.intellij.usageView.UsageInfo
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.*
|
||||
@@ -41,7 +42,6 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isInsideOf
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
@@ -152,8 +152,7 @@ class MoveConflictChecker(
|
||||
declaration.forEachDescendantOfType<KtReferenceExpression> { refExpr ->
|
||||
val targetDescriptor = refExpr.analyze(BodyResolveMode.PARTIAL)[BindingContext.REFERENCE_TARGET, refExpr] ?: return@forEachDescendantOfType
|
||||
|
||||
val module = targetDescriptor.module
|
||||
if (module.builtIns.builtInsModule == module) return@forEachDescendantOfType
|
||||
if (KotlinBuiltIns.isBuiltIn(targetDescriptor)) return@forEachDescendantOfType
|
||||
|
||||
val target = DescriptorToSourceUtilsIde.getAnyDeclaration(project, targetDescriptor) ?: return@forEachDescendantOfType
|
||||
|
||||
|
||||
+2
-3
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.fileClasses.OldPackageFacadeClassUtils
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
@@ -25,7 +26,6 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.junit.Assert
|
||||
|
||||
@@ -77,8 +77,7 @@ abstract class TextConsistencyBaseTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
override fun resolveDeclarationsInFacade(facadeFqName: FqName): List<DeclarationDescriptor> =
|
||||
module.getPackage(facadeFqName.parent()).memberScope.getContributedDescriptors().filter {
|
||||
(it is CallableMemberDescriptor && isFromFacade(it, facadeFqName) || it is TypeAliasDescriptor) &&
|
||||
it.module != module.builtIns.builtInsModule
|
||||
!KotlinBuiltIns.isBuiltIn(it)
|
||||
}.sortedWith(MemberComparator.INSTANCE)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user