default -> companion: replace all mentions of default and default object
This commit is contained in:
+2
-2
@@ -20,9 +20,9 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
public abstract class DefaultObjectMapping {
|
||||
public abstract class CompanionObjectMapping {
|
||||
public fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
|
||||
if (!DescriptorUtils.isDefaultObject(classDescriptor)) return false
|
||||
if (!DescriptorUtils.isCompanionObject(classDescriptor)) return false
|
||||
|
||||
val containingDeclaration = classDescriptor.getContainingDeclaration()
|
||||
if (containingDeclaration !is ClassDescriptor) return false
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ public abstract class FileBasedKotlinClass implements KotlinJvmBinaryClass {
|
||||
@NotNull
|
||||
protected abstract byte[] getFileContents();
|
||||
|
||||
// TODO public to be accessible in default object of subclass, workaround for KT-3974
|
||||
// TODO public to be accessible in companion object of subclass, workaround for KT-3974
|
||||
@Nullable
|
||||
public static <T extends FileBasedKotlinClass> T create(
|
||||
@NotNull byte[] fileContents,
|
||||
|
||||
+5
-5
@@ -96,12 +96,12 @@ public class PlatformStaticAnnotationChecker : AnnotationChecker {
|
||||
diagnosticHolder: DiagnosticSink
|
||||
) {
|
||||
val container = descriptor.getContainingDeclaration()
|
||||
val insideObject = container != null && DescriptorUtils.isNonDefaultObject(container)
|
||||
val insideDefaultObjectInClass =
|
||||
container != null && DescriptorUtils.isDefaultObject(container) && DescriptorUtils.isClass(container.getContainingDeclaration())
|
||||
container != null && DescriptorUtils.isDefaultObject(container) && DescriptorUtils.isClass(container.getContainingDeclaration())
|
||||
val insideObject = container != null && DescriptorUtils.isNonCompanionObject(container)
|
||||
val insideCompanionObjectInClass =
|
||||
container != null && DescriptorUtils.isCompanionObject(container) && DescriptorUtils.isClass(container.getContainingDeclaration())
|
||||
container != null && DescriptorUtils.isCompanionObject(container) && DescriptorUtils.isClass(container.getContainingDeclaration())
|
||||
|
||||
if (!insideObject && !insideDefaultObjectInClass) {
|
||||
if (!insideObject && !insideCompanionObjectInClass) {
|
||||
diagnosticHolder.report(ErrorsJvm.PLATFORM_STATIC_NOT_IN_OBJECT.on(declaration));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class NeedSyntheticChecker implements CallChecker {
|
||||
|
||||
//Necessary synthetic accessors in outer classes generated via old logic: CodegenContext.getAccessor
|
||||
//Generation of accessors in nested classes (to invoke from outer,
|
||||
// e.g.: from class to default object) controlled via NEED_SYNTHETIC_ACCESSOR slice
|
||||
// e.g.: from class to companion object) controlled via NEED_SYNTHETIC_ACCESSOR slice
|
||||
private boolean needSyntheticAccessor(JetScope invokationScope, CallableDescriptor targetDescriptor) {
|
||||
return targetDescriptor instanceof CallableMemberDescriptor &&
|
||||
Visibilities.isPrivate(targetDescriptor.getVisibility()) &&
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
static {
|
||||
MAP.put(ErrorsJvm.CONFLICTING_JVM_DECLARATIONS, "Platform declaration clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
|
||||
MAP.put(ErrorsJvm.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
|
||||
MAP.put(ErrorsJvm.PLATFORM_STATIC_NOT_IN_OBJECT, "Only functions in named objects and default objects of classes can be annotated with 'platformStatic'");
|
||||
MAP.put(ErrorsJvm.PLATFORM_STATIC_NOT_IN_OBJECT, "Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'");
|
||||
MAP.put(ErrorsJvm.OVERRIDE_CANNOT_BE_STATIC, "Override member cannot be 'platformStatic' in object");
|
||||
MAP.put(ErrorsJvm.PLATFORM_STATIC_ILLEGAL_USAGE, "This declaration does not support ''platformStatic''", DescriptorRenderer.SHORT_NAMES_IN_TYPES);
|
||||
MAP.put(ErrorsJvm.NATIVE_DECLARATION_CANNOT_BE_ABSTRACT, "Native declaration can not be abstract");
|
||||
|
||||
@@ -1379,7 +1379,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitTypeProjection(@NotNull JetTypeProjection typeProjection) {
|
||||
// TODO : Support Type Arguments. Default object may be initialized at this point");
|
||||
// TODO : Support Type Arguments. Companion object may be initialized at this point");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public interface ClassDescriptorWithResolutionScopes extends ClassDescriptor {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
ClassDescriptorWithResolutionScopes getDefaultObjectDescriptor();
|
||||
ClassDescriptorWithResolutionScopes getCompanionObjectDescriptor();
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
|
||||
+10
-10
@@ -44,7 +44,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private Collection<JetType> supertypes = new ArrayList<JetType>();
|
||||
|
||||
private MutableClassDescriptor defaultObjectDescriptor;
|
||||
private MutableClassDescriptor companionObjectDescriptor;
|
||||
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
@@ -71,7 +71,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
@NotNull SourceElement source
|
||||
) {
|
||||
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
|
||||
assert kind != ClassKind.OBJECT : "Fix isDefaultObject()";
|
||||
assert kind != ClassKind.OBJECT : "Fix isCompanionObject()";
|
||||
|
||||
this.kind = kind;
|
||||
this.isInner = isInner;
|
||||
@@ -98,13 +98,13 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MutableClassDescriptor getDefaultObjectDescriptor() {
|
||||
return defaultObjectDescriptor;
|
||||
public MutableClassDescriptor getCompanionObjectDescriptor() {
|
||||
return companionObjectDescriptor;
|
||||
}
|
||||
|
||||
public void setDefaultObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
assert this.defaultObjectDescriptor == null : "classObjectDescriptor already assigned in " + this;
|
||||
this.defaultObjectDescriptor = classObjectDescriptor;
|
||||
public void setCompanionObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||
assert this.companionObjectDescriptor == null : "classObjectDescriptor already assigned in " + this;
|
||||
this.companionObjectDescriptor = classObjectDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -155,7 +155,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefaultObject() {
|
||||
public boolean isCompanionObject() {
|
||||
//TODO:
|
||||
return false;
|
||||
}
|
||||
@@ -329,8 +329,8 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
public void lockScopes() {
|
||||
getScopeForMemberLookupAsWritableScope().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
if (defaultObjectDescriptor != null) {
|
||||
defaultObjectDescriptor.lockScopes();
|
||||
if (companionObjectDescriptor != null) {
|
||||
companionObjectDescriptor.lockScopes();
|
||||
}
|
||||
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
@@ -203,10 +203,10 @@ public interface Errors {
|
||||
DiagnosticFactory1<JetTypeReference, ClassDescriptor> ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetClass, ClassDescriptor> LOCAL_ENUM_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
|
||||
// Default objects
|
||||
// Companion objects
|
||||
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_DEFAULT_OBJECTS = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
||||
DiagnosticFactory0<JetObjectDeclaration> DEFAULT_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_COMPANION_OBJECTS = DiagnosticFactory0.create(ERROR, COMPANION_OBJECT);
|
||||
DiagnosticFactory0<JetObjectDeclaration> COMPANION_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, COMPANION_OBJECT);
|
||||
|
||||
DiagnosticFactory0<JetObjectDeclaration> DEPRECATED_CLASS_OBJECT_SYNTAX = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
@@ -217,12 +217,12 @@ public interface Errors {
|
||||
// Type parameter declarations
|
||||
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_DEFAULT_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_COMPANION_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<JetTypeReference> DYNAMIC_UPPER_BOUND = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_UPPER_BOUNDS =
|
||||
DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS
|
||||
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_COMPANION_OBJECT_UPPER_BOUNDS
|
||||
= DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
|
||||
DiagnosticFactory2<JetSimpleNameExpression, JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER =
|
||||
@@ -636,7 +636,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<JetThisExpression> NO_THIS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetRootPackageExpression> PACKAGE_IS_NOT_AN_EXPRESSION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_DEFAULT_OBJECT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_COMPANION_OBJECT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetSimpleNameExpression, TypeParameterDescriptor> TYPE_PARAMETER_IS_NOT_AN_EXPRESSION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetSimpleNameExpression, TypeParameterDescriptor> TYPE_PARAMETER_ON_LHS_OF_DOT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetExpression, ClassDescriptor> NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
@@ -391,10 +391,10 @@ public object PositioningStrategies {
|
||||
}
|
||||
}
|
||||
|
||||
public val DEFAULT_OBJECT: PositioningStrategy<JetObjectDeclaration> = object : PositioningStrategy<JetObjectDeclaration>() {
|
||||
public val COMPANION_OBJECT: PositioningStrategy<JetObjectDeclaration> = object : PositioningStrategy<JetObjectDeclaration>() {
|
||||
override fun mark(element: JetObjectDeclaration): List<TextRange> {
|
||||
if (element.hasModifier(JetTokens.DEFAULT_KEYWORD)) {
|
||||
return modifierSetPosition(JetTokens.DEFAULT_KEYWORD).mark(element)
|
||||
if (element.hasModifier(JetTokens.COMPANION_KEYWORD)) {
|
||||
return modifierSetPosition(JetTokens.COMPANION_KEYWORD).mark(element)
|
||||
}
|
||||
return DEFAULT.mark(element)
|
||||
}
|
||||
|
||||
+7
-7
@@ -273,10 +273,10 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(UNREACHABLE_CODE, "Unreachable code", TO_STRING);
|
||||
|
||||
MAP.put(MANY_DEFAULT_OBJECTS, "Only one default object is allowed per class");
|
||||
MAP.put(DEFAULT_OBJECT_NOT_ALLOWED, "A default object is not allowed here");
|
||||
MAP.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class");
|
||||
MAP.put(COMPANION_OBJECT_NOT_ALLOWED, "A companion object is not allowed here");
|
||||
|
||||
MAP.put(DEPRECATED_CLASS_OBJECT_SYNTAX, "'class object' syntax for default objects was deprecated. Use 'default' modifier instead");
|
||||
MAP.put(DEPRECATED_CLASS_OBJECT_SYNTAX, "'class object' syntax for companion objects was deprecated. Use 'default' modifier instead");
|
||||
|
||||
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
|
||||
MAP.put(LOCAL_ENUM_NOT_ALLOWED, "Enum class ''{0}'' cannot be local", NAME);
|
||||
@@ -321,9 +321,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(USELESS_NULLABLE_CHECK, "Non-null type is checked for instance of nullable type");
|
||||
MAP.put(WRONG_SETTER_PARAMETER_TYPE, "Setter parameter type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(WRONG_GETTER_RETURN_TYPE, "Getter return type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(NO_DEFAULT_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a default object", NAME);
|
||||
MAP.put(NO_COMPANION_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a companion object", NAME);
|
||||
MAP.put(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION, "Type parameter ''{0}'' is not an expression", NAME);
|
||||
MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a default object, so it cannot be on the left hand side of dot", NAME);
|
||||
MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a companion object, so it cannot be on the left hand side of dot", NAME);
|
||||
MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified");
|
||||
MAP.put(NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE, "Nested {0} accessed via instance reference", RENDER_CLASS_OR_OBJECT_NAME);
|
||||
MAP.put(NESTED_CLASS_SHOULD_BE_QUALIFIED, "Nested {0} should be qualified as ''{1}''", RENDER_CLASS_OR_OBJECT_NAME, TO_STRING);
|
||||
@@ -381,12 +381,12 @@ public class DefaultErrorMessages {
|
||||
});
|
||||
|
||||
MAP.put(UPPER_BOUND_VIOLATED, "Type argument is not within its bounds: should be subtype of ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(FINAL_DEFAULT_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a default object cannot extend it", RENDER_TYPE);
|
||||
MAP.put(FINAL_COMPANION_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a companion object cannot extend it", RENDER_TYPE);
|
||||
MAP.put(FINAL_UPPER_BOUND, "''{0}'' is a final type, and thus a value of the type parameter is predetermined", RENDER_TYPE);
|
||||
MAP.put(DYNAMIC_UPPER_BOUND, "Dynamic type can not be used as an upper bound");
|
||||
MAP.put(USELESS_ELVIS, "Elvis operator (?:) always returns the left operand of non-nullable type {0}", RENDER_TYPE);
|
||||
MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME);
|
||||
MAP.put(CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS, "Default object upper bounds of {0} have empty intersection", NAME);
|
||||
MAP.put(CONFLICTING_COMPANION_OBJECT_UPPER_BOUNDS, "Companion object upper bounds of {0} have empty intersection", NAME);
|
||||
|
||||
MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES);
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public interface JetTokens {
|
||||
JetModifierKeywordToken VARARG_KEYWORD = JetModifierKeywordToken.softKeywordModifier("vararg");
|
||||
JetModifierKeywordToken REIFIED_KEYWORD = JetModifierKeywordToken.softKeywordModifier("reified");
|
||||
JetModifierKeywordToken DYNAMIC_KEYWORD = JetModifierKeywordToken.softKeywordModifier("dynamic");
|
||||
JetModifierKeywordToken DEFAULT_KEYWORD = JetModifierKeywordToken.softKeywordModifier("default");
|
||||
JetModifierKeywordToken COMPANION_KEYWORD = JetModifierKeywordToken.softKeywordModifier("companion");
|
||||
|
||||
JetKeywordToken FINALLY_KEYWORD = JetKeywordToken.softKeyword("finally");
|
||||
JetModifierKeywordToken FINAL_KEYWORD = JetModifierKeywordToken.softKeywordModifier("final");
|
||||
@@ -173,7 +173,7 @@ public interface JetTokens {
|
||||
SET_KEYWORD, ABSTRACT_KEYWORD, ENUM_KEYWORD, OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD,
|
||||
OVERRIDE_KEYWORD, PRIVATE_KEYWORD, PUBLIC_KEYWORD, INTERNAL_KEYWORD, PROTECTED_KEYWORD,
|
||||
CATCH_KEYWORD, FINALLY_KEYWORD, OUT_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD, REIFIED_KEYWORD,
|
||||
DYNAMIC_KEYWORD, DEFAULT_KEYWORD, CONSTRUCTOR_KEYWORD, INIT_KEYWORD
|
||||
DYNAMIC_KEYWORD, COMPANION_KEYWORD, CONSTRUCTOR_KEYWORD, INIT_KEYWORD
|
||||
);
|
||||
|
||||
/*
|
||||
@@ -185,7 +185,7 @@ public interface JetTokens {
|
||||
new JetModifierKeywordToken[] {
|
||||
ABSTRACT_KEYWORD, ENUM_KEYWORD, OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD, OVERRIDE_KEYWORD, PRIVATE_KEYWORD,
|
||||
PUBLIC_KEYWORD, INTERNAL_KEYWORD, PROTECTED_KEYWORD, OUT_KEYWORD, IN_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD,
|
||||
REIFIED_KEYWORD, DEFAULT_KEYWORD
|
||||
REIFIED_KEYWORD, COMPANION_KEYWORD
|
||||
};
|
||||
|
||||
TokenSet MODIFIER_KEYWORDS = TokenSet.create(MODIFIER_KEYWORDS_ARRAY);
|
||||
|
||||
@@ -785,7 +785,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
* ;
|
||||
*
|
||||
* memberDeclaration'
|
||||
* : defaultObject
|
||||
* : companionObject
|
||||
* : secondaryConstructor
|
||||
* : function
|
||||
* : property
|
||||
@@ -957,7 +957,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
/*
|
||||
* defaultObject
|
||||
* companionObject
|
||||
* : modifiers "class" object
|
||||
* ;
|
||||
*/
|
||||
@@ -2083,7 +2083,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
if (item == JetTokens.ENUM_KEYWORD) {
|
||||
enumDetected = true;
|
||||
}
|
||||
else if (item == JetTokens.DEFAULT_KEYWORD) {
|
||||
else if (item == JetTokens.COMPANION_KEYWORD) {
|
||||
defaultDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,12 +220,12 @@ public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> imp
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetObjectDeclaration> getDefaultObjects() {
|
||||
public List<JetObjectDeclaration> getCompanionObjects() {
|
||||
JetClassBody body = getBody();
|
||||
if (body == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return body.getAllDefaultObjects();
|
||||
return body.getAllCompanionObjects();
|
||||
}
|
||||
|
||||
public boolean hasPrimaryConstructor() {
|
||||
|
||||
@@ -72,10 +72,10 @@ public class JetClassBody extends JetElementImplStub<KotlinPlaceHolderStub<JetCl
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetObjectDeclaration> getAllDefaultObjects() {
|
||||
public List<JetObjectDeclaration> getAllCompanionObjects() {
|
||||
List<JetObjectDeclaration> result = Lists.newArrayList();
|
||||
for (JetObjectDeclaration declaration : getStubOrPsiChildrenAsList(JetStubElementTypes.OBJECT_DECLARATION)) {
|
||||
if (declaration.isDefault()) {
|
||||
if (declaration.isCompanion()) {
|
||||
result.add(declaration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,10 +95,10 @@ abstract class JetNamedDeclarationStub<T extends KotlinStubWithFqName> extends J
|
||||
|
||||
if (hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
||||
JetElement containingClass = PsiTreeUtil.getParentOfType(this, JetClassOrObject.class);
|
||||
if (containingClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) containingClass).isDefault()) {
|
||||
JetElement defaultObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
|
||||
if (defaultObjectClass != null) {
|
||||
containingClass = defaultObjectClass;
|
||||
if (containingClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) containingClass).isCompanion()) {
|
||||
JetElement companionObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
|
||||
if (companionObjectClass != null) {
|
||||
containingClass = companionObjectClass;
|
||||
}
|
||||
}
|
||||
if (containingClass != null) {
|
||||
|
||||
@@ -51,9 +51,9 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
}
|
||||
|
||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
||||
if (nameAsDeclaration == null && isDefault()) {
|
||||
if (nameAsDeclaration == null && isCompanion()) {
|
||||
//NOTE: a hack in PSI that simplifies writing frontend code
|
||||
return SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.toString();
|
||||
return SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT.toString();
|
||||
}
|
||||
return nameAsDeclaration == null ? null : nameAsDeclaration.getName();
|
||||
}
|
||||
@@ -94,12 +94,12 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
return (JetObjectDeclarationName) findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME);
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
public boolean isCompanion() {
|
||||
KotlinObjectStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isDefault();
|
||||
}
|
||||
return getClassKeyword() != null || hasModifier(JetTokens.DEFAULT_KEYWORD);
|
||||
return getClassKeyword() != null || hasModifier(JetTokens.COMPANION_KEYWORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,10 +37,10 @@ public class JetTypeConstraint extends JetElementImplStub<KotlinTypeConstraintSt
|
||||
return visitor.visitTypeConstraint(this, data);
|
||||
}
|
||||
|
||||
public boolean isDefaultObjectConstraint() {
|
||||
public boolean isCompanionObjectConstraint() {
|
||||
KotlinTypeConstraintStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isDefaultObjectConstraint();
|
||||
return stub.isCompanionObjectConstraint();
|
||||
}
|
||||
return findChildByType(JetTokens.CLASS_KEYWORD) != null &&
|
||||
findChildByType(JetTokens.OBJECT_KEYWORD) != null;
|
||||
|
||||
@@ -95,4 +95,4 @@ private val MODIFIERS_ORDER = listOf(PUBLIC_KEYWORD, PROTECTED_KEYWORD, PRIVATE_
|
||||
FINAL_KEYWORD, OPEN_KEYWORD, ABSTRACT_KEYWORD,
|
||||
OVERRIDE_KEYWORD,
|
||||
INNER_KEYWORD,
|
||||
ANNOTATION_KEYWORD, ENUM_KEYWORD, DEFAULT_KEYWORD)
|
||||
ANNOTATION_KEYWORD, ENUM_KEYWORD, COMPANION_KEYWORD)
|
||||
|
||||
@@ -104,7 +104,7 @@ public trait KotlinPropertyStub : KotlinStubWithFqName<JetProperty> {
|
||||
}
|
||||
|
||||
public trait KotlinTypeConstraintStub : StubElement<JetTypeConstraint> {
|
||||
public fun isDefaultObjectConstraint(): Boolean
|
||||
public fun isCompanionObjectConstraint(): Boolean
|
||||
}
|
||||
|
||||
public trait KotlinTypeParameterStub : KotlinStubWithFqName<JetTypeParameter> {
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
|
||||
FqName fqName = ResolveSessionUtils.safeFqNameForLazyResolve(psi);
|
||||
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
|
||||
return new KotlinObjectStubImpl(parentStub, StringRef.fromString(name), fqName, Utils.INSTANCE$.wrapStrings(superNames),
|
||||
psi.isTopLevel(), psi.isDefault(), psi.isLocal(), psi.isObjectLiteral());
|
||||
psi.isTopLevel(), psi.isCompanion(), psi.isLocal(), psi.isObjectLiteral());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -34,18 +34,18 @@ public class JetTypeConstraintElementType extends JetStubElementType<KotlinTypeC
|
||||
|
||||
@Override
|
||||
public KotlinTypeConstraintStub createStub(@NotNull JetTypeConstraint psi, StubElement parentStub) {
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, psi.isDefaultObjectConstraint());
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, psi.isCompanionObjectConstraint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NotNull KotlinTypeConstraintStub stub, @NotNull StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeBoolean(stub.isDefaultObjectConstraint());
|
||||
dataStream.writeBoolean(stub.isCompanionObjectConstraint());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinTypeConstraintStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
boolean isDefaultObjectConstraint = dataStream.readBoolean();
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, isDefaultObjectConstraint);
|
||||
boolean isCompanionObjectConstraint = dataStream.readBoolean();
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, isCompanionObjectConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ import com.intellij.psi.PsiElement
|
||||
|
||||
public class KotlinTypeConstraintStubImpl(
|
||||
parent: StubElement<out PsiElement>?,
|
||||
private val isDefaultObjectConstraint: Boolean
|
||||
private val isCompanionObjectConstraint: Boolean
|
||||
) : KotlinStubBaseImpl<JetTypeConstraint>(parent, JetStubElementTypes.TYPE_CONSTRAINT), KotlinTypeConstraintStub {
|
||||
|
||||
override fun isDefaultObjectConstraint() = isDefaultObjectConstraint
|
||||
override fun isCompanionObjectConstraint() = isCompanionObjectConstraint
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ public fun DeclarationDescriptor.hasIntrinsicAnnotation(): Boolean {
|
||||
}
|
||||
|
||||
public fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
|
||||
isPlatformStaticIn { DescriptorUtils.isNonDefaultObject(it) || DescriptorUtils.isClass(it) }
|
||||
isPlatformStaticIn { DescriptorUtils.isNonCompanionObject(it) || DescriptorUtils.isClass(it) }
|
||||
|
||||
public fun CallableDescriptor.isPlatformStaticInDefaultObject(): Boolean =
|
||||
isPlatformStaticIn { DescriptorUtils.isDefaultObject(it) }
|
||||
public fun CallableDescriptor.isPlatformStaticInCompanionObject(): Boolean =
|
||||
isPlatformStaticIn { DescriptorUtils.isCompanionObject(it) }
|
||||
|
||||
private fun CallableDescriptor.isPlatformStaticIn(predicate: (DeclarationDescriptor) -> Boolean): Boolean =
|
||||
when (this) {
|
||||
|
||||
@@ -96,8 +96,8 @@ public interface BindingContext {
|
||||
|
||||
WritableSlice<JetReferenceExpression, DeclarationDescriptor> REFERENCE_TARGET =
|
||||
new BasicWritableSlice<JetReferenceExpression, DeclarationDescriptor>(DO_NOTHING);
|
||||
// if 'A' really means 'A.Default' then this slice stores class descriptor for A, REFERENCE_TARGET stores descriptor Default in this case
|
||||
WritableSlice<JetReferenceExpression, ClassDescriptor> SHORT_REFERENCE_TO_DEFAULT_OBJECT =
|
||||
// if 'A' really means 'A.Companion' then this slice stores class descriptor for A, REFERENCE_TARGET stores descriptor Companion in this case
|
||||
WritableSlice<JetReferenceExpression, ClassDescriptor> SHORT_REFERENCE_TO_COMPANION_OBJECT =
|
||||
new BasicWritableSlice<JetReferenceExpression, ClassDescriptor>(DO_NOTHING);
|
||||
|
||||
@KotlinSignature("val RESOLVED_CALL: WritableSlice<Call, ResolvedCall<out CallableDescriptor>>")
|
||||
|
||||
@@ -151,7 +151,7 @@ public class DeclarationsChecker {
|
||||
|
||||
for (JetTypeConstraint constraint : jetClass.getTypeConstraints()) {
|
||||
checkBoundsForTypeInClassHeader(constraint.getBoundTypeReference());
|
||||
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isDefaultObjectConstraint());
|
||||
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isCompanionObjectConstraint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,11 +164,11 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isDefaultObjectConstraint) {
|
||||
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isCompanionObjectConstraint) {
|
||||
if (typeReference != null) {
|
||||
JetType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||
if (type != null) {
|
||||
DescriptorResolver.checkUpperBoundType(typeReference, type, isDefaultObjectConstraint, trace);
|
||||
DescriptorResolver.checkUpperBoundType(typeReference, type, isCompanionObjectConstraint, trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,7 +258,7 @@ public class DeclarationsChecker {
|
||||
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
|
||||
checkDeprecatedClassObjectSyntax(declaration);
|
||||
reportErrorIfHasIllegalModifier(declaration);
|
||||
if (declaration.isLocal() && !declaration.isDefault() && !declaration.isObjectLiteral()) {
|
||||
if (declaration.isLocal() && !declaration.isCompanion() && !declaration.isObjectLiteral()) {
|
||||
trace.report(LOCAL_OBJECT_NOT_ALLOWED.on(declaration, classDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,12 +455,12 @@ public class DescriptorResolver {
|
||||
static final class UpperBoundCheckerTask {
|
||||
JetTypeReference upperBound;
|
||||
JetType upperBoundType;
|
||||
boolean isDefaultObjectConstraint;
|
||||
boolean isCompanionObjectConstraint;
|
||||
|
||||
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean defaultObjectConstraint) {
|
||||
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean companionObjectConstraint) {
|
||||
this.upperBound = upperBound;
|
||||
this.upperBoundType = upperBoundType;
|
||||
isDefaultObjectConstraint = defaultObjectConstraint;
|
||||
isCompanionObjectConstraint = companionObjectConstraint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
for (JetTypeConstraint constraint : declaration.getTypeConstraints()) {
|
||||
reportUnsupportedDefaultObjectConstraint(trace, constraint);
|
||||
reportUnsupportedCompanionObjectConstraint(trace, constraint);
|
||||
|
||||
JetSimpleNameExpression subjectTypeParameterName = constraint.getSubjectTypeParameterName();
|
||||
if (subjectTypeParameterName == null) {
|
||||
@@ -502,14 +502,14 @@ public class DescriptorResolver {
|
||||
if (boundTypeReference != null) {
|
||||
bound = typeResolver.resolveType(scope, boundTypeReference, trace, false);
|
||||
deferredUpperBoundCheckerTasks
|
||||
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isDefaultObjectConstraint()));
|
||||
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isCompanionObjectConstraint()));
|
||||
}
|
||||
|
||||
if (typeParameterDescriptor != null) {
|
||||
trace.record(BindingContext.REFERENCE_TARGET, subjectTypeParameterName, typeParameterDescriptor);
|
||||
if (bound != null) {
|
||||
if (constraint.isDefaultObjectConstraint()) {
|
||||
// Default object bounds are not supported
|
||||
if (constraint.isCompanionObjectConstraint()) {
|
||||
// Companion object bounds are not supported
|
||||
}
|
||||
else {
|
||||
typeParameterDescriptor.addUpperBound(bound);
|
||||
@@ -528,7 +528,7 @@ public class DescriptorResolver {
|
||||
|
||||
if (!(declaration instanceof JetClass)) {
|
||||
for (UpperBoundCheckerTask checkerTask : deferredUpperBoundCheckerTasks) {
|
||||
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isDefaultObjectConstraint, trace);
|
||||
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isCompanionObjectConstraint, trace);
|
||||
}
|
||||
|
||||
checkNamesInConstraints(declaration, descriptor, scope, trace);
|
||||
@@ -546,7 +546,7 @@ public class DescriptorResolver {
|
||||
|
||||
JetType classObjectType = parameter.getClassObjectType();
|
||||
if (classObjectType != null && KotlinBuiltIns.isNothing(classObjectType)) {
|
||||
trace.report(CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
trace.report(CONFLICTING_COMPANION_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,21 +581,21 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
public static void reportUnsupportedDefaultObjectConstraint(BindingTrace trace, JetTypeConstraint constraint) {
|
||||
if (constraint.isDefaultObjectConstraint()) {
|
||||
trace.report(UNSUPPORTED.on(constraint, "Default objects constraints are not supported yet"));
|
||||
public static void reportUnsupportedCompanionObjectConstraint(BindingTrace trace, JetTypeConstraint constraint) {
|
||||
if (constraint.isCompanionObjectConstraint()) {
|
||||
trace.report(UNSUPPORTED.on(constraint, "Companion objects constraints are not supported yet"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkUpperBoundType(
|
||||
JetTypeReference upperBound,
|
||||
@NotNull JetType upperBoundType,
|
||||
boolean isDefaultObjectConstraint,
|
||||
boolean isCompanionObjectConstraint,
|
||||
BindingTrace trace
|
||||
) {
|
||||
if (!TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, upperBoundType)) {
|
||||
if (isDefaultObjectConstraint) {
|
||||
trace.report(FINAL_DEFAULT_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
if (isCompanionObjectConstraint) {
|
||||
trace.report(FINAL_COMPANION_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
}
|
||||
else {
|
||||
trace.report(FINAL_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
|
||||
@@ -192,13 +192,13 @@ public class LazyTopDownAnalyzer {
|
||||
}
|
||||
|
||||
private void checkClassOrObjectDeclarations(JetClassOrObject classOrObject, ClassDescriptor classDescriptor) {
|
||||
boolean defaultObjectAlreadyFound = false;
|
||||
boolean companionObjectAlreadyFound = false;
|
||||
for (JetDeclaration jetDeclaration : classOrObject.getDeclarations()) {
|
||||
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isDefault()) {
|
||||
if (defaultObjectAlreadyFound) {
|
||||
trace.report(MANY_DEFAULT_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
|
||||
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isCompanion()) {
|
||||
if (companionObjectAlreadyFound) {
|
||||
trace.report(MANY_COMPANION_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
|
||||
}
|
||||
defaultObjectAlreadyFound = true;
|
||||
companionObjectAlreadyFound = true;
|
||||
}
|
||||
else if (jetDeclaration instanceof JetSecondaryConstructor) {
|
||||
if (DescriptorUtils.isSingletonOrAnonymousObject(classDescriptor)) {
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.lexer.JetTokens.*;
|
||||
import static org.jetbrains.kotlin.psi.JetStubbedPsiUtil.getContainingDeclaration;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isDefaultObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||
|
||||
public class ModifiersChecker {
|
||||
@@ -235,13 +235,13 @@ public class ModifiersChecker {
|
||||
}
|
||||
|
||||
private void checkDefaultModifier(@NotNull JetDeclaration declaration) {
|
||||
if (declaration.hasModifier(DEFAULT_KEYWORD) && !isDefaultModifierAllowed(declaration)) {
|
||||
reportIllegalModifiers(declaration, Collections.singletonList(DEFAULT_KEYWORD));
|
||||
if (declaration.hasModifier(COMPANION_KEYWORD) && !isDefaultModifierAllowed(declaration)) {
|
||||
reportIllegalModifiers(declaration, Collections.singletonList(COMPANION_KEYWORD));
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: just checks if this is legal context for default modifier (Default object descriptor can be created)
|
||||
// DEFAULT_OBJECT_NOT_ALLOWED can be reported later
|
||||
// NOTE: just checks if this is legal context for companion modifier (Companion object descriptor can be created)
|
||||
// COMPANION_OBJECT_NOT_ALLOWED can be reported later
|
||||
public static boolean isDefaultModifierAllowed(@NotNull JetDeclaration declaration) {
|
||||
if (declaration instanceof JetObjectDeclaration) {
|
||||
JetDeclaration containingDeclaration = getContainingDeclaration(declaration);
|
||||
@@ -388,7 +388,7 @@ public class ModifiersChecker {
|
||||
if (isEnumEntry(descriptor)) {
|
||||
return Visibilities.PUBLIC;
|
||||
}
|
||||
if (isDefaultObject(descriptor)) {
|
||||
if (isCompanionObject(descriptor)) {
|
||||
return ((ClassDescriptor) descriptor.getContainingDeclaration()).getVisibility();
|
||||
}
|
||||
return Visibilities.INTERNAL;
|
||||
|
||||
@@ -121,9 +121,9 @@ public class OverloadResolver {
|
||||
return name;
|
||||
}
|
||||
if (jetClass instanceof JetObjectDeclaration) {
|
||||
// must be default object
|
||||
// must be companion object
|
||||
name = classDescriptor.getContainingDeclaration().getName().asString();
|
||||
return "default object " + name;
|
||||
return "companion object " + name;
|
||||
}
|
||||
// safe
|
||||
return "<unknown>";
|
||||
|
||||
@@ -92,8 +92,8 @@ public class TaskPrioritizer(private val storageManager: StorageManager) {
|
||||
val classifierDescriptor = qualifierReceiver.classifier
|
||||
doComputeTasks(classObjectReceiver, taskPrioritizerContext.filterCollectors {
|
||||
when {
|
||||
classifierDescriptor is ClassDescriptor && classifierDescriptor.getDefaultObjectDescriptor() != null -> {
|
||||
// nested classes and objects should not be accessible via short reference to default object
|
||||
classifierDescriptor is ClassDescriptor && classifierDescriptor.getCompanionObjectDescriptor() != null -> {
|
||||
// nested classes and objects should not be accessible via short reference to companion object
|
||||
it !is ConstructorDescriptor && it !is FakeCallableDescriptorForObject
|
||||
}
|
||||
classifierDescriptor != null && DescriptorUtils.isEnumEntry(classifierDescriptor) -> {
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ public class TracingStrategyImpl extends AbstractTracingStrategy {
|
||||
if (descriptor instanceof FakeCallableDescriptorForObject) {
|
||||
FakeCallableDescriptorForObject fakeCallableDescriptorForObject = (FakeCallableDescriptorForObject) descriptor;
|
||||
descriptor = fakeCallableDescriptorForObject.getReferencedDescriptor();
|
||||
if (fakeCallableDescriptorForObject.getClassDescriptor().getDefaultObjectDescriptor() != null) {
|
||||
trace.record(SHORT_REFERENCE_TO_DEFAULT_OBJECT, reference, fakeCallableDescriptorForObject.getClassDescriptor());
|
||||
if (fakeCallableDescriptorForObject.getClassDescriptor().getCompanionObjectDescriptor() != null) {
|
||||
trace.record(SHORT_REFERENCE_TO_COMPANION_OBJECT, reference, fakeCallableDescriptorForObject.getClassDescriptor());
|
||||
}
|
||||
}
|
||||
DeclarationDescriptor storedReference = trace.get(REFERENCE_TARGET, reference);
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class FakeCallableDescriptorForObject(
|
||||
|
||||
{
|
||||
assert(classDescriptor.getClassObjectType() != null) {
|
||||
"FakeCallableDescriptorForObject can be created only for objects, classes with default object or enum entries: $classDescriptor"
|
||||
"FakeCallableDescriptorForObject can be created only for objects, classes with companion object or enum entries: $classDescriptor"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface JetClassLikeInfo extends JetDeclarationContainer {
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
List<JetObjectDeclaration> getDefaultObjects();
|
||||
List<JetObjectDeclaration> getCompanionObjects();
|
||||
|
||||
// This element is used to identify resolution scope for the class
|
||||
@NotNull
|
||||
|
||||
+2
-2
@@ -58,12 +58,12 @@ public abstract class JetClassOrObjectInfo<E extends JetClassOrObject> implement
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetObjectDeclaration> getDefaultObjects() {
|
||||
public List<JetObjectDeclaration> getCompanionObjects() {
|
||||
JetClassBody body = element.getBody();
|
||||
if (body == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return body.getAllDefaultObjects();
|
||||
return body.getAllCompanionObjects();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -54,7 +54,7 @@ public class JetObjectInfo extends JetClassOrObjectInfo<JetObjectDeclaration> {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public boolean isDefaultObject() {
|
||||
return element.isDefault() && ModifiersChecker.isDefaultModifierAllowed(element);
|
||||
public boolean isCompanionObject() {
|
||||
return element.isCompanion() && ModifiersChecker.isDefaultModifierAllowed(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class JetScriptInfo(
|
||||
public val fqName: FqName = ScriptNameUtil.classNameForScript(script)
|
||||
override fun getContainingPackageFqName() = fqName.parent()
|
||||
override fun getModifierList() = null
|
||||
override fun getDefaultObjects() = listOf<JetObjectDeclaration>()
|
||||
override fun getCompanionObjects() = listOf<JetObjectDeclaration>()
|
||||
override fun getScopeAnchor() = script
|
||||
override fun getCorrespondingClassOrObject() = null
|
||||
override fun getTypeParameterList() = null
|
||||
|
||||
+46
-46
@@ -83,8 +83,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
private final Annotations annotations;
|
||||
private final Annotations danglingAnnotations;
|
||||
private final NullableLazyValue<LazyClassDescriptor> defaultObjectDescriptor;
|
||||
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraDefaultObjectDescriptors;
|
||||
private final NullableLazyValue<LazyClassDescriptor> companionObjectDescriptor;
|
||||
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraCompanionObjectDescriptors;
|
||||
|
||||
private final LazyClassMemberScope unsubstitutedMemberScope;
|
||||
private final JetScope staticScope = new StaticScopeForKotlinClass(this);
|
||||
@@ -95,7 +95,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private final NotNullLazyValue<JetScope> scopeForSecondaryConstructorHeaderResolution;
|
||||
|
||||
private final NullableLazyValue<Void> forceResolveAllContents;
|
||||
private final boolean isDefaultObject;
|
||||
private final boolean isCompanionObject;
|
||||
|
||||
public LazyClassDescriptor(
|
||||
@NotNull LazyClassContext c,
|
||||
@@ -122,7 +122,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
this.typeConstructor = new LazyClassTypeConstructor();
|
||||
|
||||
this.kind = classLikeInfo.getClassKind();
|
||||
this.isDefaultObject = classLikeInfo instanceof JetObjectInfo && ((JetObjectInfo) classLikeInfo).isDefaultObject();
|
||||
this.isCompanionObject = classLikeInfo instanceof JetObjectInfo && ((JetObjectInfo) classLikeInfo).isCompanionObject();
|
||||
|
||||
JetModifierList modifierList = classLikeInfo.getModifierList();
|
||||
if (kind.isSingleton()) {
|
||||
@@ -182,16 +182,16 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
);
|
||||
}
|
||||
|
||||
this.defaultObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
|
||||
this.companionObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
|
||||
@Override
|
||||
public LazyClassDescriptor invoke() {
|
||||
return computeDefaultObjectDescriptor(getDefaultObjectIfAllowed());
|
||||
return computeCompanionObjectDescriptor(getCompanionObjectIfAllowed());
|
||||
}
|
||||
});
|
||||
this.extraDefaultObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
this.extraCompanionObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
|
||||
return computeDefaultObjectDescriptor(defaultObject);
|
||||
public ClassDescriptor invoke(JetObjectDeclaration companionObject) {
|
||||
return computeCompanionObjectDescriptor(companionObject);
|
||||
}
|
||||
});
|
||||
this.scopeForClassHeaderResolution = storageManager.createLazyValue(new Function0<JetScope>() {
|
||||
@@ -277,8 +277,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
thisScope.setImplicitReceiver(this.getThisAsReceiverParameter());
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
|
||||
JetScope defaultObjectAdapterScope = (defaultObjectDescriptor != null) ? new DefaultObjectMixinScope(defaultObjectDescriptor) : JetScope.Empty.INSTANCE$;
|
||||
ClassDescriptor companionObjectDescriptor = getCompanionObjectDescriptor();
|
||||
JetScope companionObjectAdapterScope = (companionObjectDescriptor != null) ? new CompanionObjectMixinScope(companionObjectDescriptor) : JetScope.Empty.INSTANCE$;
|
||||
|
||||
return new ChainedScope(
|
||||
this,
|
||||
@@ -286,7 +286,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
thisScope,
|
||||
getScopeForMemberLookup(),
|
||||
getScopeForClassHeaderResolution(),
|
||||
defaultObjectAdapterScope,
|
||||
companionObjectAdapterScope,
|
||||
getStaticScope()
|
||||
);
|
||||
}
|
||||
@@ -374,47 +374,47 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
@Override
|
||||
public LazyClassDescriptor getDefaultObjectDescriptor() {
|
||||
return defaultObjectDescriptor.invoke();
|
||||
public LazyClassDescriptor getCompanionObjectDescriptor() {
|
||||
return companionObjectDescriptor.invoke();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
public List<ClassDescriptor> getDescriptorsForExtraDefaultObjects() {
|
||||
final JetObjectDeclaration allowedDefaultObject = getDefaultObjectIfAllowed();
|
||||
public List<ClassDescriptor> getDescriptorsForExtraCompanionObjects() {
|
||||
final JetObjectDeclaration allowedCompanionObject = getCompanionObjectIfAllowed();
|
||||
|
||||
return KotlinPackage.map(
|
||||
KotlinPackage.filter(
|
||||
declarationProvider.getOwnerInfo().getDefaultObjects(),
|
||||
declarationProvider.getOwnerInfo().getCompanionObjects(),
|
||||
new Function1<JetObjectDeclaration, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(JetObjectDeclaration defaultObject) {
|
||||
return defaultObject != allowedDefaultObject;
|
||||
public Boolean invoke(JetObjectDeclaration companionObject) {
|
||||
return companionObject != allowedCompanionObject;
|
||||
}
|
||||
}
|
||||
),
|
||||
new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
|
||||
return extraDefaultObjectDescriptors.invoke(defaultObject);
|
||||
public ClassDescriptor invoke(JetObjectDeclaration companionObject) {
|
||||
return extraCompanionObjectDescriptors.invoke(companionObject);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LazyClassDescriptor computeDefaultObjectDescriptor(@Nullable JetObjectDeclaration defaultObject) {
|
||||
JetClassLikeInfo defaultObjectInfo = getDefaultObjectInfo(defaultObject);
|
||||
if (!(defaultObjectInfo instanceof JetClassOrObjectInfo)) {
|
||||
private LazyClassDescriptor computeCompanionObjectDescriptor(@Nullable JetObjectDeclaration companionObject) {
|
||||
JetClassLikeInfo companionObjectInfo = getCompanionObjectInfo(companionObject);
|
||||
if (!(companionObjectInfo instanceof JetClassOrObjectInfo)) {
|
||||
return null;
|
||||
}
|
||||
Name name = ((JetClassOrObjectInfo) defaultObjectInfo).getName();
|
||||
Name name = ((JetClassOrObjectInfo) companionObjectInfo).getName();
|
||||
assert name != null;
|
||||
getScopeForMemberLookup().getClassifier(name);
|
||||
ClassDescriptor defaultObjectDescriptor = c.getTrace().get(BindingContext.CLASS, defaultObject);
|
||||
if (defaultObjectDescriptor instanceof LazyClassDescriptor) {
|
||||
assert DescriptorUtils.isDefaultObject(defaultObjectDescriptor) : "Not a default object: " + defaultObjectDescriptor;
|
||||
return (LazyClassDescriptor) defaultObjectDescriptor;
|
||||
ClassDescriptor companionObjectDescriptor = c.getTrace().get(BindingContext.CLASS, companionObject);
|
||||
if (companionObjectDescriptor instanceof LazyClassDescriptor) {
|
||||
assert DescriptorUtils.isCompanionObject(companionObjectDescriptor) : "Not a companion object: " + companionObjectDescriptor;
|
||||
return (LazyClassDescriptor) companionObjectDescriptor;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -422,25 +422,25 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetClassLikeInfo getDefaultObjectInfo(@Nullable JetObjectDeclaration defaultObject) {
|
||||
if (defaultObject != null) {
|
||||
if (!isDefaultObjectAllowed()) {
|
||||
c.getTrace().report(DEFAULT_OBJECT_NOT_ALLOWED.on(defaultObject));
|
||||
private JetClassLikeInfo getCompanionObjectInfo(@Nullable JetObjectDeclaration companionObject) {
|
||||
if (companionObject != null) {
|
||||
if (!isCompanionObjectAllowed()) {
|
||||
c.getTrace().report(COMPANION_OBJECT_NOT_ALLOWED.on(companionObject));
|
||||
}
|
||||
|
||||
return JetClassInfoUtil.createClassLikeInfo(defaultObject);
|
||||
return JetClassInfoUtil.createClassLikeInfo(companionObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetObjectDeclaration getDefaultObjectIfAllowed() {
|
||||
JetObjectDeclaration defaultObject = firstOrNull(declarationProvider.getOwnerInfo().getDefaultObjects());
|
||||
return (defaultObject != null && isDefaultObjectAllowed()) ? defaultObject : null;
|
||||
private JetObjectDeclaration getCompanionObjectIfAllowed() {
|
||||
JetObjectDeclaration companionObject = firstOrNull(declarationProvider.getOwnerInfo().getCompanionObjects());
|
||||
return (companionObject != null && isCompanionObjectAllowed()) ? companionObject : null;
|
||||
}
|
||||
|
||||
private boolean isDefaultObjectAllowed() {
|
||||
private boolean isCompanionObjectAllowed() {
|
||||
return !(getKind().isSingleton() || isInner() || DescriptorUtils.isLocal(this));
|
||||
}
|
||||
|
||||
@@ -468,8 +468,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefaultObject() {
|
||||
return isDefaultObject;
|
||||
public boolean isCompanionObject() {
|
||||
return isCompanionObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -496,13 +496,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
private void doForceResolveAllContents() {
|
||||
resolveMemberHeaders();
|
||||
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(defaultObjectDescriptor);
|
||||
ClassDescriptor companionObjectDescriptor = getCompanionObjectDescriptor();
|
||||
if (companionObjectDescriptor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(companionObjectDescriptor);
|
||||
}
|
||||
|
||||
ForceResolveUtil.forceResolveAllContents(getConstructors());
|
||||
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraDefaultObjects());
|
||||
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraCompanionObjects());
|
||||
ForceResolveUtil.forceResolveAllContents(getScopeForMemberLookup());
|
||||
ForceResolveUtil.forceResolveAllContents(getTypeConstructor());
|
||||
}
|
||||
@@ -512,9 +512,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
ForceResolveUtil.forceResolveAllContents(getAnnotations());
|
||||
ForceResolveUtil.forceResolveAllContents(getDanglingAnnotations());
|
||||
|
||||
getDefaultObjectDescriptor();
|
||||
getCompanionObjectDescriptor();
|
||||
|
||||
getDescriptorsForExtraDefaultObjects();
|
||||
getDescriptorsForExtraCompanionObjects();
|
||||
|
||||
getClassObjectType();
|
||||
getConstructors();
|
||||
|
||||
+1
-1
@@ -230,7 +230,7 @@ public open class LazyClassMemberScope(
|
||||
|
||||
private fun <T : CallableMemberDescriptor> generateDelegatingDescriptors(name: Name, extractor: MemberExtractor<T>, existingDescriptors: Collection<CallableDescriptor>): Collection<T> {
|
||||
val classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject()
|
||||
?: return setOf() // Enum default objects do not have delegated members
|
||||
?: return setOf()
|
||||
|
||||
val lazyTypeResolver = DelegationResolver.TypeResolver { reference ->
|
||||
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution(), reference, trace, false)
|
||||
|
||||
+2
-2
@@ -83,7 +83,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
if (classOrObject instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) classOrObject;
|
||||
for (JetTypeConstraint jetTypeConstraint : jetClass.getTypeConstraints()) {
|
||||
DescriptorResolver.reportUnsupportedDefaultObjectConstraint(c.getTrace(), jetTypeConstraint);
|
||||
DescriptorResolver.reportUnsupportedCompanionObjectConstraint(c.getTrace(), jetTypeConstraint);
|
||||
|
||||
JetSimpleNameExpression constrainedParameterName = jetTypeConstraint.getSubjectTypeParameterName();
|
||||
if (constrainedParameterName != null) {
|
||||
@@ -93,7 +93,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
JetTypeReference boundTypeReference = jetTypeConstraint.getBoundTypeReference();
|
||||
if (boundTypeReference != null) {
|
||||
JetType boundType = resolveBoundType(boundTypeReference);
|
||||
if (!jetTypeConstraint.isDefaultObjectConstraint()) {
|
||||
if (!jetTypeConstraint.isCompanionObjectConstraint()) {
|
||||
upperBounds.add(boundType);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.resolve.scopes
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
|
||||
/**
|
||||
* Members of the default object are accessible from the class.
|
||||
* Scope lazily delegates requests to default object scope.
|
||||
* Members of the companion object are accessible from the class.
|
||||
* Scope lazily delegates requests to companion object scope.
|
||||
*/
|
||||
public class DefaultObjectMixinScope(private val defaultObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
|
||||
public class CompanionObjectMixinScope(private val companionObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
|
||||
override val workerScope: JetScope
|
||||
get() = defaultObjectDescriptor.getDefaultType().getMemberScope()
|
||||
get() = companionObjectDescriptor.getDefaultType().getMemberScope()
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = listOf(defaultObjectDescriptor.getThisAsReceiverParameter())
|
||||
override fun getImplicitReceiversHierarchy() = listOf(companionObjectDescriptor.getThisAsReceiverParameter())
|
||||
}
|
||||
|
||||
+2
-2
@@ -91,8 +91,8 @@ public abstract class WritableScopeWithImports(override val workerScope: JetScop
|
||||
protected open fun computeImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
|
||||
val implicitReceiverHierarchy = Lists.newArrayList<ReceiverParameterDescriptor>()
|
||||
// Imported scopes come with their receivers
|
||||
// Example: class member resolution scope imports a scope of it's default object
|
||||
// members of the default object must be able to find it as an implicit receiver
|
||||
// Example: class member resolution scope imports a scope of it's companion object
|
||||
// members of the companion object must be able to find it as an implicit receiver
|
||||
for (scope in getImports()) {
|
||||
implicitReceiverHierarchy.addAll(scope.getImplicitReceiversHierarchy())
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ private fun QualifierReceiver.resolveAsStandaloneExpression(context: ExpressionT
|
||||
context.trace.report(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION.on(referenceExpression, classifier))
|
||||
}
|
||||
else if (classifier is ClassDescriptor && classifier.getClassObjectType() == null) {
|
||||
context.trace.report(NO_DEFAULT_OBJECT.on(referenceExpression, classifier))
|
||||
context.trace.report(NO_COMPANION_OBJECT.on(referenceExpression, classifier))
|
||||
}
|
||||
else if (packageView != null) {
|
||||
context.trace.report(EXPRESSION_EXPECTED_PACKAGE_FOUND.on(referenceExpression))
|
||||
@@ -174,8 +174,8 @@ private fun QualifierReceiver.resolveReferenceTarget(
|
||||
(selector.getDispatchReceiverParameter() != null || selector.getExtensionReceiverParameter() != null)
|
||||
|
||||
if (classifier is ClassDescriptor && classifier.classObjectDescriptor != null && isCallableWithReceiver) {
|
||||
if (classifier.getDefaultObjectDescriptor() != null) {
|
||||
context.trace.record(SHORT_REFERENCE_TO_DEFAULT_OBJECT, referenceExpression, classifier)
|
||||
if (classifier.getCompanionObjectDescriptor() != null) {
|
||||
context.trace.record(SHORT_REFERENCE_TO_COMPANION_OBJECT, referenceExpression, classifier)
|
||||
}
|
||||
return classifier.getClassObjectReferenceTarget()
|
||||
}
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ class DeclarationScopeProviderForLocalClassifierAnalyzer(
|
||||
}
|
||||
|
||||
override fun getOuterDataFlowInfoForDeclaration(elementOfDeclaration: PsiElement): DataFlowInfo {
|
||||
// nested (non-inner) classes and default objects are forbidden in local classes, so it's enough to be simply inside the class
|
||||
// nested (non-inner) classes and companion objects are forbidden in local classes, so it's enough to be simply inside the class
|
||||
if (localClassDescriptorManager.insideMyClass(elementOfDeclaration)) {
|
||||
return localClassDescriptorManager.expressionTypingContext.dataFlowInfo
|
||||
}
|
||||
|
||||
@@ -150,12 +150,12 @@ public class LightClassUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiField getLightFieldForDefaultObject(@NotNull JetClassOrObject defaultObject) {
|
||||
PsiClass outerPsiClass = getWrappingClass(defaultObject);
|
||||
public static PsiField getLightFieldForCompanionObject(@NotNull JetClassOrObject companionObject) {
|
||||
PsiClass outerPsiClass = getWrappingClass(companionObject);
|
||||
if (outerPsiClass != null) {
|
||||
for (PsiField fieldOfParent : outerPsiClass.getFields()) {
|
||||
if (((KotlinLightElement<?, ?>) fieldOfParent).getOrigin() == defaultObject &&
|
||||
fieldOfParent.getName().equals(defaultObject.getName())) { // TODO this check is relevant while light class has deprecated OBJECT$ field
|
||||
if (((KotlinLightElement<?, ?>) fieldOfParent).getOrigin() == companionObject &&
|
||||
fieldOfParent.getName().equals(companionObject.getName())) { // TODO this check is relevant while light class has deprecated OBJECT$ field
|
||||
return fieldOfParent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package test
|
||||
|
||||
class WithClassObject {
|
||||
default object {
|
||||
companion object {
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package test
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
class PlatformStaticClass {
|
||||
default object {
|
||||
companion object {
|
||||
platformStatic
|
||||
fun inClassObject<T>() {}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,21 @@ public final class ClassObjectField {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public static final java.lang.String x = "";
|
||||
private static final java.lang.String y = "";
|
||||
public static final ClassObjectField.Default Default;
|
||||
public static final ClassObjectField.Companion Companion;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@java.lang.Deprecated
|
||||
public static final ClassObjectField.Default OBJECT$;
|
||||
public static final ClassObjectField.Companion OBJECT$;
|
||||
|
||||
public ClassObjectField() { /* compiled code */ }
|
||||
|
||||
public static final class Default {
|
||||
public static final class Companion {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public final java.lang.String getX() { /* compiled code */ }
|
||||
|
||||
private final java.lang.String getY() { /* compiled code */ }
|
||||
|
||||
private Default() { /* compiled code */ }
|
||||
private Companion() { /* compiled code */ }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// ClassObjectField
|
||||
|
||||
class ClassObjectField {
|
||||
default object {
|
||||
companion object {
|
||||
val x: String? = ""
|
||||
private val y: String? = ""
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
public interface TraitClassObjectField {
|
||||
TraitClassObjectField.Default Default;
|
||||
TraitClassObjectField.Companion Companion;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@java.lang.Deprecated
|
||||
TraitClassObjectField.Default OBJECT$;
|
||||
TraitClassObjectField.Companion OBJECT$;
|
||||
@org.jetbrains.annotations.Nullable
|
||||
java.lang.String x = "";
|
||||
|
||||
static final class Default {
|
||||
static final class Companion {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
private final java.lang.String x = "";
|
||||
private final java.lang.String y = "";
|
||||
@@ -18,6 +18,6 @@ public interface TraitClassObjectField {
|
||||
|
||||
private final java.lang.String getY() { /* compiled code */ }
|
||||
|
||||
private Default() { /* compiled code */ }
|
||||
private Companion() { /* compiled code */ }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// TraitClassObjectField
|
||||
|
||||
trait TraitClassObjectField {
|
||||
default object {
|
||||
companion object {
|
||||
val x: String? = ""
|
||||
private val y: String? = ""
|
||||
}
|
||||
|
||||
@@ -109,8 +109,8 @@ public final class Byte : kotlin.Number, kotlin.Comparable<kotlin.Byte> {
|
||||
public open override /*1*/ fun toLong(): kotlin.Long
|
||||
public open override /*1*/ fun toShort(): kotlin.Short
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,8 +171,8 @@ public final class ByteRange : kotlin.Range<kotlin.Byte>, kotlin.Progression<kot
|
||||
public open override /*1*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ fun iterator(): kotlin.ByteIterator
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public final val EMPTY: kotlin.ByteRange
|
||||
public final fun <get-EMPTY>(): kotlin.ByteRange
|
||||
}
|
||||
@@ -231,8 +231,8 @@ public final class Char : kotlin.Comparable<kotlin.Char> {
|
||||
public open fun toLong(): kotlin.Long
|
||||
public open fun toShort(): kotlin.Short
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,8 +293,8 @@ public final class CharRange : kotlin.Range<kotlin.Char>, kotlin.Progression<kot
|
||||
public open override /*1*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ fun iterator(): kotlin.CharIterator
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public final val EMPTY: kotlin.CharRange
|
||||
public final fun <get-EMPTY>(): kotlin.CharRange
|
||||
}
|
||||
@@ -385,8 +385,8 @@ public final class Double : kotlin.Number, kotlin.Comparable<kotlin.Double> {
|
||||
public open override /*1*/ fun toLong(): kotlin.Long
|
||||
public open override /*1*/ fun toShort(): kotlin.Short
|
||||
|
||||
public default object Default : kotlin.FloatingPointConstants<kotlin.Double> {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion : kotlin.FloatingPointConstants<kotlin.Double> {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val NEGATIVE_INFINITY: kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-NEGATIVE_INFINITY>(): kotlin.Double
|
||||
public abstract override /*1*/ /*fake_override*/ val NaN: kotlin.Double
|
||||
@@ -450,8 +450,8 @@ public final class DoubleRange : kotlin.Range<kotlin.Double>, kotlin.Progression
|
||||
public open override /*1*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ fun iterator(): kotlin.DoubleIterator
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public final val EMPTY: kotlin.DoubleRange
|
||||
public final fun <get-EMPTY>(): kotlin.DoubleRange
|
||||
}
|
||||
@@ -463,8 +463,8 @@ public abstract class Enum</*0*/ E : kotlin.Enum<E>> : kotlin.Comparable<E> {
|
||||
public final fun name(): kotlin.String
|
||||
public final fun ordinal(): kotlin.Int
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,8 +623,8 @@ public final class Float : kotlin.Number, kotlin.Comparable<kotlin.Float> {
|
||||
public open override /*1*/ fun toLong(): kotlin.Long
|
||||
public open override /*1*/ fun toShort(): kotlin.Short
|
||||
|
||||
public default object Default : kotlin.FloatingPointConstants<kotlin.Float> {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion : kotlin.FloatingPointConstants<kotlin.Float> {
|
||||
/*primary*/ private constructor Companion()
|
||||
public abstract override /*1*/ /*fake_override*/ val NEGATIVE_INFINITY: kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-NEGATIVE_INFINITY>(): kotlin.Float
|
||||
public abstract override /*1*/ /*fake_override*/ val NaN: kotlin.Float
|
||||
@@ -688,8 +688,8 @@ public final class FloatRange : kotlin.Range<kotlin.Float>, kotlin.Progression<k
|
||||
public open override /*1*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ fun iterator(): kotlin.FloatIterator
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public final val EMPTY: kotlin.FloatRange
|
||||
public final fun <get-EMPTY>(): kotlin.FloatRange
|
||||
}
|
||||
@@ -916,8 +916,8 @@ public final class Int : kotlin.Number, kotlin.Comparable<kotlin.Int> {
|
||||
public final fun ushr(/*0*/ bits: kotlin.Int): kotlin.Int
|
||||
public final fun xor(/*0*/ other: kotlin.Int): kotlin.Int
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -978,8 +978,8 @@ public final class IntRange : kotlin.Range<kotlin.Int>, kotlin.Progression<kotli
|
||||
public open override /*1*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ fun iterator(): kotlin.IntIterator
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public final val EMPTY: kotlin.IntRange
|
||||
public final fun <get-EMPTY>(): kotlin.IntRange
|
||||
}
|
||||
@@ -1087,8 +1087,8 @@ public final class Long : kotlin.Number, kotlin.Comparable<kotlin.Long> {
|
||||
public final fun ushr(/*0*/ bits: kotlin.Int): kotlin.Long
|
||||
public final fun xor(/*0*/ other: kotlin.Long): kotlin.Long
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1149,8 +1149,8 @@ public final class LongRange : kotlin.Range<kotlin.Long>, kotlin.Progression<kot
|
||||
public open override /*1*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ fun iterator(): kotlin.LongIterator
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public final val EMPTY: kotlin.LongRange
|
||||
public final fun <get-EMPTY>(): kotlin.LongRange
|
||||
}
|
||||
@@ -1383,8 +1383,8 @@ public final class Short : kotlin.Number, kotlin.Comparable<kotlin.Short> {
|
||||
public open override /*1*/ fun toLong(): kotlin.Long
|
||||
public open override /*1*/ fun toShort(): kotlin.Short
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1445,8 +1445,8 @@ public final class ShortRange : kotlin.Range<kotlin.Short>, kotlin.Progression<k
|
||||
public open override /*1*/ fun isEmpty(): kotlin.Boolean
|
||||
public open override /*1*/ fun iterator(): kotlin.ShortIterator
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
public final val EMPTY: kotlin.ShortRange
|
||||
public final fun <get-EMPTY>(): kotlin.ShortRange
|
||||
}
|
||||
@@ -1461,8 +1461,8 @@ public final class String : kotlin.Comparable<kotlin.String>, kotlin.CharSequenc
|
||||
public final fun plus(/*0*/ other: kotlin.Any?): kotlin.String
|
||||
public open override /*1*/ fun subSequence(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int): kotlin.CharSequence
|
||||
|
||||
public default object Default {
|
||||
/*primary*/ private constructor Default()
|
||||
public companion object Companion {
|
||||
/*primary*/ private constructor Companion()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
class C() {
|
||||
val a: Int = 1
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val x : Int
|
||||
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class C() {
|
||||
val a: Int = 1
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val x : Int
|
||||
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
class C() {
|
||||
val a: Int = 1
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
val x : Int
|
||||
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class A {
|
||||
default object {
|
||||
companion object {
|
||||
var xi = 0
|
||||
var xin : Int? = 0
|
||||
var xinn : Int? = null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class C() {
|
||||
default object {
|
||||
companion object {
|
||||
fun create() = C()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
fun Any.foo() = 1
|
||||
|
||||
class A {
|
||||
default object
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box() = if (A.foo() == 1) "OK" else "fail"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var global = 0;
|
||||
|
||||
class C {
|
||||
default object {
|
||||
companion object {
|
||||
{
|
||||
global = 1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class A() {
|
||||
default object {
|
||||
companion object {
|
||||
val value = 10
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// EA-38323 - Illegal field modifiers in class: classObject field in C must be static and final
|
||||
|
||||
trait C {
|
||||
default object {
|
||||
companion object {
|
||||
public val FOO: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class A {
|
||||
default object {
|
||||
companion object {
|
||||
fun values() = "O"
|
||||
fun valueOf() = "K"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class SomeClass { default object }
|
||||
class SomeClass { companion object }
|
||||
|
||||
fun box() =
|
||||
if ((SomeClass.toString() as java.lang.String).matches("SomeClass\\\$Default@[0-9a-fA-F]+"))
|
||||
if ((SomeClass.toString() as java.lang.String).matches("SomeClass\\\$Companion@[0-9a-fA-F]+"))
|
||||
"OK"
|
||||
else
|
||||
"Fail: $SomeClass"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class C() {
|
||||
default object {
|
||||
companion object {
|
||||
private fun <T> create() = C()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
open class Test {
|
||||
default object {
|
||||
companion object {
|
||||
fun testStatic(ic: InnerClass): NotInnerClass = NotInnerClass(ic.value)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ class A {
|
||||
private val p: Int
|
||||
get() = 4
|
||||
|
||||
default object B {
|
||||
companion object B {
|
||||
val p: Int
|
||||
get() = 6
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class C() {
|
||||
default object Foo
|
||||
companion object Foo
|
||||
}
|
||||
|
||||
fun C.Foo.create() = 3
|
||||
|
||||
@@ -4,7 +4,7 @@ public class StockMarketTableModel() {
|
||||
return COLUMN_TITLES?.size()!!
|
||||
}
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
private val COLUMN_TITLES : Array<Int?> = arrayOfNulls<Int>(10)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class A {
|
||||
default object {
|
||||
companion object {
|
||||
val b = 0
|
||||
val c = b
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package x
|
||||
|
||||
class Outer() {
|
||||
default object {
|
||||
companion object {
|
||||
class Inner() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box (): String {
|
||||
val inner = Outer.Default.Inner()
|
||||
val inner = Outer.Companion.Inner()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
open class Factory(p: Int)
|
||||
|
||||
class A {
|
||||
default object : Factory(1)
|
||||
companion object : Factory(1)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
|
||||
@@ -2,7 +2,7 @@ package mult_constructors_3_bug
|
||||
|
||||
public open class Identifier() {
|
||||
private var myNullable : Boolean = true
|
||||
default object {
|
||||
companion object {
|
||||
open public fun init(isNullable : Boolean) : Identifier {
|
||||
val __ = Identifier()
|
||||
__.myNullable = isNullable
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class C() {
|
||||
default object Foo {
|
||||
companion object Foo {
|
||||
fun create() = 3
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo private(val param: String = "OK") {
|
||||
default object {
|
||||
companion object {
|
||||
val s = Foo()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class A {
|
||||
default object {
|
||||
companion object {
|
||||
fun Int.foo(a: Int = 1): Int {
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fun foo(a: String = "Default", b: Int = 1, c: Long = 2): String {
|
||||
fun foo(a: String = "Companion", b: Int = 1, c: Long = 2): String {
|
||||
return "$a $b $c"
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ class Delegate<T>(var inner: T) {
|
||||
|
||||
|
||||
class Foo (val f: Int) {
|
||||
default object {
|
||||
companion object {
|
||||
val A: Foo by Delegate(Foo(11))
|
||||
var B: Foo by Delegate(Foo(11))
|
||||
}
|
||||
}
|
||||
|
||||
trait FooTrait {
|
||||
default object {
|
||||
companion object {
|
||||
val A: Foo by Delegate(Foo(11))
|
||||
var B: Foo by Delegate(Foo(11))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import java.util.IdentityHashMap
|
||||
class A {
|
||||
var foo: Int by IntHandler
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
var bar: Any? by AnyHandler
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class A {
|
||||
default object {
|
||||
companion object {
|
||||
fun invoke(i: Int) = i
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ internal final class A {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
internal default object Default {
|
||||
private constructor Default()
|
||||
internal companion object Companion {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal final fun invoke(/*0*/ i: kotlin.Int): kotlin.Int
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ trait B
|
||||
fun B.invoke(i: Int) = i
|
||||
|
||||
class A {
|
||||
default object: B {
|
||||
companion object: B {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ internal final class A {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
internal default object Default : B {
|
||||
private constructor Default()
|
||||
internal companion object Companion : B {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
class A {
|
||||
class Nested {
|
||||
default object {
|
||||
companion object {
|
||||
fun invoke(i: Int) = i
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ internal final class A {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
internal default object Default {
|
||||
private constructor Default()
|
||||
internal companion object Companion {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal final fun invoke(/*0*/ i: kotlin.Int): kotlin.Int
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import A.Nested
|
||||
|
||||
class A {
|
||||
class Nested {
|
||||
default object {
|
||||
companion object {
|
||||
fun invoke(i: Int) = i
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ internal final class A {
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
internal default object Default {
|
||||
private constructor Default()
|
||||
internal companion object Companion {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
internal final fun invoke(/*0*/ i: kotlin.Int): kotlin.Int
|
||||
|
||||
@@ -3,7 +3,7 @@ enum class Game {
|
||||
PAPER
|
||||
SCISSORS
|
||||
|
||||
default object {
|
||||
companion object {
|
||||
fun foo() = ROCK
|
||||
val bar = PAPER
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user