Refactor: process mentions of class object
Rename usages that refer to "default object" concept now Test data file names are left as is
This commit is contained in:
@@ -195,8 +195,8 @@ public class AsmUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (AnnotationsPackage.isPlatformStaticInClassObject(functionDescriptor)) {
|
||||
// Native method will be a member of the class, the class object method will be delegated to it
|
||||
if (AnnotationsPackage.isPlatformStaticInDefaultObject(functionDescriptor)) {
|
||||
// Native method will be a member of the class, the default object method will be delegated to it
|
||||
flags &= ~Opcodes.ACC_NATIVE;
|
||||
}
|
||||
|
||||
@@ -733,7 +733,7 @@ public class AsmUtil {
|
||||
|
||||
public static boolean isPropertyWithBackingFieldInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE &&
|
||||
isClassObjectWithBackingFieldsInOuter(propertyDescriptor.getContainingDeclaration());
|
||||
isDefaultObjectWithBackingFieldsInOuter(propertyDescriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
public static int getVisibilityForSpecialPropertyBackingField(@NotNull PropertyDescriptor propertyDescriptor, boolean isDelegate) {
|
||||
@@ -762,14 +762,14 @@ public class AsmUtil {
|
||||
DeclarationDescriptor propertyContainer = propertyDescriptor.getContainingDeclaration();
|
||||
return !propertyDescriptor.isVar()
|
||||
&& !isExtensionProperty
|
||||
&& isClassObject(propertyContainer) && isTrait(propertyContainer.getContainingDeclaration())
|
||||
&& isDefaultObject(propertyContainer) && isTrait(propertyContainer.getContainingDeclaration())
|
||||
&& areBothAccessorDefault(propertyDescriptor)
|
||||
&& getVisibilityForSpecialPropertyBackingField(propertyDescriptor, false) == ACC_PUBLIC;
|
||||
}
|
||||
|
||||
public static boolean isClassObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor classObject) {
|
||||
DeclarationDescriptor containingClass = classObject.getContainingDeclaration();
|
||||
return isClassObject(classObject) && (isClass(containingClass) || isEnumClass(containingClass));
|
||||
public static boolean isDefaultObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor defaultObject) {
|
||||
DeclarationDescriptor containingClass = defaultObject.getContainingDeclaration();
|
||||
return isDefaultObject(defaultObject) && (isClass(containingClass) || isEnumClass(containingClass));
|
||||
}
|
||||
|
||||
private static boolean areBothAccessorDefault(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
|
||||
@@ -1922,9 +1922,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
Type type = typeMapper.mapType((ClassDescriptor) enumClass);
|
||||
return StackValue.field(type, type, descriptor.getName().asString(), true, StackValue.none());
|
||||
}
|
||||
ClassDescriptor classObjectDescriptor = classDescriptor.getDefaultObjectDescriptor();
|
||||
if (classObjectDescriptor != null) {
|
||||
return StackValue.singleton(classObjectDescriptor, typeMapper);
|
||||
ClassDescriptor defaultObjectDescriptor = classDescriptor.getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
return StackValue.singleton(defaultObjectDescriptor, typeMapper);
|
||||
}
|
||||
return StackValue.none();
|
||||
}
|
||||
@@ -2382,7 +2382,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
public StackValue generateReceiverValue(@NotNull ReceiverValue receiverValue) {
|
||||
if (receiverValue instanceof ClassReceiver) {
|
||||
ClassDescriptor receiverDescriptor = ((ClassReceiver) receiverValue).getDeclarationDescriptor();
|
||||
if (DescriptorUtils.isClassObject(receiverDescriptor)) {
|
||||
if (DescriptorUtils.isDefaultObject(receiverDescriptor)) {
|
||||
CallableMemberDescriptor contextDescriptor = context.getContextDescriptor();
|
||||
if (contextDescriptor instanceof FunctionDescriptor && receiverDescriptor == contextDescriptor.getContainingDeclaration()) {
|
||||
return StackValue.LOCAL_0;
|
||||
|
||||
@@ -47,12 +47,12 @@ public class FieldInfo {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@NotNull
|
||||
public static FieldInfo deprecatedFieldForClassObject(@NotNull ClassDescriptor classObject, @NotNull JetTypeMapper typeMapper) {
|
||||
assert DescriptorUtils.isClassObject(classObject) : "Not a class object: " + classObject;
|
||||
public static FieldInfo deprecatedFieldForDefaultObject(@NotNull ClassDescriptor defaultObject, @NotNull JetTypeMapper typeMapper) {
|
||||
assert DescriptorUtils.isDefaultObject(defaultObject) : "Not a default object: " + defaultObject;
|
||||
return new FieldInfo(
|
||||
typeMapper.mapType((ClassifierDescriptor) classObject.getContainingDeclaration()),
|
||||
typeMapper.mapType(classObject),
|
||||
JvmAbi.DEPRECATED_CLASS_OBJECT_FIELD,
|
||||
typeMapper.mapType((ClassifierDescriptor) defaultObject.getContainingDeclaration()),
|
||||
typeMapper.mapType(defaultObject),
|
||||
JvmAbi.DEPRECATED_DEFAULT_OBJECT_FIELD,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -168,8 +168,8 @@ public class FunctionCodegen {
|
||||
|
||||
generateBridges(functionDescriptor);
|
||||
|
||||
boolean staticInClassObject = AnnotationsPackage.isPlatformStaticInClassObject(functionDescriptor);
|
||||
if (staticInClassObject) {
|
||||
boolean staticInDefaultObject = AnnotationsPackage.isPlatformStaticInDefaultObject(functionDescriptor);
|
||||
if (staticInDefaultObject) {
|
||||
ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
|
||||
parentBodyCodegen.addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state));
|
||||
}
|
||||
@@ -192,8 +192,8 @@ public class FunctionCodegen {
|
||||
if (!isNative) {
|
||||
generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen);
|
||||
}
|
||||
else if (staticInClassObject) {
|
||||
// native platformStatic foo() in class object should delegate to the static native function moved to the outer class
|
||||
else if (staticInDefaultObject) {
|
||||
// native platformStatic foo() in default object should delegate to the static native function moved to the outer class
|
||||
mv.visitCode();
|
||||
FunctionDescriptor staticFunctionDescriptor = PlatformStaticGenerator.createStaticFunctionDescriptor(functionDescriptor);
|
||||
JvmMethodSignature jvmMethodSignature =
|
||||
|
||||
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DeclarationResolver;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
|
||||
@@ -92,7 +91,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private JetType superClassType;
|
||||
private final Type classAsmType;
|
||||
|
||||
private List<PropertyAndDefaultValue> classObjectPropertiesToCopy;
|
||||
private List<PropertyAndDefaultValue> defaultObjectPropertiesToCopy;
|
||||
|
||||
private final List<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>> additionalTasks =
|
||||
new ArrayList<Function2<ImplementationBodyCodegen, ClassBuilder, Unit>>();
|
||||
@@ -152,7 +151,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
isStatic = !jetClass.isInner();
|
||||
}
|
||||
else {
|
||||
isStatic = myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isClassObject() ;
|
||||
isStatic = myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isDefault() ;
|
||||
isFinal = true;
|
||||
}
|
||||
|
||||
@@ -370,7 +369,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
generateFieldForSingleton();
|
||||
|
||||
generateClassObjectBackingFieldCopies();
|
||||
generateDefaultObjectBackingFieldCopies();
|
||||
|
||||
DelegationFieldsInfo delegationFieldsInfo = getDelegationFieldsInfo(myClass.getDelegationSpecifiers());
|
||||
try {
|
||||
@@ -885,7 +884,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) &&
|
||||
!isClassObject(bridge.getContainingDeclaration());
|
||||
!isDefaultObject(bridge.getContainingDeclaration());
|
||||
StackValue property =
|
||||
codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR,
|
||||
StackValue.none());
|
||||
@@ -975,7 +974,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateFieldForSingleton() {
|
||||
if (isEnumEntry(descriptor) || isClassObject(descriptor)) return;
|
||||
if (isEnumEntry(descriptor) || isDefaultObject(descriptor)) return;
|
||||
|
||||
if (isObject(descriptor)) {
|
||||
StackValue.Field field = StackValue.singleton(descriptor, typeMapper);
|
||||
@@ -990,34 +989,34 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassDescriptor classObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
if (classObjectDescriptor == null) {
|
||||
ClassDescriptor defaultObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
JetObjectDeclaration classObject = ((JetClass) myClass).getClassObject();
|
||||
assert classObject != null : "Class object not found: " + myClass.getText();
|
||||
JetObjectDeclaration defaultObject = ((JetClass) myClass).getDefaultObject();
|
||||
assert defaultObject != null : "Default object not found: " + myClass.getText();
|
||||
|
||||
StackValue.Field field = StackValue.singleton(classObjectDescriptor, typeMapper);
|
||||
v.newField(OtherOrigin(classObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
|
||||
StackValue.Field field = StackValue.singleton(defaultObjectDescriptor, typeMapper);
|
||||
v.newField(OtherOrigin(defaultObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL, field.name, field.type.getDescriptor(), null, null);
|
||||
|
||||
StackValue.Field deprecatedField = StackValue.deprecatedClassObjectAccessor(classObjectDescriptor, typeMapper);
|
||||
FieldVisitor fv = v.newField(OtherOrigin(classObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL | ACC_DEPRECATED,
|
||||
StackValue.Field deprecatedField = StackValue.deprecatedDefaultObjectAccessor(defaultObjectDescriptor, typeMapper);
|
||||
FieldVisitor fv = v.newField(OtherOrigin(defaultObject), ACC_PUBLIC | ACC_STATIC | ACC_FINAL | ACC_DEPRECATED,
|
||||
deprecatedField.name, deprecatedField.type.getDescriptor(), null, null);
|
||||
|
||||
fv.visitAnnotation(asmDescByFqNameWithoutInnerClasses(new FqName("java.lang.Deprecated")), true).visitEnd();
|
||||
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
if (!isClassObjectWithBackingFieldsInOuter(classObjectDescriptor)) {
|
||||
generateClassObjectInitializer(classObjectDescriptor);
|
||||
if (!isDefaultObjectWithBackingFieldsInOuter(defaultObjectDescriptor)) {
|
||||
generateDefaultObjectInitializer(defaultObjectDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateClassObjectBackingFieldCopies() {
|
||||
if (classObjectPropertiesToCopy == null) return;
|
||||
private void generateDefaultObjectBackingFieldCopies() {
|
||||
if (defaultObjectPropertiesToCopy == null) return;
|
||||
|
||||
for (PropertyAndDefaultValue info : classObjectPropertiesToCopy) {
|
||||
for (PropertyAndDefaultValue info : defaultObjectPropertiesToCopy) {
|
||||
PropertyDescriptor property = info.descriptor;
|
||||
|
||||
Type type = typeMapper.mapType(property);
|
||||
@@ -1033,40 +1032,40 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
// TODO: test this code
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL && info.defaultValue == null) {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
int classObjectIndex = putClassObjectInLocalVar(codegen);
|
||||
StackValue.local(classObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
|
||||
copyFieldFromClassObject(property);
|
||||
int defaultObjectIndex = putDefaultObjectInLocalVar(codegen);
|
||||
StackValue.local(defaultObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
|
||||
copyFieldFromDefaultObject(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int putClassObjectInLocalVar(ExpressionCodegen codegen) {
|
||||
private int putDefaultObjectInLocalVar(ExpressionCodegen codegen) {
|
||||
FrameMap frameMap = codegen.myFrameMap;
|
||||
ClassDescriptor classObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
int classObjectIndex = frameMap.getIndex(classObjectDescriptor);
|
||||
if (classObjectIndex == -1) {
|
||||
classObjectIndex = frameMap.enter(classObjectDescriptor, OBJECT_TYPE);
|
||||
StackValue classObject = StackValue.singleton(classObjectDescriptor, typeMapper);
|
||||
StackValue.local(classObjectIndex, classObject.type).store(classObject, codegen.v);
|
||||
ClassDescriptor defaultObjectDescriptor = descriptor.getDefaultObjectDescriptor();
|
||||
int defaultObjectIndex = frameMap.getIndex(defaultObjectDescriptor);
|
||||
if (defaultObjectIndex == -1) {
|
||||
defaultObjectIndex = frameMap.enter(defaultObjectDescriptor, OBJECT_TYPE);
|
||||
StackValue defaultObject = StackValue.singleton(defaultObjectDescriptor, typeMapper);
|
||||
StackValue.local(defaultObjectIndex, defaultObject.type).store(defaultObject, codegen.v);
|
||||
}
|
||||
return classObjectIndex;
|
||||
return defaultObjectIndex;
|
||||
}
|
||||
|
||||
private void copyFieldFromClassObject(PropertyDescriptor propertyDescriptor) {
|
||||
private void copyFieldFromDefaultObject(PropertyDescriptor propertyDescriptor) {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, false, null, StackValue.none());
|
||||
StackValue.Field field = StackValue.field(property.type, classAsmType, propertyDescriptor.getName().asString(), true, StackValue.none());
|
||||
field.store(property, codegen.v);
|
||||
}
|
||||
|
||||
private void generateClassObjectInitializer(@NotNull ClassDescriptor classObject) {
|
||||
private void generateDefaultObjectInitializer(@NotNull ClassDescriptor defaultObject) {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(classObject.getConstructors()));
|
||||
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(defaultObject.getConstructors()));
|
||||
generateMethodCallTo(constructor, codegen.v);
|
||||
codegen.v.dup();
|
||||
StackValue instance = StackValue.onStack(typeMapper.mapClass(classObject));
|
||||
StackValue.singleton(classObject, typeMapper).store(instance, codegen.v, true);
|
||||
StackValue.deprecatedClassObjectAccessor(classObject, typeMapper).store(instance, codegen.v, true);
|
||||
StackValue instance = StackValue.onStack(typeMapper.mapClass(defaultObject));
|
||||
StackValue.singleton(defaultObject, typeMapper).store(instance, codegen.v, true);
|
||||
StackValue.deprecatedDefaultObjectAccessor(defaultObject, typeMapper).store(instance, codegen.v, true);
|
||||
}
|
||||
|
||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||
@@ -1098,7 +1097,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor);
|
||||
FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v, myClass);
|
||||
|
||||
if (isClassObject(descriptor)) {
|
||||
if (isDefaultObject(descriptor)) {
|
||||
context.recordSyntheticAccessorIfNeeded(constructorDescriptor, bindingContext);
|
||||
}
|
||||
}
|
||||
@@ -1151,9 +1150,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
curParam++;
|
||||
}
|
||||
|
||||
if (isClassObjectWithBackingFieldsInOuter(descriptor)) {
|
||||
if (isDefaultObjectWithBackingFieldsInOuter(descriptor)) {
|
||||
final ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
|
||||
parentCodegen.generateClassObjectInitializer(descriptor);
|
||||
parentCodegen.generateDefaultObjectInitializer(descriptor);
|
||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||
@Override
|
||||
public ExpressionCodegen invoke() {
|
||||
@@ -1638,11 +1637,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
public void addClassObjectPropertyToCopy(@NotNull PropertyDescriptor descriptor, Object defaultValue) {
|
||||
if (classObjectPropertiesToCopy == null) {
|
||||
classObjectPropertiesToCopy = new ArrayList<PropertyAndDefaultValue>();
|
||||
public void addDefaultObjectPropertyToCopy(@NotNull PropertyDescriptor descriptor, Object defaultValue) {
|
||||
if (defaultObjectPropertiesToCopy == null) {
|
||||
defaultObjectPropertiesToCopy = new ArrayList<PropertyAndDefaultValue>();
|
||||
}
|
||||
classObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
|
||||
defaultObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -179,8 +179,8 @@ public class JvmCodegenUtil {
|
||||
// Delegated and extension properties have no backing fields
|
||||
if (isDelegated || property.getExtensionReceiverParameter() != null) return false;
|
||||
|
||||
// Class object properties cannot be accessed directly because their backing fields are stored in the containing class
|
||||
if (DescriptorUtils.isClassObject(property.getContainingDeclaration())) return false;
|
||||
// Default object properties cannot be accessed directly because their backing fields are stored in the containing class
|
||||
if (DescriptorUtils.isDefaultObject(property.getContainingDeclaration())) return false;
|
||||
|
||||
PropertyAccessorDescriptor accessor = forGetter ? property.getGetter() : property.getSetter();
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ import java.util.List;
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isInterface;
|
||||
import static org.jetbrains.kotlin.codegen.JvmSerializationBindings.*;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isClassObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isDefaultObject;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.PROPERTY_METADATA_TYPE;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.OtherOrigin;
|
||||
@@ -144,8 +144,8 @@ public class PropertyCodegen {
|
||||
// Delegated or extension properties can only be referenced via accessors
|
||||
if (declaration.hasDelegate() || declaration.getReceiverTypeReference() != null) return true;
|
||||
|
||||
// Class object properties always should have accessors, because their backing fields are moved/copied to the outer class
|
||||
if (isClassObject(descriptor.getContainingDeclaration())) return true;
|
||||
// Default object properties always should have accessors, because their backing fields are moved/copied to the outer class
|
||||
if (isDefaultObject(descriptor.getContainingDeclaration())) return true;
|
||||
|
||||
// Private class properties have accessors only in cases when those accessors are non-trivial
|
||||
if (kind == OwnerKind.IMPLEMENTATION && Visibilities.isPrivate(descriptor.getVisibility())) {
|
||||
@@ -265,7 +265,7 @@ public class PropertyCodegen {
|
||||
|
||||
if (AsmUtil.isPropertyWithBackingFieldCopyInOuterClass(propertyDescriptor)) {
|
||||
ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
|
||||
parentBodyCodegen.addClassObjectPropertyToCopy(propertyDescriptor, defaultValue);
|
||||
parentBodyCodegen.addDefaultObjectPropertyToCopy(propertyDescriptor, defaultValue);
|
||||
}
|
||||
|
||||
String name = backingFieldContext.getFieldName(propertyDescriptor, isDelegate);
|
||||
|
||||
@@ -513,8 +513,8 @@ public abstract class StackValue {
|
||||
return field(FieldInfo.createForSingleton(classDescriptor, typeMapper));
|
||||
}
|
||||
|
||||
public static Field deprecatedClassObjectAccessor(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
return field(FieldInfo.deprecatedFieldForClassObject(classDescriptor, typeMapper));
|
||||
public static Field deprecatedDefaultObjectAccessor(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
return field(FieldInfo.deprecatedFieldForDefaultObject(classDescriptor, typeMapper));
|
||||
}
|
||||
|
||||
public static StackValue operation(Type type, Function1<InstructionAdapter, Unit> lambda) {
|
||||
|
||||
@@ -51,7 +51,7 @@ public final class PsiCodegenPredictor {
|
||||
*/
|
||||
@Nullable
|
||||
public static String getPredefinedJvmInternalName(@NotNull JetDeclaration declaration) {
|
||||
// TODO: Method won't work for declarations inside class objects
|
||||
// TODO: Method won't work for declarations inside default objects
|
||||
// TODO: Method won't give correct class name for traits implementations
|
||||
|
||||
JetDeclaration parentDeclaration = JetStubbedPsiUtil.getContainingDeclaration(declaration);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ClassContext extends FieldOwnerContext<ClassDescriptor> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CodegenContext getClassObjectContext() {
|
||||
public CodegenContext getDefaultObjectContext() {
|
||||
if (getContextDescriptor().getDefaultObjectDescriptor() != null) {
|
||||
return findChildContext(getContextDescriptor().getDefaultObjectDescriptor());
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
CodegenContext descriptorContext = null;
|
||||
if (!fromOutsideContext || getClassOrPackageParentContext().getContextDescriptor() != descriptor.getContainingDeclaration()) {
|
||||
DeclarationDescriptor enclosed = descriptor.getContainingDeclaration();
|
||||
boolean isClassObjectMember = DescriptorUtils.isClassObject(enclosed);
|
||||
boolean isDefaultObjectMember = DescriptorUtils.isDefaultObject(enclosed);
|
||||
//go upper
|
||||
if (hasThisDescriptor() && (enclosed != getThisDescriptor() || !fromOutsideContext)) {
|
||||
CodegenContext currentContext = this;
|
||||
@@ -371,12 +371,12 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
break;
|
||||
}
|
||||
|
||||
//accessors for private members in class object for call from class
|
||||
if (isClassObjectMember && currentContext instanceof ClassContext) {
|
||||
//accessors for private members in default object for call from class
|
||||
if (isDefaultObjectMember && currentContext instanceof ClassContext) {
|
||||
ClassContext classContext = (ClassContext) currentContext;
|
||||
CodegenContext classObject = classContext.getClassObjectContext();
|
||||
if (classObject != null && classObject.getContextDescriptor() == enclosed) {
|
||||
descriptorContext = classObject;
|
||||
CodegenContext defaultObjectContext = classContext.getDefaultObjectContext();
|
||||
if (defaultObjectContext != null && defaultObjectContext.getContextDescriptor() == enclosed) {
|
||||
descriptorContext = defaultObjectContext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -417,7 +417,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
}
|
||||
|
||||
protected boolean shouldAddChild(@NotNull CodegenContext child) {
|
||||
return DescriptorUtils.isClassObject(child.contextDescriptor);
|
||||
return DescriptorUtils.isDefaultObject(child.contextDescriptor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ public abstract class FileBasedKotlinClass implements KotlinJvmBinaryClass {
|
||||
@NotNull
|
||||
protected abstract byte[] getFileContents();
|
||||
|
||||
// TODO public to be accessible in class object of subclass, workaround for KT-3974
|
||||
// TODO public to be accessible in default object of subclass, workaround for KT-3974
|
||||
@Nullable
|
||||
public static <T extends FileBasedKotlinClass> T create(
|
||||
@NotNull byte[] fileContents,
|
||||
|
||||
+2
-2
@@ -102,9 +102,9 @@ public class PlatformStaticAnnotationChecker : AnnotationChecker {
|
||||
diagnosticHolder: DiagnosticSink
|
||||
) {
|
||||
val insideObject = containerKindIs(descriptor, ClassKind.OBJECT)
|
||||
val insideClassObject = containerKindIs(descriptor, ClassKind.CLASS_OBJECT)
|
||||
val insideDefaultObject = containerKindIs(descriptor, ClassKind.CLASS_OBJECT)
|
||||
|
||||
if (!insideObject && !(insideClassObject && containerKindIs(descriptor.getContainingDeclaration()!!, ClassKind.CLASS))) {
|
||||
if (!insideObject && !(insideDefaultObject && containerKindIs(descriptor.getContainingDeclaration()!!, ClassKind.CLASS))) {
|
||||
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 classobject) controlled via NEED_SYNTHETIC_ACCESSOR slice
|
||||
// e.g.: from class to default 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 class objects of classes can be annotated with 'platformStatic'");
|
||||
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.OVERRIDE_CANNOT_BE_STATIC, "Override 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. Class object may be initialized at this point");
|
||||
// TODO : Support Type Arguments. Default object may be initialized at this point");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private Collection<JetType> supertypes = new ArrayList<JetType>();
|
||||
|
||||
private MutableClassDescriptor classObjectDescriptor;
|
||||
private MutableClassDescriptor defaultObjectDescriptor;
|
||||
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
@@ -93,7 +93,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
@Nullable
|
||||
@Override
|
||||
public MutableClassDescriptor getDefaultObjectDescriptor() {
|
||||
return classObjectDescriptor;
|
||||
return defaultObjectDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -306,8 +306,8 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
public void lockScopes() {
|
||||
getScopeForMemberLookupAsWritableScope().changeLockLevel(WritableScope.LockLevel.READING);
|
||||
if (classObjectDescriptor != null) {
|
||||
classObjectDescriptor.lockScopes();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
defaultObjectDescriptor.lockScopes();
|
||||
}
|
||||
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
scopeForMemberResolution.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
@@ -186,10 +186,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);
|
||||
|
||||
// Class objects
|
||||
// Default objects
|
||||
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_CLASS_OBJECTS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetObjectDeclaration> CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_DEFAULT_OBJECTS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetObjectDeclaration> DEFAULT_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Objects
|
||||
|
||||
@@ -198,12 +198,12 @@ public interface Errors {
|
||||
// Type parameter declarations
|
||||
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_CLASS_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetTypeReference, JetType> FINAL_DEFAULT_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_CLASS_OBJECT_UPPER_BOUNDS
|
||||
DiagnosticFactory1<JetNamedDeclaration, TypeParameterDescriptor> CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS
|
||||
= DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
|
||||
DiagnosticFactory2<JetSimpleNameExpression, JetTypeConstraint, JetTypeParameterListOwner> NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER =
|
||||
@@ -605,7 +605,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_CLASS_OBJECT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_DEFAULT_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);
|
||||
|
||||
+6
-6
@@ -270,8 +270,8 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(UNREACHABLE_CODE, "Unreachable code", TO_STRING);
|
||||
|
||||
MAP.put(MANY_CLASS_OBJECTS, "Only one class object is allowed per class");
|
||||
MAP.put(CLASS_OBJECT_NOT_ALLOWED, "A class object is not allowed here");
|
||||
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(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);
|
||||
MAP.put(DELEGATION_IN_TRAIT, "Traits cannot use delegation");
|
||||
@@ -315,9 +315,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_CLASS_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a class object", NAME);
|
||||
MAP.put(NO_DEFAULT_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a default 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 class 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 default 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);
|
||||
@@ -375,12 +375,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_CLASS_OBJECT_UPPER_BOUND, "''{0}'' is a final type, and thus a class object cannot extend it", 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_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_CLASS_OBJECT_UPPER_BOUNDS, "Class object 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(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES);
|
||||
|
||||
|
||||
@@ -765,7 +765,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
* ;
|
||||
*
|
||||
* memberDeclaration'
|
||||
* : classObject
|
||||
* : defaultObject
|
||||
* : constructor
|
||||
* : function
|
||||
* : property
|
||||
@@ -798,7 +798,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
IElementType declType = null;
|
||||
if (keywordToken == CLASS_KEYWORD) {
|
||||
if (lookahead(1) == OBJECT_KEYWORD) {
|
||||
declType = parseClassObject();
|
||||
declType = parseDefaultObject();
|
||||
}
|
||||
else {
|
||||
declType = parseClass(isEnum);
|
||||
@@ -876,11 +876,11 @@ public class JetParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
/*
|
||||
* classObject
|
||||
* defaultObject
|
||||
* : modifiers "class" object
|
||||
* ;
|
||||
*/
|
||||
private IElementType parseClassObject() {
|
||||
private IElementType parseDefaultObject() {
|
||||
assert _at(CLASS_KEYWORD) && lookahead(1) == OBJECT_KEYWORD;
|
||||
advance(); // CLASS_KEYWORD
|
||||
parseObject(NameParsingMode.ALLOWED, true);
|
||||
|
||||
@@ -237,7 +237,7 @@ private object DebugTextBuildingVisitor : JetVisitor<String, Unit>() {
|
||||
return buildText {
|
||||
append("STUB: ")
|
||||
appendInn(declaration.getModifierList(), suffix = " ")
|
||||
if (declaration.isClassObject()) {
|
||||
if (declaration.isDefault()) {
|
||||
append("class ")
|
||||
}
|
||||
append("object ")
|
||||
@@ -273,7 +273,7 @@ private object DebugTextBuildingVisitor : JetVisitor<String, Unit>() {
|
||||
|
||||
override fun visitTypeConstraint(constraint: JetTypeConstraint, data: Unit?): String? {
|
||||
return buildText {
|
||||
if (constraint.isClassObjectConstraint()) {
|
||||
if (constraint.isDefaultObjectConstraint()) {
|
||||
append("class object ")
|
||||
}
|
||||
appendInn(constraint.getSubjectTypeParameterName())
|
||||
|
||||
@@ -142,10 +142,10 @@ public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> imp
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
public JetObjectDeclaration getDefaultObject() {
|
||||
JetClassBody body = getBody();
|
||||
if (body == null) return null;
|
||||
return body.getClassObject();
|
||||
return body.getDefaultObject();
|
||||
}
|
||||
|
||||
public List<JetProperty> getProperties() {
|
||||
|
||||
@@ -67,15 +67,15 @@ public class JetClassBody extends JetElementImplStub<KotlinPlaceHolderStub<JetCl
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
return firstOrNull(getAllClassObjects());
|
||||
public JetObjectDeclaration getDefaultObject() {
|
||||
return firstOrNull(getAllDefaultObjects());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetObjectDeclaration> getAllClassObjects() {
|
||||
public List<JetObjectDeclaration> getAllDefaultObjects() {
|
||||
List<JetObjectDeclaration> result = Lists.newArrayList();
|
||||
for (JetObjectDeclaration declaration : getStubOrPsiChildrenAsList(JetStubElementTypes.OBJECT_DECLARATION)) {
|
||||
if (declaration.isClassObject()) {
|
||||
if (declaration.isDefault()) {
|
||||
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).isClassObject()) {
|
||||
JetElement classObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
|
||||
if (classObjectClass != null) {
|
||||
containingClass = classObjectClass;
|
||||
if (containingClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) containingClass).isDefault()) {
|
||||
JetElement defaultObjectClass = PsiTreeUtil.getParentOfType(containingClass, JetClassOrObject.class);
|
||||
if (defaultObjectClass != null) {
|
||||
containingClass = defaultObjectClass;
|
||||
}
|
||||
}
|
||||
if (containingClass != null) {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
}
|
||||
|
||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
||||
if (nameAsDeclaration == null && isClassObject()) {
|
||||
if (nameAsDeclaration == null && isDefault()) {
|
||||
//NOTE: a hack in PSI that simplifies writing frontend code
|
||||
return SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.toString();
|
||||
}
|
||||
@@ -86,10 +86,10 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
||||
return (JetObjectDeclarationName) findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME);
|
||||
}
|
||||
|
||||
public boolean isClassObject() {
|
||||
public boolean isDefault() {
|
||||
KotlinObjectStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isClassObject();
|
||||
return stub.isDefault();
|
||||
}
|
||||
return getClassKeyword() != null;
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ public class JetTypeConstraint extends JetElementImplStub<KotlinTypeConstraintSt
|
||||
return visitor.visitTypeConstraint(this, data);
|
||||
}
|
||||
|
||||
public boolean isClassObjectConstraint() {
|
||||
public boolean isDefaultObjectConstraint() {
|
||||
KotlinTypeConstraintStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.isClassObjectConstraint();
|
||||
return stub.isDefaultObjectConstraint();
|
||||
}
|
||||
return findChildByType(JetTokens.CLASS_KEYWORD) != null &&
|
||||
findChildByType(JetTokens.OBJECT_KEYWORD) != null;
|
||||
|
||||
@@ -47,7 +47,7 @@ public trait KotlinClassStub : KotlinClassOrObjectStub<JetClass> {
|
||||
}
|
||||
|
||||
public trait KotlinObjectStub : KotlinClassOrObjectStub<JetObjectDeclaration> {
|
||||
public fun isClassObject(): Boolean
|
||||
public fun isDefault(): Boolean
|
||||
public fun isObjectLiteral(): Boolean
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public trait KotlinPropertyStub : KotlinStubWithFqName<JetProperty> {
|
||||
}
|
||||
|
||||
public trait KotlinTypeConstraintStub : StubElement<JetTypeConstraint> {
|
||||
public fun isClassObjectConstraint(): Boolean
|
||||
public fun isDefaultObjectConstraint(): Boolean
|
||||
}
|
||||
|
||||
public trait KotlinTypeParameterStub : KotlinStubWithFqName<JetTypeParameter> {
|
||||
|
||||
+4
-4
@@ -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.isClassObject(), psi.isLocal(), psi.isObjectLiteral());
|
||||
psi.isTopLevel(), psi.isDefault(), psi.isLocal(), psi.isObjectLiteral());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,7 +56,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
|
||||
dataStream.writeName(fqName != null ? fqName.toString() : null);
|
||||
|
||||
dataStream.writeBoolean(stub.isTopLevel());
|
||||
dataStream.writeBoolean(stub.isClassObject());
|
||||
dataStream.writeBoolean(stub.isDefault());
|
||||
dataStream.writeBoolean(stub.isLocal());
|
||||
dataStream.writeBoolean(stub.isObjectLiteral());
|
||||
|
||||
@@ -75,7 +75,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
|
||||
FqName fqName = fqNameStr != null ? new FqName(fqNameStr.toString()) : null;
|
||||
|
||||
boolean isTopLevel = dataStream.readBoolean();
|
||||
boolean isClassObject = dataStream.readBoolean();
|
||||
boolean isDefault = dataStream.readBoolean();
|
||||
boolean isLocal = dataStream.readBoolean();
|
||||
boolean isObjectLiteral = dataStream.readBoolean();
|
||||
|
||||
@@ -85,7 +85,7 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
|
||||
superNames[i] = dataStream.readName();
|
||||
}
|
||||
|
||||
return new KotlinObjectStubImpl(parentStub, name, fqName, superNames, isTopLevel, isClassObject, isLocal, isObjectLiteral);
|
||||
return new KotlinObjectStubImpl(parentStub, name, fqName, superNames, isTopLevel, isDefault, isLocal, 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.isClassObjectConstraint());
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, psi.isDefaultObjectConstraint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NotNull KotlinTypeConstraintStub stub, @NotNull StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeBoolean(stub.isClassObjectConstraint());
|
||||
dataStream.writeBoolean(stub.isDefaultObjectConstraint());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinTypeConstraintStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
boolean isClassObjectConstraint = dataStream.readBoolean();
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, isClassObjectConstraint);
|
||||
boolean isDefaultObjectConstraint = dataStream.readBoolean();
|
||||
return new KotlinTypeConstraintStubImpl(parentStub, isDefaultObjectConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class KotlinObjectStubImpl(
|
||||
private val fqName: FqName?,
|
||||
private val superNames: Array<StringRef>,
|
||||
private val isTopLevel: Boolean,
|
||||
private val isClassObject: Boolean,
|
||||
private val isDefault: Boolean,
|
||||
private val isLocal: Boolean,
|
||||
private val isObjectLiteral: Boolean
|
||||
) : KotlinStubBaseImpl<JetObjectDeclaration>(parent, JetStubElementTypes.OBJECT_DECLARATION), KotlinObjectStub {
|
||||
@@ -39,7 +39,7 @@ public class KotlinObjectStubImpl(
|
||||
override fun getName() = StringRef.toString(name)
|
||||
override fun getSuperNames() = superNames map { it.toString() }
|
||||
override fun isTopLevel() = isTopLevel
|
||||
override fun isClassObject() = isClassObject
|
||||
override fun isDefault() = isDefault
|
||||
override fun isObjectLiteral() = isObjectLiteral
|
||||
override fun isLocal() = isLocal
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ import com.intellij.psi.PsiElement
|
||||
|
||||
public class KotlinTypeConstraintStubImpl(
|
||||
parent: StubElement<out PsiElement>?,
|
||||
private val isClassObjectConstraint: Boolean
|
||||
private val isDefaultObjectConstraint: Boolean
|
||||
) : KotlinStubBaseImpl<JetTypeConstraint>(parent, JetStubElementTypes.TYPE_CONSTRAINT), KotlinTypeConstraintStub {
|
||||
|
||||
override fun isClassObjectConstraint() = isClassObjectConstraint
|
||||
override fun isDefaultObjectConstraint() = isDefaultObjectConstraint
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public fun DeclarationDescriptor.hasIntrinsicAnnotation(): Boolean {
|
||||
public fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
|
||||
isPlatformStaticIn(ClassKind.OBJECT, ClassKind.CLASS)
|
||||
|
||||
public fun CallableDescriptor.isPlatformStaticInClassObject(): Boolean =
|
||||
public fun CallableDescriptor.isPlatformStaticInDefaultObject(): Boolean =
|
||||
isPlatformStaticIn(ClassKind.CLASS_OBJECT)
|
||||
|
||||
private fun CallableDescriptor.isPlatformStaticIn(vararg kinds: ClassKind): Boolean =
|
||||
|
||||
@@ -61,16 +61,16 @@ public class DeclarationResolver {
|
||||
public fun checkRedeclarationsInInnerClassNames(c: TopDownAnalysisContext) {
|
||||
for (classDescriptor in c.getDeclaredClasses().values()) {
|
||||
if (classDescriptor.getKind() == ClassKind.CLASS_OBJECT) {
|
||||
// Class objects should be considered during analysing redeclarations in classes
|
||||
// Default objects should be considered during analysing redeclarations in classes
|
||||
continue
|
||||
}
|
||||
|
||||
var allDescriptors = classDescriptor.getScopeForMemberLookup().getOwnDeclaredDescriptors()
|
||||
val classObj = classDescriptor.getDefaultObjectDescriptor()
|
||||
if (classObj != null) {
|
||||
val classObjDescriptors = classObj.getScopeForMemberLookup().getOwnDeclaredDescriptors()
|
||||
if (classObjDescriptors.isNotEmpty()) {
|
||||
allDescriptors = allDescriptors + classObjDescriptors
|
||||
val defaultObject = classDescriptor.getDefaultObjectDescriptor()
|
||||
if (defaultObject != null) {
|
||||
val descriptorsFromDefaultObject = defaultObject.getScopeForMemberLookup().getOwnDeclaredDescriptors()
|
||||
if (descriptorsFromDefaultObject.isNotEmpty()) {
|
||||
allDescriptors = allDescriptors + descriptorsFromDefaultObject
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ public class DeclarationsChecker {
|
||||
|
||||
for (JetTypeConstraint constraint : jetClass.getTypeConstraints()) {
|
||||
checkBoundsForTypeInClassHeader(constraint.getBoundTypeReference());
|
||||
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isClassObjectConstraint());
|
||||
checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isDefaultObjectConstraint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,11 +167,11 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isClassObjectConstraint) {
|
||||
private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isDefaultObjectConstraint) {
|
||||
if (typeReference != null) {
|
||||
JetType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||
if (type != null) {
|
||||
DescriptorResolver.checkUpperBoundType(typeReference, type, isClassObjectConstraint, trace);
|
||||
DescriptorResolver.checkUpperBoundType(typeReference, type, isDefaultObjectConstraint, trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,7 +260,7 @@ public class DeclarationsChecker {
|
||||
|
||||
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
|
||||
reportErrorIfHasIllegalModifier(declaration);
|
||||
if (declaration.isLocal() && !declaration.isClassObject() && !declaration.isObjectLiteral()) {
|
||||
if (declaration.isLocal() && !declaration.isDefault() && !declaration.isObjectLiteral()) {
|
||||
trace.report(LOCAL_OBJECT_NOT_ALLOWED.on(declaration, classDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,12 +651,12 @@ public class DescriptorResolver {
|
||||
static final class UpperBoundCheckerTask {
|
||||
JetTypeReference upperBound;
|
||||
JetType upperBoundType;
|
||||
boolean isClassObjectConstraint;
|
||||
boolean isDefaultObjectConstraint;
|
||||
|
||||
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean classObjectConstraint) {
|
||||
private UpperBoundCheckerTask(JetTypeReference upperBound, JetType upperBoundType, boolean defaultObjectConstraint) {
|
||||
this.upperBound = upperBound;
|
||||
this.upperBoundType = upperBoundType;
|
||||
isClassObjectConstraint = classObjectConstraint;
|
||||
isDefaultObjectConstraint = defaultObjectConstraint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
for (JetTypeConstraint constraint : declaration.getTypeConstraints()) {
|
||||
reportUnsupportedClassObjectConstraint(trace, constraint);
|
||||
reportUnsupportedDefaultObjectConstraint(trace, constraint);
|
||||
|
||||
JetSimpleNameExpression subjectTypeParameterName = constraint.getSubjectTypeParameterName();
|
||||
if (subjectTypeParameterName == null) {
|
||||
@@ -698,15 +698,14 @@ public class DescriptorResolver {
|
||||
if (boundTypeReference != null) {
|
||||
bound = typeResolver.resolveType(scope, boundTypeReference, trace, false);
|
||||
deferredUpperBoundCheckerTasks
|
||||
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isClassObjectConstraint()));
|
||||
.add(new UpperBoundCheckerTask(boundTypeReference, bound, constraint.isDefaultObjectConstraint()));
|
||||
}
|
||||
|
||||
if (typeParameterDescriptor != null) {
|
||||
trace.record(BindingContext.REFERENCE_TARGET, subjectTypeParameterName, typeParameterDescriptor);
|
||||
if (bound != null) {
|
||||
if (constraint.isClassObjectConstraint()) {
|
||||
// Class object bounds are not supported
|
||||
//typeParameterDescriptor.addClassObjectBound(bound);
|
||||
if (constraint.isDefaultObjectConstraint()) {
|
||||
// Default object bounds are not supported
|
||||
}
|
||||
else {
|
||||
typeParameterDescriptor.addUpperBound(bound);
|
||||
@@ -725,7 +724,7 @@ public class DescriptorResolver {
|
||||
|
||||
if (!(declaration instanceof JetClass)) {
|
||||
for (UpperBoundCheckerTask checkerTask : deferredUpperBoundCheckerTasks) {
|
||||
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isClassObjectConstraint, trace);
|
||||
checkUpperBoundType(checkerTask.upperBound, checkerTask.upperBoundType, checkerTask.isDefaultObjectConstraint, trace);
|
||||
}
|
||||
|
||||
checkNamesInConstraints(declaration, descriptor, scope, trace);
|
||||
@@ -743,7 +742,7 @@ public class DescriptorResolver {
|
||||
|
||||
JetType classObjectType = parameter.getClassObjectType();
|
||||
if (classObjectType != null && KotlinBuiltIns.isNothing(classObjectType)) {
|
||||
trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
trace.report(CONFLICTING_DEFAULT_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,21 +777,21 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
public static void reportUnsupportedClassObjectConstraint(BindingTrace trace, JetTypeConstraint constraint) {
|
||||
if (constraint.isClassObjectConstraint()) {
|
||||
trace.report(UNSUPPORTED.on(constraint, "Class objects constraints are not supported yet"));
|
||||
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 checkUpperBoundType(
|
||||
JetTypeReference upperBound,
|
||||
@NotNull JetType upperBoundType,
|
||||
boolean isClassObjectConstraint,
|
||||
boolean isDefaultObjectConstraint,
|
||||
BindingTrace trace
|
||||
) {
|
||||
if (!TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, upperBoundType)) {
|
||||
if (isClassObjectConstraint) {
|
||||
trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
if (isDefaultObjectConstraint) {
|
||||
trace.report(FINAL_DEFAULT_OBJECT_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
}
|
||||
else {
|
||||
trace.report(FINAL_UPPER_BOUND.on(upperBound, upperBoundType));
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.MANY_CLASS_OBJECTS;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.MANY_DEFAULT_OBJECTS;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED;
|
||||
|
||||
public class LazyTopDownAnalyzer {
|
||||
@@ -191,19 +191,19 @@ public class LazyTopDownAnalyzer {
|
||||
registerDeclarations(classOrObject.getDeclarations());
|
||||
registerTopLevelFqName(topLevelFqNames, classOrObject, descriptor);
|
||||
|
||||
checkManyClassObjects(classOrObject);
|
||||
checkManyDefaultObjects(classOrObject);
|
||||
}
|
||||
|
||||
private void checkManyClassObjects(JetClassOrObject classOrObject) {
|
||||
boolean classObjectAlreadyFound = false;
|
||||
private void checkManyDefaultObjects(JetClassOrObject classOrObject) {
|
||||
boolean defaultObjectAlreadyFound = false;
|
||||
for (JetDeclaration jetDeclaration : classOrObject.getDeclarations()) {
|
||||
jetDeclaration.accept(this);
|
||||
|
||||
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isClassObject()) {
|
||||
if (classObjectAlreadyFound) {
|
||||
trace.report(MANY_CLASS_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
|
||||
if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isDefault()) {
|
||||
if (defaultObjectAlreadyFound) {
|
||||
trace.report(MANY_DEFAULT_OBJECTS.on((JetObjectDeclaration) jetDeclaration));
|
||||
}
|
||||
classObjectAlreadyFound = true;
|
||||
defaultObjectAlreadyFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ public class ModifiersChecker {
|
||||
if (DescriptorUtils.isTrait(containingDeclaration)) {
|
||||
return InnerModifierCheckResult.IN_TRAIT;
|
||||
}
|
||||
else if (DescriptorUtils.isClassObject(containingDeclaration) || DescriptorUtils.isObject(containingDeclaration)) {
|
||||
else if (DescriptorUtils.isDefaultObject(containingDeclaration) || DescriptorUtils.isObject(containingDeclaration)) {
|
||||
return InnerModifierCheckResult.IN_OBJECT;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class OverloadResolver {
|
||||
return name;
|
||||
}
|
||||
if (jetClass instanceof JetObjectDeclaration) {
|
||||
// must be class object
|
||||
// must be default object
|
||||
name = classDescriptor.getContainingDeclaration().getName().asString();
|
||||
return "class object " + name;
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class FakeCallableDescriptorForObject(
|
||||
|
||||
{
|
||||
assert(classDescriptor.getClassObjectType() != null) {
|
||||
"FakeCallableDescriptorForObject can be created only for objects, classes with class object or enum entries: $classDescriptor"
|
||||
"FakeCallableDescriptorForObject can be created only for objects, classes with default object or enum entries: $classDescriptor"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
return false
|
||||
}
|
||||
if (DescriptorUtils.isObject(descriptor.getContainingDeclaration()) ||
|
||||
DescriptorUtils.isClassObject(descriptor.getContainingDeclaration()) ||
|
||||
DescriptorUtils.isDefaultObject(descriptor.getContainingDeclaration()) ||
|
||||
DescriptorUtils.isStaticDeclaration(descriptor)) {
|
||||
val returnType = descriptor.getType()
|
||||
return KotlinBuiltIns.isPrimitiveType(returnType) || KotlinBuiltIns.isString(returnType)
|
||||
|
||||
@@ -46,8 +46,8 @@ public class JetClassInfo extends JetClassOrObjectInfo<JetClass> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
return element.getClassObject();
|
||||
public JetObjectDeclaration getDefaultObject() {
|
||||
return element.getDefaultObject();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -34,11 +34,11 @@ public interface JetClassLikeInfo extends JetDeclarationContainer {
|
||||
JetModifierList getModifierList();
|
||||
|
||||
@Nullable
|
||||
JetObjectDeclaration getClassObject();
|
||||
JetObjectDeclaration getDefaultObject();
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
List<JetObjectDeclaration> getClassObjects();
|
||||
List<JetObjectDeclaration> getDefaultObjects();
|
||||
|
||||
// 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> getClassObjects() {
|
||||
public List<JetObjectDeclaration> getDefaultObjects() {
|
||||
JetClassBody body = element.getBody();
|
||||
if (body == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return body.getAllClassObjects();
|
||||
return body.getAllDefaultObjects();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -34,11 +34,11 @@ public class JetObjectInfo extends JetClassOrObjectInfo<JetObjectDeclaration> {
|
||||
super(element);
|
||||
this.kind = element.isObjectLiteral()
|
||||
? ClassKind.CLASS
|
||||
: (element.isClassObject() ? ClassKind.CLASS_OBJECT : ClassKind.OBJECT);
|
||||
: (element.isDefault() ? ClassKind.CLASS_OBJECT : ClassKind.OBJECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
public JetObjectDeclaration getDefaultObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ public class JetScriptInfo(
|
||||
public val fqName: FqName = ScriptNameUtil.classNameForScript(script)
|
||||
override fun getContainingPackageFqName() = fqName.parent()
|
||||
override fun getModifierList() = null
|
||||
override fun getClassObject() = null
|
||||
override fun getClassObjects() = listOf<JetObjectDeclaration>()
|
||||
override fun getDefaultObject() = null
|
||||
override fun getDefaultObjects() = listOf<JetObjectDeclaration>()
|
||||
override fun getScopeAnchor() = script
|
||||
override fun getCorrespondingClassOrObject() = null
|
||||
override fun getTypeParameterList() = null
|
||||
|
||||
+40
-40
@@ -81,8 +81,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
private final Annotations annotations;
|
||||
private final Annotations danglingAnnotations;
|
||||
private final NullableLazyValue<LazyClassDescriptor> classObjectDescriptor;
|
||||
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraClassObjectDescriptors;
|
||||
private final NullableLazyValue<LazyClassDescriptor> defaultObjectDescriptor;
|
||||
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> extraDefaultObjectDescriptors;
|
||||
|
||||
private final LazyClassMemberScope unsubstitutedMemberScope;
|
||||
private final JetScope staticScope = new StaticScopeForKotlinClass(this);
|
||||
@@ -177,16 +177,16 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
);
|
||||
}
|
||||
|
||||
this.classObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
|
||||
this.defaultObjectDescriptor = storageManager.createNullableLazyValue(new Function0<LazyClassDescriptor>() {
|
||||
@Override
|
||||
public LazyClassDescriptor invoke() {
|
||||
return computeClassObjectDescriptor(getClassObjectIfAllowed());
|
||||
return computeDefaultObjectDescriptor(getDefaultObjectIfAllowed());
|
||||
}
|
||||
});
|
||||
this.extraClassObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
this.extraDefaultObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(JetObjectDeclaration classObject) {
|
||||
return computeClassObjectDescriptor(classObject);
|
||||
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
|
||||
return computeDefaultObjectDescriptor(defaultObject);
|
||||
}
|
||||
});
|
||||
this.scopeForClassHeaderResolution = storageManager.createLazyValue(new Function0<JetScope>() {
|
||||
@@ -266,8 +266,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
thisScope.setImplicitReceiver(this.getThisAsReceiverParameter());
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
ClassDescriptor classObject = getDefaultObjectDescriptor();
|
||||
JetScope classObjectAdapterScope = (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.Empty.INSTANCE$;
|
||||
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
|
||||
JetScope defaultObjectAdapterScope = (defaultObjectDescriptor != null) ? new DefaultObjectMixinScope(defaultObjectDescriptor) : JetScope.Empty.INSTANCE$;
|
||||
|
||||
return new ChainedScope(
|
||||
this,
|
||||
@@ -275,7 +275,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
thisScope,
|
||||
getScopeForMemberLookup(),
|
||||
getScopeForClassHeaderResolution(),
|
||||
classObjectAdapterScope,
|
||||
defaultObjectAdapterScope,
|
||||
getStaticScope()
|
||||
);
|
||||
}
|
||||
@@ -347,46 +347,46 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
@Override
|
||||
public LazyClassDescriptor getDefaultObjectDescriptor() {
|
||||
return classObjectDescriptor.invoke();
|
||||
return defaultObjectDescriptor.invoke();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
public List<ClassDescriptor> getDescriptorsForExtraClassObjects() {
|
||||
final JetObjectDeclaration allowedClassObject = getClassObjectIfAllowed();
|
||||
public List<ClassDescriptor> getDescriptorsForExtraDefaultObjects() {
|
||||
final JetObjectDeclaration allowedDefaultObject = getDefaultObjectIfAllowed();
|
||||
|
||||
return KotlinPackage.map(
|
||||
KotlinPackage.filter(
|
||||
declarationProvider.getOwnerInfo().getClassObjects(),
|
||||
declarationProvider.getOwnerInfo().getDefaultObjects(),
|
||||
new Function1<JetObjectDeclaration, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(JetObjectDeclaration classObject) {
|
||||
return classObject != allowedClassObject;
|
||||
public Boolean invoke(JetObjectDeclaration defaultObject) {
|
||||
return defaultObject != allowedDefaultObject;
|
||||
}
|
||||
}
|
||||
),
|
||||
new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(JetObjectDeclaration classObject) {
|
||||
return extraClassObjectDescriptors.invoke(classObject);
|
||||
public ClassDescriptor invoke(JetObjectDeclaration defaultObject) {
|
||||
return extraDefaultObjectDescriptors.invoke(defaultObject);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LazyClassDescriptor computeClassObjectDescriptor(@Nullable JetObjectDeclaration classObject) {
|
||||
JetClassLikeInfo classObjectInfo = getClassObjectInfo(classObject);
|
||||
if (!(classObjectInfo instanceof JetClassOrObjectInfo)) {
|
||||
private LazyClassDescriptor computeDefaultObjectDescriptor(@Nullable JetObjectDeclaration defaultObject) {
|
||||
JetClassLikeInfo defaultObjectInfo = getDefaultObjectInfo(defaultObject);
|
||||
if (!(defaultObjectInfo instanceof JetClassOrObjectInfo)) {
|
||||
return null;
|
||||
}
|
||||
Name name = ((JetClassOrObjectInfo) classObjectInfo).getName();
|
||||
Name name = ((JetClassOrObjectInfo) defaultObjectInfo).getName();
|
||||
assert name != null;
|
||||
getScopeForMemberLookup().getClassifier(name);
|
||||
ClassDescriptor classObjectDescriptor = c.getTrace().get(BindingContext.CLASS, classObject);
|
||||
if (classObjectDescriptor instanceof LazyClassDescriptor) {
|
||||
assert DescriptorUtils.isClassObject(classObjectDescriptor) : "Not a class object: " + classObjectDescriptor;
|
||||
return (LazyClassDescriptor) classObjectDescriptor;
|
||||
ClassDescriptor defaultObjectDescriptor = c.getTrace().get(BindingContext.CLASS, defaultObject);
|
||||
if (defaultObjectDescriptor instanceof LazyClassDescriptor) {
|
||||
assert DescriptorUtils.isDefaultObject(defaultObjectDescriptor) : "Not a default object: " + defaultObjectDescriptor;
|
||||
return (LazyClassDescriptor) defaultObjectDescriptor;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -394,25 +394,25 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetClassLikeInfo getClassObjectInfo(@Nullable JetObjectDeclaration classObject) {
|
||||
if (classObject != null) {
|
||||
if (!isClassObjectAllowed()) {
|
||||
c.getTrace().report(CLASS_OBJECT_NOT_ALLOWED.on(classObject));
|
||||
private JetClassLikeInfo getDefaultObjectInfo(@Nullable JetObjectDeclaration defaultObject) {
|
||||
if (defaultObject != null) {
|
||||
if (!isDefaultObjectAllowed()) {
|
||||
c.getTrace().report(DEFAULT_OBJECT_NOT_ALLOWED.on(defaultObject));
|
||||
}
|
||||
|
||||
return JetClassInfoUtil.createClassLikeInfo(classObject);
|
||||
return JetClassInfoUtil.createClassLikeInfo(defaultObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetObjectDeclaration getClassObjectIfAllowed() {
|
||||
JetObjectDeclaration classObject = declarationProvider.getOwnerInfo().getClassObject();
|
||||
return (classObject != null && isClassObjectAllowed()) ? classObject : null;
|
||||
private JetObjectDeclaration getDefaultObjectIfAllowed() {
|
||||
JetObjectDeclaration defaultObject = declarationProvider.getOwnerInfo().getDefaultObject();
|
||||
return (defaultObject != null && isDefaultObjectAllowed()) ? defaultObject : null;
|
||||
}
|
||||
|
||||
private boolean isClassObjectAllowed() {
|
||||
private boolean isDefaultObjectAllowed() {
|
||||
return !(getKind().isSingleton() || isInner() || DescriptorUtils.isLocal(this));
|
||||
}
|
||||
|
||||
@@ -463,13 +463,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
private void doForceResolveAllContents() {
|
||||
resolveMemberHeaders();
|
||||
ClassDescriptor classObjectDescriptor = getDefaultObjectDescriptor();
|
||||
if (classObjectDescriptor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(classObjectDescriptor);
|
||||
ClassDescriptor defaultObjectDescriptor = getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(defaultObjectDescriptor);
|
||||
}
|
||||
|
||||
ForceResolveUtil.forceResolveAllContents(getConstructors());
|
||||
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraClassObjects());
|
||||
ForceResolveUtil.forceResolveAllContents(getDescriptorsForExtraDefaultObjects());
|
||||
ForceResolveUtil.forceResolveAllContents(getScopeForMemberLookup());
|
||||
ForceResolveUtil.forceResolveAllContents(getTypeConstructor());
|
||||
}
|
||||
@@ -481,7 +481,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
getDefaultObjectDescriptor();
|
||||
|
||||
getDescriptorsForExtraClassObjects();
|
||||
getDescriptorsForExtraDefaultObjects();
|
||||
|
||||
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 class objects do not have delegated members
|
||||
?: return setOf() // Enum default objects do not have delegated members
|
||||
|
||||
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.reportUnsupportedClassObjectConstraint(c.getTrace(), jetTypeConstraint);
|
||||
DescriptorResolver.reportUnsupportedDefaultObjectConstraint(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.isClassObjectConstraint()) {
|
||||
if (!jetTypeConstraint.isDefaultObjectConstraint()) {
|
||||
upperBounds.add(boundType);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.resolve.scopes
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
|
||||
/**
|
||||
* Members of the class object are accessible from the class.
|
||||
* Scope lazily delegates requests to class object scope.
|
||||
* Members of the default object are accessible from the class.
|
||||
* Scope lazily delegates requests to default object scope.
|
||||
*/
|
||||
public class ClassObjectMixinScope(private val classObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
|
||||
public class DefaultObjectMixinScope(private val defaultObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
|
||||
override val workerScope: JetScope
|
||||
get() = classObjectDescriptor.getDefaultType().getMemberScope()
|
||||
get() = defaultObjectDescriptor.getDefaultType().getMemberScope()
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = listOf(classObjectDescriptor.getThisAsReceiverParameter())
|
||||
override fun getImplicitReceiversHierarchy() = listOf(defaultObjectDescriptor.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 class object
|
||||
// members of the class object must be able to find it as an implicit receiver
|
||||
// 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
|
||||
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_CLASS_OBJECT.on(referenceExpression, classifier))
|
||||
context.trace.report(NO_DEFAULT_OBJECT.on(referenceExpression, classifier))
|
||||
}
|
||||
else if (packageView != null) {
|
||||
context.trace.report(EXPRESSION_EXPECTED_PACKAGE_FOUND.on(referenceExpression))
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ class DeclarationScopeProviderForLocalClassifierAnalyzer(
|
||||
}
|
||||
|
||||
override fun getOuterDataFlowInfoForDeclaration(elementOfDeclaration: PsiElement): DataFlowInfo {
|
||||
// nested (non-inner) classes and class objects are forbidden in local classes, so it's enough to be simply inside the class
|
||||
// nested (non-inner) classes and default objects are forbidden in local classes, so it's enough to be simply inside the class
|
||||
if (localClassDescriptorManager.insideMyClass(elementOfDeclaration)) {
|
||||
return localClassDescriptorManager.expressionTypingContext.dataFlowInfo
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ val t3 = test2<C>(C())
|
||||
|
||||
class Test<T>
|
||||
where
|
||||
<!UNSUPPORTED!>class object T : <!FINAL_CLASS_OBJECT_UPPER_BOUND!>Foo<!><!>,
|
||||
<!UNSUPPORTED!>class object T : <!FINAL_DEFAULT_OBJECT_UPPER_BOUND!>Foo<!><!>,
|
||||
<!UNSUPPORTED!>class object T : A<!> {}
|
||||
|
||||
val <T, B : T> x : Int = 0
|
||||
@@ -3,24 +3,24 @@ package foo
|
||||
class X {}
|
||||
|
||||
val s = <!EXPRESSION_EXPECTED_PACKAGE_FOUND!>java<!>
|
||||
val ss = <!NO_CLASS_OBJECT!>System<!>
|
||||
val sss = <!NO_CLASS_OBJECT!>X<!>
|
||||
val x = "${<!NO_CLASS_OBJECT!>System<!>}"
|
||||
val ss = <!NO_DEFAULT_OBJECT!>System<!>
|
||||
val sss = <!NO_DEFAULT_OBJECT!>X<!>
|
||||
val x = "${<!NO_DEFAULT_OBJECT!>System<!>}"
|
||||
val xs = java.<!EXPRESSION_EXPECTED_PACKAGE_FOUND!>lang<!>
|
||||
val xss = java.lang.<!NO_CLASS_OBJECT!>System<!>
|
||||
val xsss = foo.<!NO_CLASS_OBJECT!>X<!>
|
||||
val xss = java.lang.<!NO_DEFAULT_OBJECT!>System<!>
|
||||
val xsss = foo.<!NO_DEFAULT_OBJECT!>X<!>
|
||||
val xssss = <!EXPRESSION_EXPECTED_PACKAGE_FOUND!>foo<!>
|
||||
val f = { <!NO_CLASS_OBJECT!>System<!> }
|
||||
val f = { <!NO_DEFAULT_OBJECT!>System<!> }
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
<!EXPRESSION_EXPECTED_PACKAGE_FOUND!>java<!> = null
|
||||
<!NO_CLASS_OBJECT!>System<!> = null
|
||||
<!NO_CLASS_OBJECT!>System<!>!!
|
||||
java.lang.<!NO_CLASS_OBJECT!>System<!> = null
|
||||
java.lang.<!NO_CLASS_OBJECT!>System<!>!!
|
||||
<!NO_CLASS_OBJECT!>System<!> is Int
|
||||
<!NO_DEFAULT_OBJECT!>System<!> = null
|
||||
<!NO_DEFAULT_OBJECT!>System<!>!!
|
||||
java.lang.<!NO_DEFAULT_OBJECT!>System<!> = null
|
||||
java.lang.<!NO_DEFAULT_OBJECT!>System<!>!!
|
||||
<!NO_DEFAULT_OBJECT!>System<!> is Int
|
||||
<!INVISIBLE_MEMBER!>System<!>()
|
||||
(<!NO_CLASS_OBJECT!>System<!>)
|
||||
@foo <!NO_CLASS_OBJECT!>System<!>
|
||||
null in <!NO_CLASS_OBJECT!>System<!>
|
||||
}
|
||||
(<!NO_DEFAULT_OBJECT!>System<!>)
|
||||
@foo <!NO_DEFAULT_OBJECT!>System<!>
|
||||
null in <!NO_DEFAULT_OBJECT!>System<!>
|
||||
}
|
||||
@@ -4,7 +4,7 @@ class A {
|
||||
<!REDECLARATION!>class object<!> {
|
||||
val x = 1
|
||||
}
|
||||
<!MANY_CLASS_OBJECTS, REDECLARATION!>class object<!> {
|
||||
<!MANY_DEFAULT_OBJECTS, REDECLARATION!>class object<!> {
|
||||
val x = 1
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@ class AA {
|
||||
class object {
|
||||
val x = 1
|
||||
}
|
||||
<!MANY_CLASS_OBJECTS!>class object A<!> {
|
||||
<!MANY_DEFAULT_OBJECTS!>class object A<!> {
|
||||
val x = 1
|
||||
}
|
||||
<!MANY_CLASS_OBJECTS!>class object AA<!> {
|
||||
<!MANY_DEFAULT_OBJECTS!>class object AA<!> {
|
||||
val x = 1
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class B() {
|
||||
}
|
||||
|
||||
object b {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object<!> {
|
||||
<!DEFAULT_OBJECT_NOT_ALLOWED!>class object<!> {
|
||||
val x = 1
|
||||
} // error
|
||||
}
|
||||
@@ -35,7 +35,7 @@ val a = A.x
|
||||
val c = B.<!UNRESOLVED_REFERENCE!>x<!>
|
||||
val d = b.<!UNRESOLVED_REFERENCE!>x<!>
|
||||
|
||||
val s = <!NO_CLASS_OBJECT!>System<!> // error
|
||||
val s = <!NO_DEFAULT_OBJECT!>System<!> // error
|
||||
fun test() {
|
||||
System.out.println()
|
||||
java.lang.System.out.println()
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ object O {
|
||||
fun f() {
|
||||
A.c
|
||||
A.hashCode()
|
||||
A().<!NO_CLASS_OBJECT, NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE!>Nested<!>
|
||||
A().<!NO_DEFAULT_OBJECT, NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE!>Nested<!>
|
||||
A.Nested()
|
||||
A().Inner()
|
||||
A.Default.<!UNRESOLVED_REFERENCE!>Nested<!>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class A {
|
||||
inner class B {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object<!> { }
|
||||
<!DEFAULT_OBJECT_NOT_ALLOWED!>class object<!> { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,4 @@ class C {
|
||||
class D {
|
||||
class object { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
fun test() {
|
||||
class A {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object<!> {}
|
||||
<!DEFAULT_OBJECT_NOT_ALLOWED!>class object<!> {}
|
||||
}
|
||||
|
||||
object {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object<!> {}
|
||||
<!DEFAULT_OBJECT_NOT_ALLOWED!>class object<!> {}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -MANY_CLASS_OBJECTS -REDECLARATION
|
||||
// !DIAGNOSTICS: -MANY_DEFAULT_OBJECTS -REDECLARATION
|
||||
|
||||
// KT-3464 Front-end shouldn't allow override modifier in class declaration
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ enum class E {
|
||||
FIRST
|
||||
|
||||
SECOND {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object<!> {
|
||||
<!DEFAULT_OBJECT_NOT_ALLOWED!>class object<!> {
|
||||
fun foo() = 42
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package bar
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!><!NO_CLASS_OBJECT!>String<!>[<!SYNTAX!><!>]<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>names<!> <!DEBUG_INFO_MISSING_UNRESOLVED!><!SYNTAX!>=<!> ["ads"]<!>
|
||||
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!><!NO_DEFAULT_OBJECT!>String<!>[<!SYNTAX!><!>]<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>names<!> <!DEBUG_INFO_MISSING_UNRESOLVED!><!SYNTAX!>=<!> ["ads"]<!>
|
||||
}
|
||||
@@ -4,11 +4,11 @@ class A<T> {
|
||||
class B {
|
||||
fun test() {
|
||||
class C<W>() : P<W, <!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>T<!>> {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object<!> : P<<!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>W<!>, <!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>T<!>> {
|
||||
<!DEFAULT_OBJECT_NOT_ALLOWED!>class object<!> : P<<!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>W<!>, <!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>T<!>> {
|
||||
}
|
||||
|
||||
inner class D : P<W, <!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>T<!>>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
val a: String = <!NO_CLASS_OBJECT!>Nothing<!>
|
||||
val a: String = <!NO_DEFAULT_OBJECT!>Nothing<!>
|
||||
@@ -11,6 +11,6 @@ class C {
|
||||
}
|
||||
|
||||
fun f() {
|
||||
<!NO_CLASS_OBJECT, FUNCTION_EXPECTED!>TestInterface<!>()
|
||||
<!NO_DEFAULT_OBJECT, FUNCTION_EXPECTED!>TestInterface<!>()
|
||||
C.<!UNRESOLVED_REFERENCE!>I<!>()
|
||||
}
|
||||
@@ -144,8 +144,8 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
loadFile("classes/classObjectIsInnerClass.kt");
|
||||
GeneratedClassLoader loader = generateAndCreateClassLoader();
|
||||
Class<?> a = loader.loadClass("A");
|
||||
Class<?> aClassObject = loader.loadClass("A$" + SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.asString());
|
||||
assertSameElements(a.getDeclaredClasses(), aClassObject);
|
||||
assertEquals(a, aClassObject.getDeclaringClass());
|
||||
Class<?> defaultObject = loader.loadClass("A$" + SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.asString());
|
||||
assertSameElements(a.getDeclaredClasses(), defaultObject);
|
||||
assertEquals(a, defaultObject.getDeclaringClass());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@ public class InnerClassInfoGenTest extends CodegenTestCase {
|
||||
public void testInnerClassInfo() {
|
||||
InnerClassAttribute innerB = new InnerClassAttribute("A$B", "A", "B", ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
|
||||
InnerClassAttribute innerC = new InnerClassAttribute("A$B$C", "A$B", "C", ACC_PUBLIC | ACC_FINAL);
|
||||
String classObjectDefaultName = SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.asString();
|
||||
InnerClassAttribute innerAClassObject = new InnerClassAttribute(
|
||||
"A$" + classObjectDefaultName, "A", classObjectDefaultName, ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
|
||||
String defaultObjectDefaultName = SpecialNames.DEFAULT_NAME_FOR_DEFAULT_OBJECT.asString();
|
||||
InnerClassAttribute innerADefaultObject = new InnerClassAttribute(
|
||||
"A$" + defaultObjectDefaultName, "A", defaultObjectDefaultName, ACC_PUBLIC | ACC_STATIC | ACC_FINAL);
|
||||
|
||||
extractAndCompareInnerClasses("A", innerB, innerAClassObject);
|
||||
extractAndCompareInnerClasses("A", innerB, innerADefaultObject);
|
||||
extractAndCompareInnerClasses("A$B", innerB, innerC);
|
||||
extractAndCompareInnerClasses("A$B$C", innerB, innerC);
|
||||
extractAndCompareInnerClasses("A$" + classObjectDefaultName, innerAClassObject);
|
||||
extractAndCompareInnerClasses("A$" + defaultObjectDefaultName, innerADefaultObject);
|
||||
}
|
||||
|
||||
public void testLocalClass() {
|
||||
|
||||
+3
-8
@@ -75,7 +75,9 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
||||
|
||||
ClassDescriptor myClass = getClassDescriptor(testPackage, "MyClass");
|
||||
checkDescriptor(expectedAnnotation, myClass);
|
||||
checkDescriptor(expectedAnnotation, getClassObjectDescriptor(myClass));
|
||||
ClassDescriptor defaultObjectDescriptor = myClass.getDefaultObjectDescriptor();
|
||||
assert defaultObjectDescriptor != null : "Cannot find default object for class " + myClass.getName();
|
||||
checkDescriptor(expectedAnnotation, defaultObjectDescriptor);
|
||||
checkDescriptor(expectedAnnotation, getInnerClassDescriptor(myClass, "InnerClass"));
|
||||
|
||||
FunctionDescriptor foo = getFunctionDescriptor(myClass, "foo");
|
||||
@@ -199,13 +201,6 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
||||
return (ClassDescriptor) aClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClassDescriptor getClassObjectDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
||||
ClassDescriptor objectDescriptor = classDescriptor.getDefaultObjectDescriptor();
|
||||
assert objectDescriptor != null : "Cannot find class object for class " + classDescriptor.getName();
|
||||
return objectDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClassDescriptor getInnerClassDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
|
||||
Name propertyName = Name.identifier(name);
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class JvmAbi {
|
||||
|
||||
//TODO: To be removed after kotlin M11
|
||||
@Deprecated
|
||||
public static final String DEPRECATED_CLASS_OBJECT_FIELD = "OBJECT$";
|
||||
public static final String DEPRECATED_DEFAULT_OBJECT_FIELD = "OBJECT$";
|
||||
|
||||
@NotNull
|
||||
public static String getSyntheticMethodNameForAnnotatedProperty(@NotNull Name propertyName) {
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
||||
val classKind = Flags.CLASS_KIND[classProto.getFlags()]
|
||||
val classId = nameResolver.getClassId(classProto.getFqName())
|
||||
if (classKind == ProtoBuf.Class.Kind.CLASS_OBJECT && isStaticFieldInOuter(proto)) {
|
||||
// Backing fields of properties of a class object are generated in the outer class
|
||||
// Backing fields of properties of a default object are generated in the outer class
|
||||
return kotlinClassFinder.findKotlinClass(classId.getOuterClassId())
|
||||
}
|
||||
else if (classKind == ProtoBuf.Class.Kind.TRAIT && annotatedCallableKind == AnnotatedCallableKind.PROPERTY) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Visibilities {
|
||||
DeclarationDescriptor parent = what;
|
||||
while (parent != null) {
|
||||
parent = parent.getContainingDeclaration();
|
||||
if ((parent instanceof ClassDescriptor && !DescriptorUtils.isClassObject(parent)) ||
|
||||
if ((parent instanceof ClassDescriptor && !DescriptorUtils.isDefaultObject(parent)) ||
|
||||
parent instanceof PackageFragmentDescriptor) {
|
||||
break;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class Visibilities {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
ClassDescriptor classDescriptor = DescriptorUtils.getParentOfType(what, ClassDescriptor.class);
|
||||
if (DescriptorUtils.isClassObject(classDescriptor)) {
|
||||
if (DescriptorUtils.isDefaultObject(classDescriptor)) {
|
||||
classDescriptor = DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
|
||||
}
|
||||
if (classDescriptor == null) return false;
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
||||
|
||||
@Override
|
||||
public JetType getClassObjectType() {
|
||||
// TODO: class object bounds
|
||||
// TODO: default object bounds
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -50,7 +50,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
private final NotNullLazyValue<Collection<Name>> enumMemberNames;
|
||||
|
||||
/**
|
||||
* Creates and initializes descriptors for enum entry with the given name and its class object
|
||||
* Creates and initializes descriptors for enum entry with the given name and its default object
|
||||
* @param enumMemberNames needed for fake overrides resolution
|
||||
*/
|
||||
@NotNull
|
||||
@@ -214,7 +214,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull
|
||||
private JetScope getSupertypeScope() {
|
||||
Collection<JetType> supertype = getTypeConstructor().getSupertypes();
|
||||
assert supertype.size() == 1 : "Enum entry and its class object both should have exactly one supertype: " + supertype;
|
||||
assert supertype.size() == 1 : "Enum entry and its default object both should have exactly one supertype: " + supertype;
|
||||
return supertype.iterator().next().getMemberScope();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,13 +53,14 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
.setWithoutTypeParameters(true)
|
||||
.setWithoutFunctionParameterNames(true)
|
||||
.setReceiverAfterName(true)
|
||||
.setRenderClassObjectName(true)
|
||||
.setRenderDefaultObjectName(true)
|
||||
.setWithoutSuperTypes(true)
|
||||
.setStartFromName(true).build();
|
||||
|
||||
DescriptorRenderer FQ_NAMES_IN_TYPES = new DescriptorRendererBuilder().build();
|
||||
|
||||
DescriptorRenderer SHORT_NAMES_IN_TYPES = new DescriptorRendererBuilder().setNameShortness(NameShortness.SHORT).setIncludeSynthesizedParameterNames(false).build();
|
||||
DescriptorRenderer SHORT_NAMES_IN_TYPES = new DescriptorRendererBuilder().setNameShortness(
|
||||
NameShortness.SHORT).setIncludeSynthesizedParameterNames(false).build();
|
||||
|
||||
DescriptorRenderer DEBUG_TEXT = new DescriptorRendererBuilder()
|
||||
.setDebugMode(true)
|
||||
@@ -77,7 +78,7 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
DescriptorRenderer HTML_NAMES_WITH_SHORT_TYPES = new DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setRenderClassObjectName(true)
|
||||
.setRenderDefaultObjectName(true)
|
||||
.setTextFormat(TextFormat.HTML).build();
|
||||
|
||||
DescriptorRenderer HTML = new DescriptorRendererBuilder().setTextFormat(TextFormat.HTML).build();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DescriptorRendererBuilder {
|
||||
@NotNull
|
||||
private Collection<FqName> excludedAnnotationClasses = Collections.emptyList();
|
||||
private boolean receiverAfterName = false;
|
||||
private boolean renderClassObjectName = false;
|
||||
private boolean renderDefaultObjectName = false;
|
||||
|
||||
public DescriptorRendererBuilder() {
|
||||
}
|
||||
@@ -200,8 +200,8 @@ public class DescriptorRendererBuilder {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DescriptorRendererBuilder setRenderClassObjectName(boolean renderClassObjectName) {
|
||||
this.renderClassObjectName = renderClassObjectName;
|
||||
public DescriptorRendererBuilder setRenderDefaultObjectName(boolean renderDefaultObjectName) {
|
||||
this.renderDefaultObjectName = renderDefaultObjectName;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public class DescriptorRendererBuilder {
|
||||
normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName,
|
||||
overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant,
|
||||
includeSynthesizedParameterNames, withoutFunctionParameterNames, withoutTypeParameters, receiverAfterName,
|
||||
renderClassObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues, flexibleTypesForCode);
|
||||
renderDefaultObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues, flexibleTypesForCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
private final boolean includeSynthesizedParameterNames;
|
||||
private final boolean withoutFunctionParameterNames;
|
||||
private final boolean withoutTypeParameters;
|
||||
private final boolean renderClassObjectName;
|
||||
private final boolean renderDefaultObjectName;
|
||||
private final boolean withoutSuperTypes;
|
||||
private final boolean receiverAfterName;
|
||||
private final boolean renderDefaultValues;
|
||||
@@ -100,7 +100,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
boolean withoutFunctionParameterNames,
|
||||
boolean withoutTypeParameters,
|
||||
boolean receiverAfterName,
|
||||
boolean renderClassObjectName,
|
||||
boolean renderDefaultObjectName,
|
||||
boolean withoutSuperTypes,
|
||||
@NotNull Function1<JetType, JetType> typeNormalizer,
|
||||
boolean renderDefaultValues,
|
||||
@@ -127,7 +127,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
this.withoutFunctionParameterNames = withoutFunctionParameterNames;
|
||||
this.withoutTypeParameters = withoutTypeParameters;
|
||||
this.receiverAfterName = receiverAfterName;
|
||||
this.renderClassObjectName = renderClassObjectName;
|
||||
this.renderDefaultObjectName = renderDefaultObjectName;
|
||||
this.withoutSuperTypes = withoutSuperTypes;
|
||||
this.typeNormalizer = typeNormalizer;
|
||||
this.renderDefaultValues = renderDefaultValues;
|
||||
@@ -234,8 +234,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
builder.append(renderName(descriptor.getName()));
|
||||
}
|
||||
|
||||
private void renderClassObjectName(@NotNull DeclarationDescriptor descriptor, @NotNull StringBuilder builder) {
|
||||
if (renderClassObjectName) {
|
||||
private void renderDefaultObjectName(@NotNull DeclarationDescriptor descriptor, @NotNull StringBuilder builder) {
|
||||
if (renderDefaultObjectName) {
|
||||
if (startFromName) {
|
||||
builder.append("class object");
|
||||
}
|
||||
@@ -956,7 +956,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
renderName(klass, builder);
|
||||
}
|
||||
else {
|
||||
renderClassObjectName(klass, builder);
|
||||
renderDefaultObjectName(klass, builder);
|
||||
}
|
||||
|
||||
List<TypeParameterDescriptor> typeParameters = klass.getTypeConstructor().getParameters();
|
||||
|
||||
@@ -191,7 +191,7 @@ public class DescriptorUtils {
|
||||
public static ClassDescriptor getContainingClass(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor containing = descriptor.getContainingDeclaration();
|
||||
while (containing != null) {
|
||||
if (containing instanceof ClassDescriptor && !isClassObject(containing)) {
|
||||
if (containing instanceof ClassDescriptor && !isDefaultObject(containing)) {
|
||||
return (ClassDescriptor) containing;
|
||||
}
|
||||
containing = containing.getContainingDeclaration();
|
||||
@@ -240,7 +240,7 @@ public class DescriptorUtils {
|
||||
return descriptor instanceof AnonymousFunctionDescriptor;
|
||||
}
|
||||
|
||||
public static boolean isClassObject(@Nullable DeclarationDescriptor descriptor) {
|
||||
public static boolean isDefaultObject(@Nullable DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.CLASS_OBJECT);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class EnumValue extends CompileTimeConstant<ClassDescriptor> {
|
||||
@Override
|
||||
public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) {
|
||||
JetType type = value.getClassObjectType();
|
||||
assert type != null : "Enum entry should have a class object: " + value;
|
||||
assert type != null : "Enum entry should have a default object: " + value;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@ import java.lang.reflect.Modifier
|
||||
|
||||
public trait JetScope {
|
||||
|
||||
/**
|
||||
* Should not return object (class object or enum entry) class descriptors.
|
||||
*/
|
||||
public fun getClassifier(name: Name): ClassifierDescriptor?
|
||||
|
||||
public fun getPackage(name: Name): PackageViewDescriptor?
|
||||
|
||||
@@ -52,7 +52,7 @@ message JvmFieldSignature {
|
||||
required int32 name = 1;
|
||||
required JvmType type = 2;
|
||||
|
||||
// True iff this field is a backing field for a class object and is really present as a static
|
||||
// True iff this field is a backing field for a default object and is really present as a static
|
||||
// field in the outer class, not as an instance field here
|
||||
optional bool is_static_in_outer = 3 [default = false];
|
||||
}
|
||||
|
||||
@@ -131,9 +131,9 @@ public class DescriptorSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
ClassDescriptor classObject = classDescriptor.getDefaultObjectDescriptor();
|
||||
if (classObject != null) {
|
||||
builder.setClassObjectName(stringTable.getSimpleNameIndex(classObject.getName()));
|
||||
ClassDescriptor defaultObjectDescriptor = classDescriptor.getDefaultObjectDescriptor();
|
||||
if (defaultObjectDescriptor != null) {
|
||||
builder.setClassObjectName(stringTable.getSimpleNameIndex(defaultObjectDescriptor.getName()));
|
||||
}
|
||||
|
||||
extension.serializeClass(classDescriptor, builder, stringTable);
|
||||
|
||||
+5
-5
@@ -60,7 +60,7 @@ public class DeserializedClassDescriptor(
|
||||
|
||||
private val containingDeclaration = outerContext.containingDeclaration
|
||||
private val primaryConstructor = c.storageManager.createNullableLazyValue { computePrimaryConstructor() }
|
||||
private val classObjectDescriptor = c.storageManager.createNullableLazyValue { computeClassObjectDescriptor() }
|
||||
private val defaultObjectDescriptor = c.storageManager.createNullableLazyValue { computeDefaultObjectDescriptor() }
|
||||
|
||||
private val annotations =
|
||||
if (!Flags.HAS_ANNOTATIONS.get(classProto.getFlags())) {
|
||||
@@ -109,14 +109,14 @@ public class DeserializedClassDescriptor(
|
||||
return listOf(constructor)
|
||||
}
|
||||
|
||||
private fun computeClassObjectDescriptor(): ClassDescriptor? {
|
||||
private fun computeDefaultObjectDescriptor(): ClassDescriptor? {
|
||||
if (!classProto.hasClassObjectName()) return null
|
||||
|
||||
val classObjectName = c.nameResolver.getName(classProto.getClassObjectName())
|
||||
return memberScope.getClassifier(classObjectName) as? ClassDescriptor
|
||||
val defaultObjectName = c.nameResolver.getName(classProto.getClassObjectName())
|
||||
return memberScope.getClassifier(defaultObjectName) as? ClassDescriptor
|
||||
}
|
||||
|
||||
override fun getDefaultObjectDescriptor(): ClassDescriptor? = classObjectDescriptor()
|
||||
override fun getDefaultObjectDescriptor(): ClassDescriptor? = defaultObjectDescriptor()
|
||||
|
||||
private fun computeSuperTypes(): Collection<JetType> {
|
||||
val supertypes = ArrayList<JetType>(classProto.getSupertypeCount())
|
||||
|
||||
@@ -27,7 +27,7 @@ class Example(a : Foo, i : Int) : Bar(i), Some {
|
||||
*/
|
||||
|
||||
memberDeclaration
|
||||
: classObject
|
||||
: defaultObject
|
||||
: object
|
||||
: function
|
||||
: property
|
||||
@@ -40,12 +40,9 @@ anonymousInitializer
|
||||
: block
|
||||
;
|
||||
|
||||
classObject
|
||||
defaultObject
|
||||
: modifiers "class" object
|
||||
;
|
||||
/**
|
||||
See [Class objects](classes.html#class-objects)
|
||||
*/
|
||||
|
||||
valueParameters
|
||||
: "(" functionParameter{","}? ")" // default values
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public class ReferenceVariantsHelper(
|
||||
|
||||
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
|
||||
if (qualifier != null) {
|
||||
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
||||
// It's impossible to add extension function for package or class (if it's default object, expression type is not null)
|
||||
qualifier.scope.getDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter).filterTo(descriptors) { callType.canCall(it) }
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import java.util.HashSet
|
||||
|
||||
public fun JetScope.getImplicitReceiversWithInstance(): List<ReceiverParameterDescriptor> {
|
||||
// we use a set to workaround a bug with receiver for class object present twice in the result of getImplicitReceiversHierarchy()
|
||||
// we use a set to workaround a bug with receiver for default object present twice in the result of getImplicitReceiversHierarchy()
|
||||
val receivers = LinkedHashSet(getImplicitReceiversHierarchy())
|
||||
|
||||
val withInstance = HashSet<DeclarationDescriptor>()
|
||||
|
||||
+9
-9
@@ -66,7 +66,7 @@ private class ClassClsStubBuilder(
|
||||
supertypeIds
|
||||
}
|
||||
}
|
||||
private val classObjectName = if (classProto.hasClassObjectName()) c.nameResolver.getName(classProto.getClassObjectName()) else null
|
||||
private val defaultObjectName = if (classProto.hasClassObjectName()) c.nameResolver.getName(classProto.getClassObjectName()) else null
|
||||
|
||||
private val classOrObjectStub = createClassOrObjectStubAndModifierListStub()
|
||||
|
||||
@@ -100,7 +100,7 @@ private class ClassClsStubBuilder(
|
||||
}
|
||||
|
||||
private fun doCreateClassOrObjectStub(): StubElement<out PsiElement> {
|
||||
val isClassObject = classKind == ProtoBuf.Class.Kind.CLASS_OBJECT
|
||||
val isDefaultObject = classKind == ProtoBuf.Class.Kind.CLASS_OBJECT
|
||||
val fqName = outerContext.containerFqName.child(classId.getRelativeClassName().shortName())
|
||||
val shortName = fqName.shortName()?.ref()
|
||||
val superTypeRefs = supertypeIds.filter {
|
||||
@@ -112,7 +112,7 @@ private class ClassClsStubBuilder(
|
||||
KotlinObjectStubImpl(
|
||||
parentStub, shortName, fqName, superTypeRefs,
|
||||
isTopLevel = !classId.isNestedClass(),
|
||||
isClassObject = isClassObject,
|
||||
isDefault = isDefaultObject,
|
||||
isLocal = false,
|
||||
isObjectLiteral = false
|
||||
)
|
||||
@@ -163,19 +163,19 @@ private class ClassClsStubBuilder(
|
||||
|
||||
private fun createClassBodyAndMemberStubs() {
|
||||
val classBody = KotlinPlaceHolderStubImpl<JetClassBody>(classOrObjectStub, JetStubElementTypes.CLASS_BODY)
|
||||
createClassObjectStub(classBody)
|
||||
createDefaultObjectStub(classBody)
|
||||
createEnumEntryStubs(classBody)
|
||||
createCallableMemberStubs(classBody)
|
||||
createInnerAndNestedClasses(classBody)
|
||||
}
|
||||
|
||||
private fun createClassObjectStub(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
if (classObjectName == null) {
|
||||
private fun createDefaultObjectStub(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
if (defaultObjectName == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val classObjectId = classId.createNestedClassId(classObjectName)
|
||||
createNestedClassStub(classBody, classObjectId)
|
||||
val defaultObjectId = classId.createNestedClassId(defaultObjectName)
|
||||
createNestedClassStub(classBody, defaultObjectId)
|
||||
}
|
||||
|
||||
private fun createEnumEntryStubs(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
@@ -211,7 +211,7 @@ private class ClassClsStubBuilder(
|
||||
private fun createInnerAndNestedClasses(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
classProto.getNestedClassNameList().forEach { id ->
|
||||
val nestedClassName = c.nameResolver.getName(id)
|
||||
if (nestedClassName != classObjectName) {
|
||||
if (nestedClassName != defaultObjectName) {
|
||||
val nestedClassId = classId.createNestedClassId(nestedClassName)
|
||||
createNestedClassStub(classBody, nestedClassId)
|
||||
}
|
||||
|
||||
+1
-1
@@ -210,7 +210,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
}
|
||||
val typeConstraintListStub = KotlinPlaceHolderStubImpl<JetTypeConstraintList>(parent, JetStubElementTypes.TYPE_CONSTRAINT_LIST)
|
||||
for ((name, type) in protosForTypeConstraintList) {
|
||||
val typeConstraintStub = KotlinTypeConstraintStubImpl(typeConstraintListStub, isClassObjectConstraint = false)
|
||||
val typeConstraintStub = KotlinTypeConstraintStubImpl(typeConstraintListStub, isDefaultObjectConstraint = false)
|
||||
KotlinNameReferenceExpressionStubImpl(typeConstraintStub, name.ref())
|
||||
createTypeReferenceStub(typeConstraintStub, type)
|
||||
}
|
||||
|
||||
+4
-4
@@ -146,17 +146,17 @@ private fun buildDecompiledText(packageFqName: FqName, descriptors: List<Declara
|
||||
builder.append(" {\n")
|
||||
var firstPassed = false
|
||||
val subindent = indent + " "
|
||||
val classObject = descriptor.getDefaultObjectDescriptor()
|
||||
if (classObject != null) {
|
||||
val defaultObject = descriptor.getDefaultObjectDescriptor()
|
||||
if (defaultObject != null) {
|
||||
firstPassed = true
|
||||
builder.append(subindent)
|
||||
appendDescriptor(classObject, subindent)
|
||||
appendDescriptor(defaultObject, subindent)
|
||||
}
|
||||
for (member in descriptor.getDefaultType().getMemberScope().getDescriptors()) {
|
||||
if (member.getContainingDeclaration() != descriptor) {
|
||||
continue
|
||||
}
|
||||
if (member == classObject) {
|
||||
if (member == defaultObject) {
|
||||
continue
|
||||
}
|
||||
if (member is CallableMemberDescriptor
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ private object DeclarationKindDetector : JetVisitor<AnnotationHostKind?, Unit?>(
|
||||
override fun visitParameter(d: JetParameter, _: Unit?) = detect(d, "parameter", newLineNeeded = false)
|
||||
|
||||
override fun visitObjectDeclaration(d: JetObjectDeclaration, _: Unit?): AnnotationHostKind? {
|
||||
if (d.isClassObject()) return detect(d, "class object", name = "${d.getName()} of ${d.getStrictParentOfType<JetClass>()?.getName()}")
|
||||
if (d.isDefault()) return detect(d, "class object", name = "${d.getName()} of ${d.getStrictParentOfType<JetClass>()?.getName()}")
|
||||
if (d.getParent() is JetObjectLiteralExpression) return null
|
||||
return detect(d, "object")
|
||||
}
|
||||
|
||||
@@ -36,14 +36,14 @@ import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
// Navigation element of the resolved reference
|
||||
// For property accessor return enclosing property
|
||||
// For class object return enclosing class
|
||||
// For default object return enclosing class
|
||||
public val PsiReference.unwrappedTargets: Set<PsiElement>
|
||||
get() {
|
||||
fun PsiElement.adjust(): PsiElement? {
|
||||
val target = unwrapped?.getOriginalElement()
|
||||
return when {
|
||||
target is JetPropertyAccessor -> target.getNonStrictParentOfType<JetProperty>()
|
||||
target is JetObjectDeclaration && target.isClassObject() -> target.getNonStrictParentOfType<JetClass>()
|
||||
target is JetObjectDeclaration && target.isDefault() -> target.getNonStrictParentOfType<JetClass>()
|
||||
else -> target
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
PsiElement elementAtCaret = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(elementAtCaret, JetClassOrObject.class);
|
||||
|
||||
assert classOrObject != null : "ClassObject should be checked in isValidFor method";
|
||||
assert classOrObject != null;
|
||||
|
||||
Set<CallableMemberDescriptor> missingImplementations = collectMethodsToGenerate(classOrObject);
|
||||
if (missingImplementations.isEmpty() && !implementAll) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
|
||||
|
||||
@Override
|
||||
public void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration) {
|
||||
if (declaration.isClassObject()) {
|
||||
if (declaration.isDefault()) {
|
||||
memberSuspects.add(declaration.getClassKeyword());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ private class JetDeclarationRemotenessWeigher(private val file: JetFile) : Looku
|
||||
}
|
||||
|
||||
val qualifiedName = qualifiedName(o)
|
||||
// Invalid name can be met for class object descriptor: Test.MyTest.A.<no name provided>.testOther
|
||||
// Invalid name can be met for default object descriptor: Test.MyTest.A.<no name provided>.testOther
|
||||
if (qualifiedName != null && isValidJavaFqName(qualifiedName)) {
|
||||
val importPath = ImportPath(qualifiedName)
|
||||
val fqName = importPath.fqnPart()
|
||||
|
||||
@@ -223,7 +223,7 @@ class SmartCompletion(
|
||||
val typeParameter = type.type.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor ?: return false
|
||||
if (!type.freeParameters.contains(typeParameter)) return false
|
||||
return KotlinBuiltIns.isAnyOrNullableAny(typeParameter.getUpperBoundsAsType())
|
||||
//TODO: check for class object constraint when there will be supported
|
||||
//TODO: check for default object constraint when they are supported
|
||||
}
|
||||
|
||||
private fun calcExpectedInfos(expression: JetExpression): Collection<ExpectedInfo>? {
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.idea.completion.isVisible
|
||||
import org.jetbrains.kotlin.idea.completion.ExpectedInfo
|
||||
|
||||
// adds java static members, enum members and members from class object
|
||||
// adds java static members, enum members and members from default object
|
||||
class StaticMembers(
|
||||
val bindingContext: BindingContext,
|
||||
val resolutionFacade: ResolutionFacade,
|
||||
@@ -85,9 +85,9 @@ class StaticMembers(
|
||||
|
||||
classDescriptor.getStaticScope().getAllDescriptors().forEach(::processMember)
|
||||
|
||||
val classObject = classDescriptor.getDefaultObjectDescriptor()
|
||||
if (classObject != null) {
|
||||
classObject.getDefaultType().getMemberScope().getAllDescriptors()
|
||||
val defaultObject = classDescriptor.getDefaultObjectDescriptor()
|
||||
if (defaultObject != null) {
|
||||
defaultObject.getDefaultType().getMemberScope().getAllDescriptors()
|
||||
.filter { !it.isExtension }
|
||||
.forEach(::processMember)
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Posi
|
||||
element is JetClassInitializer -> {
|
||||
val parent = getElementToCalculateClassName(element.getParent())
|
||||
// Class-object initializer
|
||||
if (parent is JetObjectDeclaration && parent.isClassObject()) {
|
||||
if (parent is JetObjectDeclaration && parent.isDefault()) {
|
||||
return getClassNameForElement(parent.getParent(), typeMapper, file, isInLibrary)
|
||||
}
|
||||
return getClassNameForElement(element, typeMapper, file, isInLibrary)
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ public class KotlinCallHierarchyNodeDescriptor extends HierarchyNodeDescriptor i
|
||||
if (descriptor == null) return null;
|
||||
|
||||
if (element instanceof JetClassOrObject) {
|
||||
if (element instanceof JetObjectDeclaration && ((JetObjectDeclaration) element).isClassObject()) {
|
||||
if (element instanceof JetObjectDeclaration && ((JetObjectDeclaration) element).isDefault()) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
if (!(descriptor instanceof ClassDescriptor)) return null;
|
||||
|
||||
|
||||
@@ -126,8 +126,8 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
if (declaration is JetProperty && declaration.isLocal()) return
|
||||
if (declaration is JetParameter && (declaration.getParent()?.getParent() !is JetClass || !declaration.hasValOrVarNode())) return
|
||||
if (declaration is JetNamedFunction && isConventionalName(declaration)) return
|
||||
//TODO: support this inspection for class objects
|
||||
if (declaration is JetObjectDeclaration && declaration.isClassObject()) return
|
||||
//TODO: support this inspection for default objects
|
||||
if (declaration is JetObjectDeclaration && declaration.isDefault()) return
|
||||
|
||||
// More expensive, resolve-based checks
|
||||
if (isEntryPoint(declaration)) return
|
||||
|
||||
+1
-1
@@ -851,7 +851,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
is ConstructorInfo -> with(callableInfo.classInfo) {
|
||||
!inner && kind != ClassKind.ENUM_ENTRY && kind != ClassKind.ENUM_CLASS
|
||||
}
|
||||
else -> callableInfo.receiverTypeInfo.classObjectRequired
|
||||
else -> callableInfo.receiverTypeInfo.staticContextRequired
|
||||
}
|
||||
modifierList.setModifierProperty(PsiModifier.STATIC, needStatic)
|
||||
|
||||
|
||||
+3
-3
@@ -75,12 +75,12 @@ abstract class TypeInfo(val variance: Variance) {
|
||||
override val substitutionsAllowed: Boolean = false
|
||||
}
|
||||
|
||||
class ClassObjectRequired(delegate: TypeInfo): DelegatingTypeInfo(delegate) {
|
||||
override val classObjectRequired: Boolean = true
|
||||
class StaticContextRequired(delegate: TypeInfo): DelegatingTypeInfo(delegate) {
|
||||
override val staticContextRequired: Boolean = true
|
||||
}
|
||||
|
||||
open val substitutionsAllowed: Boolean = true
|
||||
open val classObjectRequired: Boolean = false
|
||||
open val staticContextRequired: Boolean = false
|
||||
open val possibleNamesFromExpression: Array<String> get() = ArrayUtil.EMPTY_STRING_ARRAY
|
||||
abstract fun getPossibleTypes(builder: CallableBuilder): List<JetType>
|
||||
|
||||
|
||||
+4
-4
@@ -79,8 +79,8 @@ public class CreateCallableFromUsageFix(
|
||||
val receiverInfo = callableInfo.receiverTypeInfo
|
||||
|
||||
if (receiverInfo is TypeInfo.Empty) return !isExtension
|
||||
// TODO: Remove after class object extensions are supported
|
||||
if (isExtension && receiverInfo.classObjectRequired) return false
|
||||
// TODO: Remove after default object extensions are supported
|
||||
if (isExtension && receiverInfo.staticContextRequired) return false
|
||||
|
||||
val file = element.getContainingFile() as JetFile
|
||||
val project = file.getProject()
|
||||
@@ -93,9 +93,9 @@ public class CreateCallableFromUsageFix(
|
||||
val declaration = getDeclarationIfApplicable(project, it)
|
||||
val insertToJavaInterface = declaration is PsiClass && declaration.isInterface()
|
||||
when {
|
||||
propertyInfo != null && insertToJavaInterface && (!receiverInfo.classObjectRequired || propertyInfo.writable) ->
|
||||
propertyInfo != null && insertToJavaInterface && (!receiverInfo.staticContextRequired || propertyInfo.writable) ->
|
||||
false
|
||||
isFunction && insertToJavaInterface && receiverInfo.classObjectRequired ->
|
||||
isFunction && insertToJavaInterface && receiverInfo.staticContextRequired ->
|
||||
false
|
||||
else ->
|
||||
declaration != null
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user