Refactor: process mentions of class object
Rename usages that refer to "default object" concept now Test data file names are left as is
This commit is contained in:
@@ -195,8 +195,8 @@ public class AsmUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (AnnotationsPackage.isPlatformStaticInClassObject(functionDescriptor)) {
|
||||
// Native method will be a member of the class, the class object method will be delegated to it
|
||||
if (AnnotationsPackage.isPlatformStaticInDefaultObject(functionDescriptor)) {
|
||||
// Native method will be a member of the class, the default object method will be delegated to it
|
||||
flags &= ~Opcodes.ACC_NATIVE;
|
||||
}
|
||||
|
||||
@@ -733,7 +733,7 @@ public class AsmUtil {
|
||||
|
||||
public static boolean isPropertyWithBackingFieldInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE &&
|
||||
isClassObjectWithBackingFieldsInOuter(propertyDescriptor.getContainingDeclaration());
|
||||
isDefaultObjectWithBackingFieldsInOuter(propertyDescriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
public static int getVisibilityForSpecialPropertyBackingField(@NotNull PropertyDescriptor propertyDescriptor, boolean isDelegate) {
|
||||
@@ -762,14 +762,14 @@ public class AsmUtil {
|
||||
DeclarationDescriptor propertyContainer = propertyDescriptor.getContainingDeclaration();
|
||||
return !propertyDescriptor.isVar()
|
||||
&& !isExtensionProperty
|
||||
&& isClassObject(propertyContainer) && isTrait(propertyContainer.getContainingDeclaration())
|
||||
&& isDefaultObject(propertyContainer) && isTrait(propertyContainer.getContainingDeclaration())
|
||||
&& areBothAccessorDefault(propertyDescriptor)
|
||||
&& getVisibilityForSpecialPropertyBackingField(propertyDescriptor, false) == ACC_PUBLIC;
|
||||
}
|
||||
|
||||
public static boolean isClassObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor classObject) {
|
||||
DeclarationDescriptor containingClass = classObject.getContainingDeclaration();
|
||||
return isClassObject(classObject) && (isClass(containingClass) || isEnumClass(containingClass));
|
||||
public static boolean isDefaultObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor defaultObject) {
|
||||
DeclarationDescriptor containingClass = defaultObject.getContainingDeclaration();
|
||||
return isDefaultObject(defaultObject) && (isClass(containingClass) || isEnumClass(containingClass));
|
||||
}
|
||||
|
||||
private static boolean areBothAccessorDefault(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
|
||||
@@ -1922,9 +1922,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 classObjectDescriptor = classDescriptor.getDefaultObjectDescriptor();
|
||||
if (classObjectDescriptor != null) {
|
||||
return StackValue.singleton(classObjectDescriptor, typeMapper);
|
||||
ClassDescriptor defaultObjectDescriptor = classDescriptor.getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
return StackValue.singleton(defaultObjectDescriptor, typeMapper);
|
||||
}
|
||||
return StackValue.none();
|
||||
}
|
||||
@@ -2382,7 +2382,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.isClassObject(receiverDescriptor)) {
|
||||
if (DescriptorUtils.isDefaultObject(receiverDescriptor)) {
|
||||
CallableMemberDescriptor contextDescriptor = context.getContextDescriptor();
|
||||
if (contextDescriptor instanceof FunctionDescriptor && receiverDescriptor == contextDescriptor.getContainingDeclaration()) {
|
||||
return StackValue.LOCAL_0;
|
||||
|
||||
@@ -47,12 +47,12 @@ public class FieldInfo {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@NotNull
|
||||
public static FieldInfo deprecatedFieldForClassObject(@NotNull ClassDescriptor classObject, @NotNull JetTypeMapper typeMapper) {
|
||||
assert DescriptorUtils.isClassObject(classObject) : "Not a class object: " + classObject;
|
||||
public static FieldInfo deprecatedFieldForDefaultObject(@NotNull ClassDescriptor defaultObject, @NotNull JetTypeMapper typeMapper) {
|
||||
assert DescriptorUtils.isDefaultObject(defaultObject) : "Not a default object: " + defaultObject;
|
||||
return new FieldInfo(
|
||||
typeMapper.mapType((ClassifierDescriptor) classObject.getContainingDeclaration()),
|
||||
typeMapper.mapType(classObject),
|
||||
JvmAbi.DEPRECATED_CLASS_OBJECT_FIELD,
|
||||
typeMapper.mapType((ClassifierDescriptor) defaultObject.getContainingDeclaration()),
|
||||
typeMapper.mapType(defaultObject),
|
||||
JvmAbi.DEPRECATED_DEFAULT_OBJECT_FIELD,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -168,8 +168,8 @@ public class FunctionCodegen {
|
||||
|
||||
generateBridges(functionDescriptor);
|
||||
|
||||
boolean staticInClassObject = AnnotationsPackage.isPlatformStaticInClassObject(functionDescriptor);
|
||||
if (staticInClassObject) {
|
||||
boolean staticInDefaultObject = AnnotationsPackage.isPlatformStaticInDefaultObject(functionDescriptor);
|
||||
if (staticInDefaultObject) {
|
||||
ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
|
||||
parentBodyCodegen.addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state));
|
||||
}
|
||||
@@ -192,8 +192,8 @@ public class FunctionCodegen {
|
||||
if (!isNative) {
|
||||
generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen);
|
||||
}
|
||||
else if (staticInClassObject) {
|
||||
// native platformStatic foo() in class object should delegate to the static native function moved to the outer class
|
||||
else if (staticInDefaultObject) {
|
||||
// native platformStatic foo() in default object should delegate to the static native function moved to the outer class
|
||||
mv.visitCode();
|
||||
FunctionDescriptor staticFunctionDescriptor = PlatformStaticGenerator.createStaticFunctionDescriptor(functionDescriptor);
|
||||
JvmMethodSignature jvmMethodSignature =
|
||||
|
||||
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DeclarationResolver;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
|
||||
@@ -92,7 +91,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private JetType superClassType;
|
||||
private final Type classAsmType;
|
||||
|
||||
private List<PropertyAndDefaultValue> classObjectPropertiesToCopy;
|
||||
private List<PropertyAndDefaultValue> defaultObjectPropertiesToCopy;
|
||||
|
||||
private final List<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>> additionalTasks =
|
||||
new ArrayList<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>>();
|
||||
@@ -152,7 +151,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
isStatic = !jetClass.isInner();
|
||||
}
|
||||
else {
|
||||
isStatic = myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isClassObject() ;
|
||||
isStatic = myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isDefault() ;
|
||||
isFinal = true;
|
||||
}
|
||||
|
||||
@@ -370,7 +369,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
generateFieldForSingleton();
|
||||
|
||||
generateClassObjectBackingFieldCopies();
|
||||
generateDefaultObjectBackingFieldCopies();
|
||||
|
||||
DelegationFieldsInfo delegationFieldsInfo = getDelegationFieldsInfo(myClass.getDelegationSpecifiers());
|
||||
try {
|
||||
@@ -885,7 +884,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) &&
|
||||
!isClassObject(bridge.getContainingDeclaration());
|
||||
!isDefaultObject(bridge.getContainingDeclaration());
|
||||
StackValue property =
|
||||
codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR,
|
||||
StackValue.none());
|
||||
@@ -975,7 +974,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateFieldForSingleton() {
|
||||
if (isEnumEntry(descriptor) || isClassObject(descriptor)) return;
|
||||
if (isEnumEntry(descriptor) || isDefaultObject(descriptor)) return;
|
||||
|
||||
if (isObject(descriptor)) {
|
||||
StackValue.Field field = StackValue.singleton(descriptor, typeMapper);
|
||||
@@ -990,34 +989,34 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassDescriptor classObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
if (classObjectDescriptor == null) {
|
||||
ClassDescriptor defaultObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
JetObjectDeclaration classObject = ((JetClass) myClass).getClassObject();
|
||||
assert classObject != null : "Class object not found: " + myClass.getText();
|
||||
JetObjectDeclaration defaultObject = ((JetClass) myClass).getDefaultObject();
|
||||
assert defaultObject != null : "Default object not found: " + myClass.getText();
|
||||
|
||||
StackValue.Field field = StackValue.singleton(classObjectDescriptor, typeMapper);
|
||||
v.newField(OtherOrigin(classObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
|
||||
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 deprecatedField = StackValue.deprecatedClassObjectAccessor(classObjectDescriptor, typeMapper);
|
||||
FieldVisitor fv = v.newField(OtherOrigin(classObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL | ACC_DEPRECATED,
|
||||
StackValue.Field deprecatedField = StackValue.deprecatedDefaultObjectAccessor(defaultObjectDescriptor, typeMapper);
|
||||
FieldVisitor fv = v.newField(OtherOrigin(defaultObject), 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 (!isClassObjectWithBackingFieldsInOuter(classObjectDescriptor)) {
|
||||
generateClassObjectInitializer(classObjectDescriptor);
|
||||
if (!isDefaultObjectWithBackingFieldsInOuter(defaultObjectDescriptor)) {
|
||||
generateDefaultObjectInitializer(defaultObjectDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateClassObjectBackingFieldCopies() {
|
||||
if (classObjectPropertiesToCopy == null) return;
|
||||
private void generateDefaultObjectBackingFieldCopies() {
|
||||
if (defaultObjectPropertiesToCopy == null) return;
|
||||
|
||||
for (PropertyAndDefaultValue info : classObjectPropertiesToCopy) {
|
||||
for (PropertyAndDefaultValue info : defaultObjectPropertiesToCopy) {
|
||||
PropertyDescriptor property = info.descriptor;
|
||||
|
||||
Type type = typeMapper.mapType(property);
|
||||
@@ -1033,40 +1032,40 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
// TODO: test this code
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL && info.defaultValue == null) {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
int classObjectIndex = putClassObjectInLocalVar(codegen);
|
||||
StackValue.local(classObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
|
||||
copyFieldFromClassObject(property);
|
||||
int defaultObjectIndex = putDefaultObjectInLocalVar(codegen);
|
||||
StackValue.local(defaultObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
|
||||
copyFieldFromDefaultObject(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int putClassObjectInLocalVar(ExpressionCodegen codegen) {
|
||||
private int putDefaultObjectInLocalVar(ExpressionCodegen codegen) {
|
||||
FrameMap frameMap = codegen.myFrameMap;
|
||||
ClassDescriptor classObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
int classObjectIndex = frameMap.getIndex(classObjectDescriptor);
|
||||
if (classObjectIndex == -1) {
|
||||
classObjectIndex = frameMap.enter(classObjectDescriptor, OBJECT_TYPE);
|
||||
StackValue classObject = StackValue.singleton(classObjectDescriptor, typeMapper);
|
||||
StackValue.local(classObjectIndex, classObject.type).store(classObject, codegen.v);
|
||||
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);
|
||||
}
|
||||
return classObjectIndex;
|
||||
return defaultObjectIndex;
|
||||
}
|
||||
|
||||
private void copyFieldFromClassObject(PropertyDescriptor propertyDescriptor) {
|
||||
private void copyFieldFromDefaultObject(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 generateClassObjectInitializer(@NotNull ClassDescriptor classObject) {
|
||||
private void generateDefaultObjectInitializer(@NotNull ClassDescriptor defaultObject) {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(classObject.getConstructors()));
|
||||
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(defaultObject.getConstructors()));
|
||||
generateMethodCallTo(constructor, codegen.v);
|
||||
codegen.v.dup();
|
||||
StackValue instance = StackValue.onStack(typeMapper.mapClass(classObject));
|
||||
StackValue.singleton(classObject, typeMapper).store(instance, codegen.v, true);
|
||||
StackValue.deprecatedClassObjectAccessor(classObject, typeMapper).store(instance, codegen.v, true);
|
||||
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);
|
||||
}
|
||||
|
||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||
@@ -1098,7 +1097,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor);
|
||||
FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v, myClass);
|
||||
|
||||
if (isClassObject(descriptor)) {
|
||||
if (isDefaultObject(descriptor)) {
|
||||
context.recordSyntheticAccessorIfNeeded(constructorDescriptor, bindingContext);
|
||||
}
|
||||
}
|
||||
@@ -1151,9 +1150,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
curParam++;
|
||||
}
|
||||
|
||||
if (isClassObjectWithBackingFieldsInOuter(descriptor)) {
|
||||
if (isDefaultObjectWithBackingFieldsInOuter(descriptor)) {
|
||||
final ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
|
||||
parentCodegen.generateClassObjectInitializer(descriptor);
|
||||
parentCodegen.generateDefaultObjectInitializer(descriptor);
|
||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||
@Override
|
||||
public ExpressionCodegen invoke() {
|
||||
@@ -1638,11 +1637,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
public void addClassObjectPropertyToCopy(@NotNull PropertyDescriptor descriptor, Object defaultValue) {
|
||||
if (classObjectPropertiesToCopy == null) {
|
||||
classObjectPropertiesToCopy = new ArrayList<PropertyAndDefaultValue>();
|
||||
public void addDefaultObjectPropertyToCopy(@NotNull PropertyDescriptor descriptor, Object defaultValue) {
|
||||
if (defaultObjectPropertiesToCopy == null) {
|
||||
defaultObjectPropertiesToCopy = new ArrayList<PropertyAndDefaultValue>();
|
||||
}
|
||||
classObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
|
||||
defaultObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -179,8 +179,8 @@ public class JvmCodegenUtil {
|
||||
// Delegated and extension properties have no backing fields
|
||||
if (isDelegated || property.getExtensionReceiverParameter() != null) return false;
|
||||
|
||||
// Class object properties cannot be accessed directly because their backing fields are stored in the containing class
|
||||
if (DescriptorUtils.isClassObject(property.getContainingDeclaration())) 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;
|
||||
|
||||
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.isClassObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isDefaultObject;
|
||||
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;
|
||||
|
||||
// Class object properties always should have accessors, because their backing fields are moved/copied to the outer class
|
||||
if (isClassObject(descriptor.getContainingDeclaration())) 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;
|
||||
|
||||
// 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.addClassObjectPropertyToCopy(propertyDescriptor, defaultValue);
|
||||
parentBodyCodegen.addDefaultObjectPropertyToCopy(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 deprecatedClassObjectAccessor(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
return field(FieldInfo.deprecatedFieldForClassObject(classDescriptor, typeMapper));
|
||||
public static Field deprecatedDefaultObjectAccessor(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
return field(FieldInfo.deprecatedFieldForDefaultObject(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 class objects
|
||||
// TODO: Method won't work for declarations inside default objects
|
||||
// TODO: Method won't give correct class name for traits implementations
|
||||
|
||||
JetDeclaration parentDeclaration = JetStubbedPsiUtil.getContainingDeclaration(declaration);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ClassContext extends FieldOwnerContext<ClassDescriptor> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CodegenContext getClassObjectContext() {
|
||||
public CodegenContext getDefaultObjectContext() {
|
||||
if (getContextDescriptor().getDefaultObjectDescriptor() != null) {
|
||||
return findChildContext(getContextDescriptor().getDefaultObjectDescriptor());
|
||||
}
|
||||
|
||||
@@ -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 isClassObjectMember = DescriptorUtils.isClassObject(enclosed);
|
||||
boolean isDefaultObjectMember = DescriptorUtils.isDefaultObject(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 class object for call from class
|
||||
if (isClassObjectMember && currentContext instanceof ClassContext) {
|
||||
//accessors for private members in default object for call from class
|
||||
if (isDefaultObjectMember && currentContext instanceof ClassContext) {
|
||||
ClassContext classContext = (ClassContext) currentContext;
|
||||
CodegenContext classObject = classContext.getClassObjectContext();
|
||||
if (classObject != null && classObject.getContextDescriptor() == enclosed) {
|
||||
descriptorContext = classObject;
|
||||
CodegenContext defaultObjectContext = classContext.getDefaultObjectContext();
|
||||
if (defaultObjectContext != null && defaultObjectContext.getContextDescriptor() == enclosed) {
|
||||
descriptorContext = defaultObjectContext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -417,7 +417,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
}
|
||||
|
||||
protected boolean shouldAddChild(@NotNull CodegenContext child) {
|
||||
return DescriptorUtils.isClassObject(child.contextDescriptor);
|
||||
return DescriptorUtils.isDefaultObject(child.contextDescriptor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user