default -> companion: replace all mentions of default and default object

This commit is contained in:
Pavel V. Talanov
2015-03-16 14:56:06 +03:00
parent a0783757e8
commit 06916d98c6
1019 changed files with 2468 additions and 2469 deletions
@@ -195,8 +195,8 @@ public class AsmUtil {
}
}
if (AnnotationsPackage.isPlatformStaticInDefaultObject(functionDescriptor)) {
// Native method will be a member of the class, the default object method will be delegated to it
if (AnnotationsPackage.isPlatformStaticInCompanionObject(functionDescriptor)) {
// Native method will be a member of the class, the companion object method will be delegated to it
flags &= ~Opcodes.ACC_NATIVE;
}
@@ -344,7 +344,7 @@ public class AsmUtil {
}
// the following code is only for PRIVATE visibility of member
if (memberDescriptor instanceof ConstructorDescriptor) {
if (isNonDefaultObject(containingDeclaration) || isEnumEntry(containingDeclaration)) {
if (isNonCompanionObject(containingDeclaration) || isEnumEntry(containingDeclaration)) {
return NO_FLAG_PACKAGE_PRIVATE;
}
if (isEnumClass(containingDeclaration)) {
@@ -727,12 +727,12 @@ public class AsmUtil {
return false;
}
return isNonDefaultObject(propertyDescriptor.getContainingDeclaration()) || isPropertyWithBackingFieldInOuterClass(propertyDescriptor);
return isNonCompanionObject(propertyDescriptor.getContainingDeclaration()) || isPropertyWithBackingFieldInOuterClass(propertyDescriptor);
}
public static boolean isPropertyWithBackingFieldInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
return propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE &&
isDefaultObjectWithBackingFieldsInOuter(propertyDescriptor.getContainingDeclaration());
isCompanionObjectWithBackingFieldsInOuter(propertyDescriptor.getContainingDeclaration());
}
public static int getVisibilityForSpecialPropertyBackingField(@NotNull PropertyDescriptor propertyDescriptor, boolean isDelegate) {
@@ -761,14 +761,14 @@ public class AsmUtil {
DeclarationDescriptor propertyContainer = propertyDescriptor.getContainingDeclaration();
return !propertyDescriptor.isVar()
&& !isExtensionProperty
&& isDefaultObject(propertyContainer) && isTrait(propertyContainer.getContainingDeclaration())
&& isCompanionObject(propertyContainer) && isTrait(propertyContainer.getContainingDeclaration())
&& areBothAccessorDefault(propertyDescriptor)
&& getVisibilityForSpecialPropertyBackingField(propertyDescriptor, false) == ACC_PUBLIC;
}
public static boolean isDefaultObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor defaultObject) {
DeclarationDescriptor containingClass = defaultObject.getContainingDeclaration();
return isDefaultObject(defaultObject) && (isClass(containingClass) || isEnumClass(containingClass));
public static boolean isCompanionObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor companionObject) {
DeclarationDescriptor containingClass = companionObject.getContainingDeclaration();
return isCompanionObject(companionObject) && (isClass(containingClass) || isEnumClass(containingClass));
}
private static boolean areBothAccessorDefault(@NotNull PropertyDescriptor propertyDescriptor) {
@@ -1946,9 +1946,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
Type type = typeMapper.mapType((ClassDescriptor) enumClass);
return StackValue.field(type, type, descriptor.getName().asString(), true, StackValue.none());
}
ClassDescriptor defaultObjectDescriptor = classDescriptor.getDefaultObjectDescriptor();
if (defaultObjectDescriptor != null) {
return StackValue.singleton(defaultObjectDescriptor, typeMapper);
ClassDescriptor companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor();
if (companionObjectDescriptor != null) {
return StackValue.singleton(companionObjectDescriptor, typeMapper);
}
return StackValue.none();
}
@@ -2439,7 +2439,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
public StackValue generateReceiverValue(@NotNull ReceiverValue receiverValue) {
if (receiverValue instanceof ClassReceiver) {
ClassDescriptor receiverDescriptor = ((ClassReceiver) receiverValue).getDeclarationDescriptor();
if (DescriptorUtils.isDefaultObject(receiverDescriptor)) {
if (DescriptorUtils.isCompanionObject(receiverDescriptor)) {
CallableMemberDescriptor contextDescriptor = context.getContextDescriptor();
if (contextDescriptor instanceof FunctionDescriptor && receiverDescriptor == contextDescriptor.getContainingDeclaration()) {
return StackValue.LOCAL_0;
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.org.objectweb.asm.Type;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonDefaultObject;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
public class FieldInfo {
@NotNull
@@ -34,7 +34,7 @@ public class FieldInfo {
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
}
if (isNonDefaultObject(classDescriptor) || IntrinsicObjects.INSTANCE$.hasMappingToObject(classDescriptor)) {
if (isNonCompanionObject(classDescriptor) || IntrinsicObjects.INSTANCE$.hasMappingToObject(classDescriptor)) {
Type type = typeMapper.mapType(classDescriptor);
return new FieldInfo(type, type, JvmAbi.INSTANCE_FIELD, true);
}
@@ -48,12 +48,12 @@ public class FieldInfo {
@SuppressWarnings("deprecation")
@NotNull
public static FieldInfo deprecatedFieldForDefaultObject(@NotNull ClassDescriptor defaultObject, @NotNull JetTypeMapper typeMapper) {
assert DescriptorUtils.isDefaultObject(defaultObject) : "Not a default object: " + defaultObject;
public static FieldInfo deprecatedFieldForCompanionObject(@NotNull ClassDescriptor companionObject, @NotNull JetTypeMapper typeMapper) {
assert DescriptorUtils.isCompanionObject(companionObject) : "Not a companion object: " + companionObject;
return new FieldInfo(
typeMapper.mapType((ClassifierDescriptor) defaultObject.getContainingDeclaration()),
typeMapper.mapType(defaultObject),
JvmAbi.DEPRECATED_DEFAULT_OBJECT_FIELD,
typeMapper.mapType((ClassifierDescriptor) companionObject.getContainingDeclaration()),
typeMapper.mapType(companionObject),
JvmAbi.DEPRECATED_COMPANION_OBJECT_FIELD,
true
);
}
@@ -166,8 +166,8 @@ public class FunctionCodegen {
generateBridges(functionDescriptor);
boolean staticInDefaultObject = AnnotationsPackage.isPlatformStaticInDefaultObject(functionDescriptor);
if (staticInDefaultObject) {
boolean staticInCompanionObject = AnnotationsPackage.isPlatformStaticInCompanionObject(functionDescriptor);
if (staticInCompanionObject) {
ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
parentBodyCodegen.addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state));
}
@@ -190,8 +190,8 @@ public class FunctionCodegen {
if (!isNative) {
generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen);
}
else if (staticInDefaultObject) {
// native platformStatic foo() in default object should delegate to the static native function moved to the outer class
else if (staticInCompanionObject) {
// native platformStatic foo() in companion object should delegate to the static native function moved to the outer class
mv.visitCode();
FunctionDescriptor staticFunctionDescriptor = PlatformStaticGenerator.createStaticFunctionDescriptor(functionDescriptor);
JvmMethodSignature jvmMethodSignature =
@@ -92,7 +92,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private JetType superClassType;
private final Type classAsmType;
private List<PropertyAndDefaultValue> defaultObjectPropertiesToCopy;
private List<PropertyAndDefaultValue> companionObjectPropertiesToCopy;
private final List<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>> additionalTasks =
new ArrayList<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>>();
@@ -152,7 +152,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
isStatic = !jetClass.isInner();
}
else {
isStatic = myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isDefault() ;
isStatic = myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isCompanion() ;
isFinal = true;
}
@@ -352,7 +352,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateFieldForSingleton();
generateDefaultObjectBackingFieldCopies();
generateCompanionObjectBackingFieldCopies();
DelegationFieldsInfo delegationFieldsInfo = getDelegationFieldsInfo(myClass.getDelegationSpecifiers());
try {
@@ -872,7 +872,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) &&
!isDefaultObject(bridge.getContainingDeclaration());
!isCompanionObject(bridge.getContainingDeclaration());
StackValue property =
codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR,
StackValue.none());
@@ -962,9 +962,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
private void generateFieldForSingleton() {
if (isEnumEntry(descriptor) || isDefaultObject(descriptor)) return;
if (isEnumEntry(descriptor) || isCompanionObject(descriptor)) return;
if (isNonDefaultObject(descriptor)) {
if (isNonCompanionObject(descriptor)) {
StackValue.Field field = StackValue.singleton(descriptor, typeMapper);
v.newField(OtherOrigin(myClass), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
@@ -977,34 +977,34 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
return;
}
ClassDescriptor defaultObjectDescriptor = descriptor.getDefaultObjectDescriptor();
if (defaultObjectDescriptor == null) {
ClassDescriptor companionObjectDescriptor = descriptor.getCompanionObjectDescriptor();
if (companionObjectDescriptor == null) {
return;
}
JetObjectDeclaration defaultObject = firstOrNull(((JetClass) myClass).getDefaultObjects());
assert defaultObject != null : "Default object not found: " + myClass.getText();
JetObjectDeclaration companionObject = firstOrNull(((JetClass) myClass).getCompanionObjects());
assert companionObject != null : "Companion object not found: " + myClass.getText();
StackValue.Field field = StackValue.singleton(defaultObjectDescriptor, typeMapper);
v.newField(OtherOrigin(defaultObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
StackValue.Field field = StackValue.singleton(companionObjectDescriptor, typeMapper);
v.newField(OtherOrigin(companionObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
StackValue.Field deprecatedField = StackValue.deprecatedDefaultObjectAccessor(defaultObjectDescriptor, typeMapper);
FieldVisitor fv = v.newField(OtherOrigin(defaultObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL | ACC_DEPRECATED,
StackValue.Field deprecatedField = StackValue.deprecatedCompanionObjectAccessor(companionObjectDescriptor, typeMapper);
FieldVisitor fv = v.newField(OtherOrigin(companionObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL | ACC_DEPRECATED,
deprecatedField.name, deprecatedField.type.getDescriptor(), null, null);
fv.visitAnnotation(asmDescByFqNameWithoutInnerClasses(new FqName("java.lang.Deprecated")), true).visitEnd();
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
if (!isDefaultObjectWithBackingFieldsInOuter(defaultObjectDescriptor)) {
generateDefaultObjectInitializer(defaultObjectDescriptor);
if (!isCompanionObjectWithBackingFieldsInOuter(companionObjectDescriptor)) {
generateCompanionObjectInitializer(companionObjectDescriptor);
}
}
private void generateDefaultObjectBackingFieldCopies() {
if (defaultObjectPropertiesToCopy == null) return;
private void generateCompanionObjectBackingFieldCopies() {
if (companionObjectPropertiesToCopy == null) return;
for (PropertyAndDefaultValue info : defaultObjectPropertiesToCopy) {
for (PropertyAndDefaultValue info : companionObjectPropertiesToCopy) {
PropertyDescriptor property = info.descriptor;
Type type = typeMapper.mapType(property);
@@ -1020,40 +1020,40 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
// TODO: test this code
if (state.getClassBuilderMode() == ClassBuilderMode.FULL && info.defaultValue == null) {
ExpressionCodegen codegen = createOrGetClInitCodegen();
int defaultObjectIndex = putDefaultObjectInLocalVar(codegen);
StackValue.local(defaultObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
copyFieldFromDefaultObject(property);
int companionObjectIndex = putCompanionObjectInLocalVar(codegen);
StackValue.local(companionObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
copyFieldFromCompanionObject(property);
}
}
}
private int putDefaultObjectInLocalVar(ExpressionCodegen codegen) {
private int putCompanionObjectInLocalVar(ExpressionCodegen codegen) {
FrameMap frameMap = codegen.myFrameMap;
ClassDescriptor defaultObjectDescriptor = descriptor.getDefaultObjectDescriptor();
int defaultObjectIndex = frameMap.getIndex(defaultObjectDescriptor);
if (defaultObjectIndex == -1) {
defaultObjectIndex = frameMap.enter(defaultObjectDescriptor, OBJECT_TYPE);
StackValue defaultObject = StackValue.singleton(defaultObjectDescriptor, typeMapper);
StackValue.local(defaultObjectIndex, defaultObject.type).store(defaultObject, codegen.v);
ClassDescriptor companionObjectDescriptor = descriptor.getCompanionObjectDescriptor();
int companionObjectIndex = frameMap.getIndex(companionObjectDescriptor);
if (companionObjectIndex == -1) {
companionObjectIndex = frameMap.enter(companionObjectDescriptor, OBJECT_TYPE);
StackValue companionObject = StackValue.singleton(companionObjectDescriptor, typeMapper);
StackValue.local(companionObjectIndex, companionObject.type).store(companionObject, codegen.v);
}
return defaultObjectIndex;
return companionObjectIndex;
}
private void copyFieldFromDefaultObject(PropertyDescriptor propertyDescriptor) {
private void copyFieldFromCompanionObject(PropertyDescriptor propertyDescriptor) {
ExpressionCodegen codegen = createOrGetClInitCodegen();
StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, false, null, StackValue.none());
StackValue.Field field = StackValue.field(property.type, classAsmType, propertyDescriptor.getName().asString(), true, StackValue.none());
field.store(property, codegen.v);
}
private void generateDefaultObjectInitializer(@NotNull ClassDescriptor defaultObject) {
private void generateCompanionObjectInitializer(@NotNull ClassDescriptor companionObject) {
ExpressionCodegen codegen = createOrGetClInitCodegen();
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(defaultObject.getConstructors()));
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(companionObject.getConstructors()));
generateMethodCallTo(constructor, codegen.v);
codegen.v.dup();
StackValue instance = StackValue.onStack(typeMapper.mapClass(defaultObject));
StackValue.singleton(defaultObject, typeMapper).store(instance, codegen.v, true);
StackValue.deprecatedDefaultObjectAccessor(defaultObject, typeMapper).store(instance, codegen.v, true);
StackValue instance = StackValue.onStack(typeMapper.mapClass(companionObject));
StackValue.singleton(companionObject, typeMapper).store(instance, codegen.v, true);
StackValue.deprecatedCompanionObjectAccessor(companionObject, typeMapper).store(instance, codegen.v, true);
}
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
@@ -1079,7 +1079,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor);
FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v, myClass);
if (isDefaultObject(descriptor)) {
if (isCompanionObject(descriptor)) {
context.recordSyntheticAccessorIfNeeded(constructorDescriptor, bindingContext);
}
}
@@ -1112,7 +1112,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor,
getDelegationConstructorCall(bindingContext, constructorDescriptor));
if (isNonDefaultObject(descriptor)) {
if (isNonCompanionObject(descriptor)) {
StackValue.singleton(descriptor, typeMapper).store(StackValue.LOCAL_0, iv);
}
@@ -1137,9 +1137,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
curParam++;
}
if (isDefaultObjectWithBackingFieldsInOuter(descriptor)) {
if (isCompanionObjectWithBackingFieldsInOuter(descriptor)) {
final ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
parentCodegen.generateDefaultObjectInitializer(descriptor);
parentCodegen.generateCompanionObjectInitializer(descriptor);
generateInitializers(new Function0<ExpressionCodegen>() {
@Override
public ExpressionCodegen invoke() {
@@ -1740,11 +1740,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
}
public void addDefaultObjectPropertyToCopy(@NotNull PropertyDescriptor descriptor, Object defaultValue) {
if (defaultObjectPropertiesToCopy == null) {
defaultObjectPropertiesToCopy = new ArrayList<PropertyAndDefaultValue>();
public void addCompanionObjectPropertyToCopy(@NotNull PropertyDescriptor descriptor, Object defaultValue) {
if (companionObjectPropertiesToCopy == null) {
companionObjectPropertiesToCopy = new ArrayList<PropertyAndDefaultValue>();
}
defaultObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
companionObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
}
@Override
@@ -180,8 +180,8 @@ public class JvmCodegenUtil {
// Delegated and extension properties have no backing fields
if (isDelegated || property.getExtensionReceiverParameter() != null) return false;
// Default object properties cannot be accessed directly because their backing fields are stored in the containing class
if (DescriptorUtils.isDefaultObject(property.getContainingDeclaration())) return false;
// Companion object properties cannot be accessed directly because their backing fields are stored in the containing class
if (DescriptorUtils.isCompanionObject(property.getContainingDeclaration())) return false;
PropertyAccessorDescriptor accessor = forGetter ? property.getGetter() : property.getSetter();
@@ -48,7 +48,7 @@ import java.util.List;
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isInterface;
import static org.jetbrains.kotlin.codegen.JvmSerializationBindings.*;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isDefaultObject;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.PROPERTY_METADATA_TYPE;
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.OtherOrigin;
@@ -144,8 +144,8 @@ public class PropertyCodegen {
// Delegated or extension properties can only be referenced via accessors
if (declaration.hasDelegate() || declaration.getReceiverTypeReference() != null) return true;
// Default object properties always should have accessors, because their backing fields are moved/copied to the outer class
if (isDefaultObject(descriptor.getContainingDeclaration())) return true;
// Companion object properties always should have accessors, because their backing fields are moved/copied to the outer class
if (isCompanionObject(descriptor.getContainingDeclaration())) return true;
// Private class properties have accessors only in cases when those accessors are non-trivial
if (kind == OwnerKind.IMPLEMENTATION && Visibilities.isPrivate(descriptor.getVisibility())) {
@@ -265,7 +265,7 @@ public class PropertyCodegen {
if (AsmUtil.isPropertyWithBackingFieldCopyInOuterClass(propertyDescriptor)) {
ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
parentBodyCodegen.addDefaultObjectPropertyToCopy(propertyDescriptor, defaultValue);
parentBodyCodegen.addCompanionObjectPropertyToCopy(propertyDescriptor, defaultValue);
}
String name = backingFieldContext.getFieldName(propertyDescriptor, isDelegate);
@@ -513,8 +513,8 @@ public abstract class StackValue {
return field(FieldInfo.createForSingleton(classDescriptor, typeMapper));
}
public static Field deprecatedDefaultObjectAccessor(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
return field(FieldInfo.deprecatedFieldForDefaultObject(classDescriptor, typeMapper));
public static Field deprecatedCompanionObjectAccessor(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
return field(FieldInfo.deprecatedFieldForCompanionObject(classDescriptor, typeMapper));
}
public static StackValue operation(Type type, Function1<InstructionAdapter, Unit> lambda) {
@@ -51,7 +51,7 @@ public final class PsiCodegenPredictor {
*/
@Nullable
public static String getPredefinedJvmInternalName(@NotNull JetDeclaration declaration) {
// TODO: Method won't work for declarations inside default objects
// TODO: Method won't work for declarations inside companion objects
// TODO: Method won't give correct class name for traits implementations
JetDeclaration parentDeclaration = JetStubbedPsiUtil.getContainingDeclaration(declaration);
@@ -61,9 +61,9 @@ public class ClassContext extends FieldOwnerContext<ClassDescriptor> {
}
@Nullable
public CodegenContext getDefaultObjectContext() {
if (getContextDescriptor().getDefaultObjectDescriptor() != null) {
return findChildContext(getContextDescriptor().getDefaultObjectDescriptor());
public CodegenContext getCompanionObjectContext() {
if (getContextDescriptor().getCompanionObjectDescriptor() != null) {
return findChildContext(getContextDescriptor().getCompanionObjectDescriptor());
}
return null;
}
@@ -361,7 +361,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
CodegenContext descriptorContext = null;
if (!fromOutsideContext || getClassOrPackageParentContext().getContextDescriptor() != descriptor.getContainingDeclaration()) {
DeclarationDescriptor enclosed = descriptor.getContainingDeclaration();
boolean isDefaultObjectMember = DescriptorUtils.isDefaultObject(enclosed);
boolean isCompanionObjectMember = DescriptorUtils.isCompanionObject(enclosed);
//go upper
if (hasThisDescriptor() && (enclosed != getThisDescriptor() || !fromOutsideContext)) {
CodegenContext currentContext = this;
@@ -371,12 +371,12 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
break;
}
//accessors for private members in default object for call from class
if (isDefaultObjectMember && currentContext instanceof ClassContext) {
//accessors for private members in companion object for call from class
if (isCompanionObjectMember && currentContext instanceof ClassContext) {
ClassContext classContext = (ClassContext) currentContext;
CodegenContext defaultObjectContext = classContext.getDefaultObjectContext();
if (defaultObjectContext != null && defaultObjectContext.getContextDescriptor() == enclosed) {
descriptorContext = defaultObjectContext;
CodegenContext companionObjectContext = classContext.getCompanionObjectContext();
if (companionObjectContext != null && companionObjectContext.getContextDescriptor() == enclosed) {
descriptorContext = companionObjectContext;
break;
}
}
@@ -417,7 +417,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
}
protected boolean shouldAddChild(@NotNull CodegenContext child) {
return DescriptorUtils.isDefaultObject(child.contextDescriptor);
return DescriptorUtils.isCompanionObject(child.contextDescriptor);
}
@Nullable
@@ -16,17 +16,17 @@
package org.jetbrains.kotlin.codegen.intrinsics
import org.jetbrains.kotlin.backend.common.builtins.DefaultObjectMapping
import org.jetbrains.kotlin.backend.common.builtins.CompanionObjectMapping
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
public object IntrinsicObjects : DefaultObjectMapping() {
public object IntrinsicObjects : CompanionObjectMapping() {
public fun mapType(classDescriptor: ClassDescriptor): FqName? {
if (!hasMappingToObject(classDescriptor)) return null
val containingDeclaration = classDescriptor.getContainingDeclaration()
val name = Name.identifier(containingDeclaration.getName().asString() + "DefaultObject")
val name = Name.identifier(containingDeclaration.getName().asString() + "CompanionObject")
return FqName("kotlin.jvm.internal").child(name)
}
}
@@ -300,9 +300,9 @@ public class JetTypeMapper {
}
if (descriptor instanceof ClassDescriptor) {
FqName defaultObjectMappedFqName = IntrinsicObjects.INSTANCE$.mapType((ClassDescriptor) descriptor);
if (defaultObjectMappedFqName != null) {
Type asmType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(defaultObjectMappedFqName);
FqName companionObjectMappedFqName = IntrinsicObjects.INSTANCE$.mapType((ClassDescriptor) descriptor);
if (companionObjectMappedFqName != null) {
Type asmType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(companionObjectMappedFqName);
if (signatureVisitor != null) {
signatureVisitor.writeAsmType(asmType);
}