Removed accessors for const properties
This commit is contained in:
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.load.java.JavaVisibilities;
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap;
|
||||
import org.jetbrains.kotlin.resolve.DeprecationUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||
@@ -298,9 +299,6 @@ public class AsmUtil {
|
||||
|
||||
public static int getDeprecatedAccessFlag(@NotNull MemberDescriptor descriptor) {
|
||||
if (descriptor instanceof PropertyAccessorDescriptor) {
|
||||
if (((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty().isConst()) {
|
||||
return ACC_DEPRECATED;
|
||||
}
|
||||
return KotlinBuiltIns.isDeprecated(descriptor)
|
||||
? ACC_DEPRECATED
|
||||
: getDeprecatedAccessFlag(((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty());
|
||||
@@ -680,14 +678,8 @@ public class AsmUtil {
|
||||
}
|
||||
|
||||
public static boolean isInstancePropertyWithStaticBackingField(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
if (propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DeclarationDescriptor container = propertyDescriptor.getContainingDeclaration();
|
||||
return isNonCompanionObject(container) ||
|
||||
isPropertyWithBackingFieldInOuterClass(propertyDescriptor) ||
|
||||
(isCompanionObject(container) && isInterface(container.getContainingDeclaration()));
|
||||
return propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE &&
|
||||
isObject(propertyDescriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
public static boolean isPropertyWithBackingFieldInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
@@ -727,7 +719,9 @@ public class AsmUtil {
|
||||
}
|
||||
|
||||
public static boolean isCompanionObjectWithBackingFieldsInOuter(@NotNull DeclarationDescriptor companionObject) {
|
||||
return isCompanionObject(companionObject) && isClassOrEnumClass(companionObject.getContainingDeclaration());
|
||||
return isCompanionObject(companionObject) &&
|
||||
isClassOrEnumClass(companionObject.getContainingDeclaration()) &&
|
||||
!JavaToKotlinClassMap.INSTANCE.isMappedCompanion((ClassDescriptor) companionObject);
|
||||
}
|
||||
|
||||
private static boolean areBothAccessorDefault(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
|
||||
@@ -92,15 +92,13 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isInt;
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.couldUseDirectAccessToProperty;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isJvmInterface;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContextUtils.*;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isObject;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.annotations.AnnotationUtilKt.hasJvmFieldAnnotation;
|
||||
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression;
|
||||
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
@@ -2168,7 +2166,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
propertyDescriptor = context.accessibleDescriptor(propertyDescriptor, superCallTarget);
|
||||
|
||||
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
||||
if (getter != null && !hasJvmFieldAnnotation(propertyDescriptor)) {
|
||||
if (getter != null && !isConstOrHasJvmFieldAnnotation(propertyDescriptor)) {
|
||||
callableGetter = typeMapper.mapToCallableMethod(getter, isSuper);
|
||||
}
|
||||
}
|
||||
@@ -2177,7 +2175,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
|
||||
if (setter != null &&
|
||||
!couldUseDirectAccessToProperty(propertyDescriptor, false, isDelegatedProperty, context) &&
|
||||
!hasJvmFieldAnnotation(propertyDescriptor)) {
|
||||
!isConstOrHasJvmFieldAnnotation(propertyDescriptor)) {
|
||||
callableSetter = typeMapper.mapToCallableMethod(setter, isSuper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import java.io.File;
|
||||
|
||||
import static org.jetbrains.kotlin.descriptors.Modality.ABSTRACT;
|
||||
import static org.jetbrains.kotlin.descriptors.Modality.FINAL;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.annotations.AnnotationUtilKt.hasJvmFieldAnnotation;
|
||||
|
||||
public class JvmCodegenUtil {
|
||||
|
||||
@@ -130,6 +131,10 @@ public class JvmCodegenUtil {
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean isConstOrHasJvmFieldAnnotation(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return propertyDescriptor.isConst() || hasJvmFieldAnnotation(propertyDescriptor);
|
||||
}
|
||||
|
||||
public static boolean couldUseDirectAccessToProperty(
|
||||
@NotNull PropertyDescriptor property,
|
||||
boolean forGetter,
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isConstOrHasJvmFieldAnnotation;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isJvmInterface;
|
||||
import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.*;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
||||
@@ -155,7 +156,7 @@ public class PropertyCodegen {
|
||||
@NotNull PropertyDescriptor descriptor,
|
||||
@Nullable KtPropertyAccessor accessor
|
||||
) {
|
||||
if (hasJvmFieldAnnotation(descriptor)) return false;
|
||||
if (isConstOrHasJvmFieldAnnotation(descriptor)) return false;
|
||||
|
||||
boolean isDefaultAccessor = accessor == null || !accessor.hasBody();
|
||||
|
||||
|
||||
Vendored
-6
@@ -8,12 +8,6 @@ public interface TraitClassObjectField {
|
||||
public static final java.lang.String x = "";
|
||||
private static final java.lang.String y = "";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public final java.lang.String getX() { /* compiled code */ }
|
||||
|
||||
private final java.lang.String getY() { /* compiled code */ }
|
||||
|
||||
private Companion() { /* compiled code */ }
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
val packageResult = packageInline { it + "K" }
|
||||
if (packageResult != "OK") return "package inline fail: $packageResult"
|
||||
|
||||
val samePackageResult = samePackageCall()
|
||||
if (samePackageResult != "OK") return "same package inline fail: $samePackageResult"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
private const val packageProp = "O"
|
||||
|
||||
internal inline fun packageInline(p: (String) -> String): String {
|
||||
return p(packageProp)
|
||||
}
|
||||
|
||||
internal fun samePackageCall(): String {
|
||||
return packageInline { it + "K"}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
const val CONST_VAL = 1
|
||||
|
||||
object A {
|
||||
const val CONST_VAL = 2
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object {
|
||||
const val CONST_VAL = 2
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
3 DEPRECATED are for getCONST_VAL
|
||||
*/
|
||||
|
||||
// 3 DEPRECATED
|
||||
@@ -101,12 +101,6 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("constValsGetterDeprecated.kt")
|
||||
public void testConstValsGetterDeprecated() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constValsGetterDeprecated.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("falseSmartCast.kt")
|
||||
public void testFalseSmartCast() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/falseSmartCast.kt");
|
||||
|
||||
+6
@@ -1645,6 +1645,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/syntheticAccessors"), Pattern.compile("^(.+)\\.1.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("constField.1.kt")
|
||||
public void testConstField() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/syntheticAccessors/constField.1.kt");
|
||||
doTestMultiFileWithInlineCheck(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("packagePrivateMembers.1.kt")
|
||||
public void testPackagePrivateMembers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/syntheticAccessors/packagePrivateMembers.1.kt");
|
||||
|
||||
+6
@@ -1645,6 +1645,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/syntheticAccessors"), Pattern.compile("^(.+)\\.1.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("constField.1.kt")
|
||||
public void testConstField() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/syntheticAccessors/constField.1.kt");
|
||||
doBoxTestWithInlineCheck(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("packagePrivateMembers.1.kt")
|
||||
public void testPackagePrivateMembers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/syntheticAccessors/packagePrivateMembers.1.kt");
|
||||
|
||||
+6
-1
@@ -42,6 +42,7 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap {
|
||||
|
||||
private final Map<ClassDescriptor, ClassDescriptor> mutableToReadOnly = new HashMap<ClassDescriptor, ClassDescriptor>();
|
||||
private final Map<ClassDescriptor, ClassDescriptor> readOnlyToMutable = new HashMap<ClassDescriptor, ClassDescriptor>();
|
||||
private final CompanionObjectMapping companionObjectMapping;
|
||||
|
||||
private JavaToKotlinClassMap() {
|
||||
KotlinBuiltIns builtIns = JvmBuiltIns.getInstance();
|
||||
@@ -69,7 +70,7 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap {
|
||||
add(ClassId.topLevel(jvmType.getWrapperFqName()), builtIns.getPrimitiveClassDescriptor(jvmType.getPrimitiveType()));
|
||||
}
|
||||
|
||||
CompanionObjectMapping companionObjectMapping = new CompanionObjectMapping(builtIns);
|
||||
companionObjectMapping = new CompanionObjectMapping(builtIns);
|
||||
for (ClassDescriptor descriptor : companionObjectMapping.allClassesWithIntrinsicCompanions()) {
|
||||
ClassDescriptor companion = descriptor.getCompanionObjectDescriptor();
|
||||
assert companion != null : "No companion object found for " + descriptor;
|
||||
@@ -118,6 +119,10 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap {
|
||||
return kotlinToJava.get(kotlinFqName);
|
||||
}
|
||||
|
||||
public boolean isMappedCompanion(@NotNull ClassDescriptor descriptor) {
|
||||
return companionObjectMapping.hasMappingToObject(descriptor);
|
||||
}
|
||||
|
||||
private void add(
|
||||
@NotNull Class<?> javaClass,
|
||||
@NotNull ClassDescriptor kotlinDescriptor,
|
||||
|
||||
Reference in New Issue
Block a user