Add Java symbol resolve in default star importing scope
Related to KT-24098
This commit is contained in:
@@ -16,6 +16,9 @@ import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade
|
||||
|
||||
class JavaSymbolProvider(val project: Project) : FirSymbolProvider {
|
||||
|
||||
override val doesLookupInFir: Boolean
|
||||
get() = false
|
||||
|
||||
// TODO: Concrete scope here
|
||||
private val allScope = GlobalSearchScope.allScope(project)
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
interface FirSymbolProvider {
|
||||
|
||||
val doesLookupInFir: Boolean
|
||||
|
||||
fun getSymbolByFqName(classId: ClassId): ConeSymbol?
|
||||
|
||||
fun getPackage(fqName: FqName): FqName? // TODO: Replace to symbol sometime
|
||||
|
||||
+4
@@ -12,6 +12,10 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
|
||||
class FirCompositeSymbolProvider(val providers: List<FirSymbolProvider>) : FirSymbolProvider {
|
||||
|
||||
override val doesLookupInFir: Boolean
|
||||
get() = providers.any(FirSymbolProvider::doesLookupInFir)
|
||||
|
||||
override fun getPackage(fqName: FqName): FqName? {
|
||||
return providers.firstNotNullResult { it.getPackage(fqName) }
|
||||
}
|
||||
|
||||
+3
@@ -25,6 +25,9 @@ import java.io.InputStream
|
||||
|
||||
class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider {
|
||||
|
||||
override val doesLookupInFir: Boolean
|
||||
get() = false
|
||||
|
||||
private class BuiltInsPackageFragment(stream: InputStream, val fqName: FqName) {
|
||||
lateinit var version: BuiltInsBinaryVersion
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class FirProviderImpl(val session: FirSession) : FirProvider {
|
||||
|
||||
override val doesLookupInFir: Boolean
|
||||
get() = true
|
||||
|
||||
override fun getFirClassifierBySymbol(symbol: ConeSymbol): FirNamedDeclaration? {
|
||||
return when (symbol) {
|
||||
is FirBasedSymbol<*> -> symbol.fir as? FirNamedDeclaration
|
||||
|
||||
+1
-4
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvedImport
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirCompositeSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirLibrarySymbolProviderImpl
|
||||
import org.jetbrains.kotlin.fir.scopes.FirPosition
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||
@@ -20,11 +19,9 @@ abstract class FirAbstractStarImportingScope(val session: FirSession, lookupInFi
|
||||
|
||||
protected abstract val starImports: List<FirResolvedImport>
|
||||
|
||||
|
||||
// TODO: Abstractify this optimization
|
||||
val provider = FirSymbolProvider.getInstance(session).let {
|
||||
when {
|
||||
it is FirCompositeSymbolProvider && !lookupInFir -> it.providers.first { it is FirLibrarySymbolProviderImpl }
|
||||
it is FirCompositeSymbolProvider && !lookupInFir -> FirCompositeSymbolProvider(it.providers.filter { !it.doesLookupInFir })
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
@Volatile
|
||||
var xx: Int = 2
|
||||
|
||||
@Synchronized
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
FILE: concurrent.kt
|
||||
@R|kotlin/jvm/Volatile|() public? final? property xx(var): R|kotlin/Int| = STUB
|
||||
public? get(): R|kotlin/Int|
|
||||
public? set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||
@R|kotlin/jvm/Synchronized|() public? final? function foo(): R|error: Not supported: FirImplicitTypeImpl| {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
val javaClass: Class<String> = String::class.java
|
||||
val kotlinClass: KClass<String> = String::class
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
FILE: reflectionClass.kt
|
||||
public? final? property javaClass(val): R|java/lang/Class<kotlin/String>| = STUB
|
||||
public? get(): R|java/lang/Class<kotlin/String>|
|
||||
public? final? property kotlinClass(val): R|kotlin/reflect/KClass<kotlin/String>| = STUB
|
||||
public? get(): R|kotlin/reflect/KClass<kotlin/String>|
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
|
||||
abstract class AbstractFirResolveTestCaseWithStdlib : AbstractFirResolveTestCase() {
|
||||
override fun createEnvironment(): KotlinCoreEnvironment {
|
||||
return createEnvironmentWithJdk(ConfigurationKind.ALL, TestJdkKind.FULL_JDK)
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,12 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInResolve() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/fir/resolve"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/fir/resolve"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true, "stdlib");
|
||||
}
|
||||
|
||||
@TestMetadata("derivedClass.kt")
|
||||
public void testDerivedClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/resolve/derivedClass.kt");
|
||||
doTest(fileName);
|
||||
runTest("compiler/testData/fir/resolve/derivedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enum.kt")
|
||||
@@ -62,8 +61,7 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
|
||||
|
||||
@TestMetadata("nestedClass.kt")
|
||||
public void testNestedClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/resolve/nestedClass.kt");
|
||||
doTest(fileName);
|
||||
runTest("compiler/testData/fir/resolve/nestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NestedOfAliasedType.kt")
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/fir/resolve/stdlib")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class FirResolveTestCaseWithStdlibGenerated extends AbstractFirResolveTestCaseWithStdlib {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInStdlib() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/fir/resolve/stdlib"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("concurrent.kt")
|
||||
public void testConcurrent() throws Exception {
|
||||
runTest("compiler/testData/fir/resolve/stdlib/concurrent.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectionClass.kt")
|
||||
public void testReflectionClass() throws Exception {
|
||||
runTest("compiler/testData/fir/resolve/stdlib/reflectionClass.kt");
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.codegen.defaultConstructor.AbstractDefaultArgumentsR
|
||||
import org.jetbrains.kotlin.codegen.flags.AbstractWriteFlagsTest
|
||||
import org.jetbrains.kotlin.codegen.ir.*
|
||||
import org.jetbrains.kotlin.fir.AbstractFirResolveTestCase
|
||||
import org.jetbrains.kotlin.fir.AbstractFirResolveTestCaseWithStdlib
|
||||
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
|
||||
import org.jetbrains.kotlin.generators.tests.generator.testGroup
|
||||
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||
@@ -206,7 +207,11 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
testClass<AbstractFirResolveTestCase> {
|
||||
model("fir/resolve", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||
model("fir/resolve", pattern = KT_WITHOUT_DOTS_IN_NAME, excludeDirs = listOf("stdlib"))
|
||||
}
|
||||
|
||||
testClass<AbstractFirResolveTestCaseWithStdlib> {
|
||||
model("fir/resolve/stdlib", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||
}
|
||||
|
||||
testClass<AbstractBytecodeListingTest> {
|
||||
|
||||
Reference in New Issue
Block a user