Removed 'INSTANCE' field from companions
This commit is contained in:
@@ -840,17 +840,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateFieldForSingleton() {
|
||||
if (isEnumEntry(descriptor)) return;
|
||||
if (isEnumEntry(descriptor) || isCompanionObject(descriptor)) return;
|
||||
|
||||
boolean isCompanionObject = isCompanionObject(descriptor);
|
||||
if (isNonCompanionObject(descriptor) || isCompanionObject) {
|
||||
if (isNonCompanionObject(descriptor)) {
|
||||
StackValue.Field field = StackValue.singletonViaInstance(descriptor, typeMapper);
|
||||
v.newField(JvmDeclarationOriginKt.OtherOrigin(myClass),
|
||||
ACC_PUBLIC | ACC_STATIC | ACC_FINAL | (isCompanionObject ? ACC_DEPRECATED : 0),
|
||||
ACC_PUBLIC | ACC_STATIC | ACC_FINAL,
|
||||
field.name, field.type.getDescriptor(), null, null);
|
||||
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
// Invoke the object constructor but ignore the result because INSTANCE$ will be initialized in the first line of <init>
|
||||
// Invoke the object constructor but ignore the result because INSTANCE will be initialized in the first line of <init>
|
||||
InstructionAdapter v = createOrGetClInitCodegen().v;
|
||||
markLineNumberForElement(element, v);
|
||||
v.anew(classAsmType);
|
||||
@@ -869,12 +868,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
StackValue.Field field = StackValue.singleton(companionObjectDescriptor, typeMapper);
|
||||
v.newField(JvmDeclarationOriginKt.OtherOrigin(companionObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
|
||||
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
if (!isCompanionObjectWithBackingFieldsInOuter(companionObjectDescriptor)) {
|
||||
generateCompanionObjectInitializer(companionObjectDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateCompanionObjectBackingFieldCopies() {
|
||||
@@ -926,13 +919,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
private void generateCompanionObjectInitializer(@NotNull ClassDescriptor companionObject) {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
//TODO: uncomment when DEPRECATED INSTANCE is removed
|
||||
//FunctionDescriptor constructor = (FunctionDescriptor) context.accessibleDescriptor(
|
||||
// CollectionsKt.single(companionObject.getConstructors()), /* superCallExpression = */ null
|
||||
//);
|
||||
//generateMethodCallTo(constructor, null, codegen.v);
|
||||
//StackValue instance = StackValue.onStack(typeMapper.mapClass(companionObject));
|
||||
StackValue.singleton(companionObject, typeMapper).store(StackValue.singletonViaInstance(companionObject, typeMapper), codegen.v, true);
|
||||
|
||||
FunctionDescriptor constructor = (FunctionDescriptor) context.accessibleDescriptor(
|
||||
CollectionsKt.single(companionObject.getConstructors()), /* superCallExpression = */ null
|
||||
);
|
||||
generateMethodCallTo(constructor, null, codegen.v);
|
||||
StackValue instance = StackValue.onStack(typeMapper.mapClass(companionObject));
|
||||
StackValue.singleton(companionObject, typeMapper).store(instance, codegen.v, true);
|
||||
}
|
||||
|
||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||
@@ -1002,7 +995,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor,
|
||||
getDelegationConstructorCall(bindingContext, constructorDescriptor));
|
||||
|
||||
if (isObject(descriptor)) {
|
||||
if (isNonCompanionObject(descriptor)) {
|
||||
StackValue.singletonViaInstance(descriptor, typeMapper).store(StackValue.LOCAL_0, iv);
|
||||
}
|
||||
|
||||
@@ -1027,9 +1020,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
curParam++;
|
||||
}
|
||||
|
||||
if (isCompanionObject(descriptor)) {
|
||||
ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
|
||||
parentCodegen.generateCompanionObjectInitializer(descriptor);
|
||||
}
|
||||
|
||||
if (isCompanionObjectWithBackingFieldsInOuter(descriptor)) {
|
||||
final ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
|
||||
parentCodegen.generateCompanionObjectInitializer(descriptor);
|
||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||
@Override
|
||||
public ExpressionCodegen invoke() {
|
||||
|
||||
@@ -672,7 +672,7 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
|
||||
}
|
||||
}
|
||||
|
||||
private StackValue generateMethodCallTo(
|
||||
protected StackValue generateMethodCallTo(
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@Nullable FunctionDescriptor accessorDescriptor,
|
||||
@NotNull InstructionAdapter iv
|
||||
|
||||
-5
@@ -10,11 +10,6 @@ public final class ClassObjectField {
|
||||
public ClassObjectField() { /* compiled code */ }
|
||||
|
||||
public static final class Companion {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public static final ClassObjectField.Companion INSTANCE;
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public final java.lang.String getX() { /* compiled code */ }
|
||||
|
||||
|
||||
Vendored
-4
@@ -7,10 +7,6 @@ public interface TraitClassObjectField {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public static final java.lang.String x = "";
|
||||
private static final java.lang.String y = "";
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public static final TraitClassObjectField.Companion INSTANCE;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
|
||||
@@ -7,11 +7,6 @@ public final class C {
|
||||
public C() { /* compiled code */ }
|
||||
|
||||
public static final class Companion {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public static final C.Companion INSTANCE;
|
||||
|
||||
private Companion() { /* compiled code */ }
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,7 @@ class B {
|
||||
}
|
||||
|
||||
/*
|
||||
1 DEPRECATED is for INSTANCE temporarily
|
||||
3 others are for getCONST_VAL
|
||||
3 DEPRECATED are for getCONST_VAL
|
||||
*/
|
||||
|
||||
// 4 DEPRECATED
|
||||
// 3 DEPRECATED
|
||||
@@ -7,7 +7,6 @@ syntheticMethods.kt:19
|
||||
syntheticMethods.kt:20
|
||||
syntheticMethods.kt:17
|
||||
syntheticMethods.kt:7
|
||||
syntheticMethods.kt:34
|
||||
syntheticMethods.kt:0
|
||||
syntheticMethods.kt:7
|
||||
syntheticMethods.kt:25
|
||||
|
||||
@@ -5,7 +5,6 @@ syntheticMethodsSkip.kt:6
|
||||
syntheticMethodsSkip.kt:19
|
||||
syntheticMethodsSkip.kt:20
|
||||
syntheticMethodsSkip.kt:7
|
||||
syntheticMethodsSkip.kt:34
|
||||
syntheticMethodsSkip.kt:0
|
||||
syntheticMethodsSkip.kt:7
|
||||
syntheticMethodsSkip.kt:25
|
||||
|
||||
Reference in New Issue
Block a user