Deprecate non-const properties copies in interface
This commit is contained in:
@@ -786,10 +786,13 @@ public class AsmUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPropertyWithBackingFieldCopyInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
|
public static boolean isPropertyWithBackingFieldCopyInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
|
boolean isExtensionProperty = propertyDescriptor.getExtensionReceiverParameter() != null;
|
||||||
DeclarationDescriptor propertyContainer = propertyDescriptor.getContainingDeclaration();
|
DeclarationDescriptor propertyContainer = propertyDescriptor.getContainingDeclaration();
|
||||||
return propertyDescriptor.isConst()
|
return !propertyDescriptor.isVar()
|
||||||
&& isInterfaceCompanionObject(propertyContainer)
|
&& !isExtensionProperty
|
||||||
&& propertyDescriptor.getVisibility() == Visibilities.PUBLIC;
|
&& isCompanionObject(propertyContainer) && isInterface(propertyContainer.getContainingDeclaration())
|
||||||
|
&& areBothAccessorDefault(propertyDescriptor)
|
||||||
|
&& getVisibilityForSpecialPropertyBackingField(propertyDescriptor, false) == ACC_PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCompanionObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor companionObject) {
|
public static boolean isCompanionObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor companionObject) {
|
||||||
|
|||||||
@@ -1024,8 +1024,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
PropertyDescriptor property = info.descriptor;
|
PropertyDescriptor property = info.descriptor;
|
||||||
|
|
||||||
Type type = typeMapper.mapType(property);
|
Type type = typeMapper.mapType(property);
|
||||||
|
int modifiers = ACC_STATIC | ACC_FINAL | ACC_PUBLIC | (property.isConst() ? 0 : ACC_DEPRECATED);
|
||||||
FieldVisitor fv = v.newField(Synthetic(DescriptorToSourceUtils.descriptorToDeclaration(property), property),
|
FieldVisitor fv = v.newField(Synthetic(DescriptorToSourceUtils.descriptorToDeclaration(property), property),
|
||||||
ACC_STATIC | ACC_FINAL | ACC_PUBLIC, context.getFieldName(property, false),
|
modifiers, context.getFieldName(property, false),
|
||||||
type.getDescriptor(), typeMapper.mapFieldSignature(property.getType()),
|
type.getDescriptor(), typeMapper.mapFieldSignature(property.getType()),
|
||||||
info.defaultValue);
|
info.defaultValue);
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -8,8 +8,11 @@ class Test {
|
|||||||
s = Trait.NAME;
|
s = Trait.NAME;
|
||||||
if (!s.equals("Trait")) throw new AssertionError("Fail interface: " + s);
|
if (!s.equals("Trait")) throw new AssertionError("Fail interface: " + s);
|
||||||
|
|
||||||
|
s = Trait.DEPRECATED;
|
||||||
|
if (!s.equals("DEPRECATED")) throw new AssertionError("Fail interface: " + s);
|
||||||
|
|
||||||
s = Enoom.NAME;
|
s = Enoom.NAME;
|
||||||
if (!s.equals("Enoom")) throw new AssertionError("Fail enum: " + s);
|
if (!s.equals("Enum")) throw new AssertionError("Fail enum: " + s);
|
||||||
|
|
||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-1
@@ -7,13 +7,14 @@ class Klass {
|
|||||||
interface Trait {
|
interface Trait {
|
||||||
companion object {
|
companion object {
|
||||||
const val NAME = "Trait"
|
const val NAME = "Trait"
|
||||||
|
val DEPRECATED = "DEPRECATED"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Enoom {
|
enum class Enoom {
|
||||||
;
|
;
|
||||||
companion object {
|
companion object {
|
||||||
const val NAME = "Enoom"
|
const val NAME = "Enum"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ interface Test {
|
|||||||
|
|
||||||
// TESTED_OBJECT_KIND: property
|
// TESTED_OBJECT_KIND: property
|
||||||
// TESTED_OBJECTS: Test, prop
|
// TESTED_OBJECTS: Test, prop
|
||||||
// ABSENT: TRUE
|
// FLAGS: ACC_PUBLIC, ACC_FINAL, ACC_STATIC
|
||||||
|
|
||||||
// TESTED_OBJECT_KIND: property
|
// TESTED_OBJECT_KIND: property
|
||||||
// TESTED_OBJECTS: Test$Companion, prop
|
// TESTED_OBJECTS: Test$Companion, prop
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ interface Test {
|
|||||||
|
|
||||||
// TESTED_OBJECT_KIND: property
|
// TESTED_OBJECT_KIND: property
|
||||||
// TESTED_OBJECTS: Test, prop
|
// TESTED_OBJECTS: Test, prop
|
||||||
// ABSENT: TRUE
|
// FLAGS: ACC_PUBLIC, ACC_FINAL, ACC_STATIC, ACC_DEPRECATED
|
||||||
|
|
||||||
// TESTED_OBJECT_KIND: property
|
// TESTED_OBJECT_KIND: property
|
||||||
// TESTED_OBJECTS: Test$Companion, prop
|
// TESTED_OBJECTS: Test$Companion, prop
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ interface Test {
|
|||||||
|
|
||||||
// TESTED_OBJECT_KIND: property
|
// TESTED_OBJECT_KIND: property
|
||||||
// TESTED_OBJECTS: Test, prop
|
// TESTED_OBJECTS: Test, prop
|
||||||
// ABSENT: TRUE
|
// FLAGS: ACC_PUBLIC, ACC_FINAL, ACC_STATIC, ACC_DEPRECATED
|
||||||
|
|
||||||
// TESTED_OBJECT_KIND: property
|
// TESTED_OBJECT_KIND: property
|
||||||
// TESTED_OBJECTS: Test$Companion, prop
|
// TESTED_OBJECTS: Test$Companion, prop
|
||||||
|
|||||||
Reference in New Issue
Block a user