FIR Java: implement "appendErasedType" thus adding predefined signatures

Related to KT-29937
This commit is contained in:
Mikhail Glukhikh
2019-03-12 11:55:57 +03:00
parent 43d06f85e3
commit d00d078b4f
7 changed files with 50 additions and 5 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
import org.jetbrains.kotlin.fir.java.declarations.FirJavaValueParameter
import org.jetbrains.kotlin.fir.java.enhancement.*
import org.jetbrains.kotlin.fir.java.enhancement.EnhancementSignatureParts
import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType
import org.jetbrains.kotlin.fir.java.types.FirJavaTypeRef
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
@@ -26,8 +27,7 @@ import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.ir.expressions.IrConstKind
import org.jetbrains.kotlin.load.java.AnnotationTypeQualifierResolver
import org.jetbrains.kotlin.load.java.descriptors.NullDefaultValue
@@ -173,17 +173,38 @@ class JavaClassEnhancementScope(
append("(")
for (parameter in valueParameters) {
// TODO: appendErasedType(parameter.returnTypeRef)
appendErasedType(parameter.returnTypeRef)
}
append(")")
if (this@computeJvmDescriptor !is FirJavaMethod || (returnTypeRef as FirJavaTypeRef).isVoid()) {
append("V")
} else {
// TODO: appendErasedType(returnTypeRef)
appendErasedType(returnTypeRef)
}
}
private fun StringBuilder.appendErasedType(typeRef: FirTypeRef) {
when (typeRef) {
is FirResolvedTypeRef -> appendConeType(typeRef.type)
is FirJavaTypeRef -> appendConeType(typeRef.toNotNullConeKotlinType(session))
}
}
private fun StringBuilder.appendConeType(coneType: ConeKotlinType) {
append("L")
when (coneType) {
is ConeClassLikeType -> {
val classId = coneType.lookupTag.classId
append(classId.packageFqName.asString().replace(".", "/"))
append("/")
append(classId.relativeClassName)
}
is ConeTypeParameterType -> append(coneType.lookupTag.name)
}
append(";")
}
private fun FirJavaTypeRef.isVoid(): Boolean {
return type is JavaPrimitiveType && type.type == null
}
@@ -0,0 +1,2 @@
<T> public abstract interface MyIterable : R|java/lang/Iterable<T>| {
}
@@ -0,0 +1 @@
public interface MyIterable<T> extends Iterable<T>
@@ -0,0 +1,6 @@
interface UseIterable : MyIterable<String> {
fun test() {
val it = iterator()
val split = spliterator()
}
}
@@ -0,0 +1,8 @@
FILE: test.kt
public abstract interface UseIterable : R|MyIterable<kotlin/String>| {
public open function test(): R|kotlin/Unit| {
val it: R|error: Not supported: FirImplicitTypeRefImpl| = R|FakeOverride<java/lang/Iterable.iterator: R|ft<kotlin/collections/MutableIterator<ft<T, T?>>, kotlin/collections/Iterator<ft<T, T?>>?>|!>|()
val split: R|error: Not supported: FirImplicitTypeRefImpl| = R|FakeOverride<java/lang/Iterable.spliterator: R|ft<java/util/Spliterator<ft<T, T>>, java/util/Spliterator<ft<T, T>>>|>|()
}
}
@@ -53,10 +53,12 @@ abstract class AbstractFirMultiModuleResolveTest : AbstractMultiModuleTest() {
fun doTest(dirPath: String) {
setupMppProjectFromDirStructure(File(dirPath))
val useFullJdk = "full" in dirPath
val jdkKind = if (useFullJdk) TestJdkKind.FULL_JDK else TestJdkKind.MOCK_JDK
for (module in project.allModules().drop(1)) {
ConfigLibraryUtil.configureSdk(
module,
PluginTestCaseBase.addJdk(testRootDisposable) { PluginTestCaseBase.jdk(TestJdkKind.MOCK_JDK) }
PluginTestCaseBase.addJdk(testRootDisposable) { PluginTestCaseBase.jdk(jdkKind) }
)
}
doFirResolveTest(dirPath)
@@ -59,6 +59,11 @@ public class FirMultiModuleResolveTestGenerated extends AbstractFirMultiModuleRe
runTest("idea/testData/fir/multiModule/basicWithPrimitiveJava/");
}
@TestMetadata("fullWithJavaPredefinedSignature")
public void testFullWithJavaPredefinedSignature() throws Exception {
runTest("idea/testData/fir/multiModule/fullWithJavaPredefinedSignature/");
}
@TestMetadata("javaInheritsRawKotlin")
public void testJavaInheritsRawKotlin() throws Exception {
runTest("idea/testData/fir/multiModule/javaInheritsRawKotlin/");