Load additional JDK functions into built-ins member scope
#KT-5990 Fixed #KT-7127 Fixed #KT-10370 Fixed
This commit is contained in:
@@ -355,7 +355,11 @@ public abstract class AbstractDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
|
||||
@NotNull
|
||||
protected ModuleDescriptorImpl createModule(@NotNull String moduleName, @NotNull StorageManager storageManager) {
|
||||
return TargetPlatformKt.createModule(JvmPlatform.INSTANCE, Name.special(moduleName), storageManager, JvmBuiltIns.getInstance());
|
||||
JvmBuiltIns builtIns = new JvmBuiltIns(storageManager);
|
||||
ModuleDescriptorImpl module = TargetPlatformKt.createModule(
|
||||
JvmPlatform.INSTANCE, Name.special(moduleName), storageManager, builtIns);
|
||||
builtIns.setOwnerModuleDescriptor(module);
|
||||
return module;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+6
-2
@@ -60,9 +60,11 @@ class MultiModuleJavaAnalysisCustomTest : KtUsefulTestCase() {
|
||||
val moduleDirs = File(PATH_TO_TEST_ROOT_DIR).listFiles { it -> it.isDirectory }!!
|
||||
val environment = createEnvironment(moduleDirs)
|
||||
val modules = setupModules(environment, moduleDirs)
|
||||
val projectContext = ProjectContext(environment.project)
|
||||
val builtIns = JvmBuiltIns(projectContext.storageManager)
|
||||
val resolverForProject = JvmAnalyzerFacade.setupResolverForProject(
|
||||
"test",
|
||||
ProjectContext(environment.project), modules,
|
||||
projectContext, modules,
|
||||
{ m -> ModuleContent(m.kotlinFiles, m.javaFilesScope) },
|
||||
JvmPlatformParameters {
|
||||
javaClass ->
|
||||
@@ -70,10 +72,12 @@ class MultiModuleJavaAnalysisCustomTest : KtUsefulTestCase() {
|
||||
modules.first { it._name == moduleName }
|
||||
},
|
||||
CompilerEnvironment,
|
||||
JvmBuiltIns.Instance,
|
||||
builtIns,
|
||||
packagePartProviderFactory = { a, b -> JvmPackagePartProvider(environment) }
|
||||
)
|
||||
|
||||
builtIns.setOwnerModuleDescriptor(resolverForProject.descriptorForModule(resolverForProject.allModules.first()))
|
||||
|
||||
performChecks(resolverForProject, modules)
|
||||
}
|
||||
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.builtins
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.*
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.context.ModuleContext
|
||||
import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
||||
import org.jetbrains.kotlin.frontend.java.di.createContainerForTopDownAnalyzerForJvm
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.JvmBuiltIns
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractBuiltInsWithJDKMembersTest : KotlinTestWithEnvironment() {
|
||||
override fun createEnvironment(): KotlinCoreEnvironment {
|
||||
return createEnvironmentWithJdk(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK)
|
||||
}
|
||||
|
||||
protected fun doTest(builtinVersionName: String) {
|
||||
val configuration = RecursiveDescriptorComparator.RECURSIVE_ALL.includeMethodsOfKotlinAny(false).withRenderer(
|
||||
DescriptorRenderer.withOptions {
|
||||
withDefinedIn = false
|
||||
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE
|
||||
verbose = true
|
||||
modifiers = DescriptorRendererModifier.ALL
|
||||
})
|
||||
|
||||
val jvmBuiltIns = JvmBuiltIns(LockBasedStorageManager.NO_LOCKS)
|
||||
val emptyModule = KotlinTestUtils.createEmptyModule("<empty>", JvmPlatform, jvmBuiltIns)
|
||||
jvmBuiltIns.setOwnerModuleDescriptor(emptyModule)
|
||||
|
||||
val moduleContext = ModuleContext(emptyModule, environment.project)
|
||||
val providerFactory = FileBasedDeclarationProviderFactory(moduleContext.storageManager, emptyList())
|
||||
|
||||
val container = createContainerForTopDownAnalyzerForJvm(
|
||||
moduleContext,
|
||||
CliLightClassGenerationSupport.CliBindingTrace(), providerFactory,
|
||||
GlobalSearchScope.allScope(environment.project), LookupTracker.DO_NOTHING, PackagePartProvider.EMPTY)
|
||||
|
||||
emptyModule.initialize(container.javaDescriptorResolver.packageFragmentProvider)
|
||||
emptyModule.setDependencies(emptyModule)
|
||||
|
||||
val packageFragmentProvider = emptyModule.builtIns.builtInsModule.packageFragmentProvider
|
||||
|
||||
for (packageFqName in listOf<FqName>(BUILT_INS_PACKAGE_FQ_NAME, COLLECTIONS_PACKAGE_FQ_NAME, RANGES_PACKAGE_FQ_NAME)) {
|
||||
val loaded = packageFragmentProvider.getPackageFragments(packageFqName).single()
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||
loaded, configuration,
|
||||
File("compiler/testData/builtin-classes/$builtinVersionName/" + packageFqName.asString().replace('.', '-') + ".txt"))
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.builtins
|
||||
|
||||
class Java6BuiltInsWithJDKMembersTest : AbstractBuiltInsWithJDKMembersTest() {
|
||||
fun testLoadBuiltIns() {
|
||||
doTest("java6")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user