Light classes: generate ACC_STATIC for DefaultImpls classes

To provide consistency between light classes and their delegates

IdeLightClass#testExtendingInterfaceWithDefaultImpls still failing since
    we do not generate implementations delegating to DefaultImpls of superinterfaces
This commit is contained in:
Pavel V. Talanov
2017-04-05 16:19:55 +03:00
parent 5e351061e8
commit 32d3a1b4c9
4 changed files with 7 additions and 5 deletions
@@ -48,8 +48,10 @@ class InterfaceImplBodyCodegen(
get() = (v as InterfaceImplClassBuilder).isAnythingGenerated
override fun generateDeclaration() {
val codegenFlags = ACC_PUBLIC or ACC_FINAL or ACC_SUPER
val flags = if (state.classBuilderMode == ClassBuilderMode.LIGHT_CLASSES) codegenFlags or ACC_STATIC else codegenFlags
v.defineClass(
myClass.psiOrParent, state.classFileVersion, ACC_PUBLIC or ACC_FINAL or ACC_SUPER,
myClass.psiOrParent, state.classFileVersion, flags,
typeMapper.mapDefaultImpls(descriptor).internalName,
null, "java/lang/Object", ArrayUtil.EMPTY_STRING_ARRAY
)
@@ -2,11 +2,11 @@ public interface B extends p.A {
@org.jetbrains.annotations.NotNull
java.lang.String b();
final class DefaultImpls {
static final class DefaultImpls {
@org.jetbrains.annotations.NotNull
public static java.lang.String b(p.B $this) { /* compiled code */ }
@org.jetbrains.annotations.NotNull
public static java.lang.String a(p.B $this) { /* compiled code */ }
}
}
}
@@ -1,5 +1,5 @@
public interface PrivateInTrait {
final class DefaultImpls {
static final class DefaultImpls {
private static java.lang.String getNn(PrivateInTrait $this) { /* compiled code */ }
private static void setNn(PrivateInTrait $this, java.lang.String value) { /* compiled code */ }
@@ -64,5 +64,5 @@ object LightClassTestCommon {
// Actual text for light class is generated with ClsElementImpl.appendMirrorText() that can find empty DefaultImpl inner class in stubs
// for all interfaces. This inner class can't be used in Java as it generally is not seen from light classes built from Kotlin sources.
// It is also omitted during classes generation in backend so it also absent in light classes built from compiled code.
fun removeEmptyDefaultImpls(text: String) : String = text.replace("\n final class DefaultImpls {\n }\n", "")
fun removeEmptyDefaultImpls(text: String) : String = text.replace("\n static final class DefaultImpls {\n }\n", "")
}