Don't generate unnecessary accessors for private class properties
This commit is contained in:
@@ -2936,6 +2936,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest("compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/objectExpressionInConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("privateClassPropertyNoClash.kt")
|
||||
public void testPrivateClassPropertyNoClash() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/privateClassPropertyNoClash.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevel.kt")
|
||||
public void testTopLevel() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/duplicateJvmSignature/functionAndProperty/topLevel.kt");
|
||||
|
||||
@@ -96,12 +96,20 @@ public class CodegenTestUtil {
|
||||
|
||||
@NotNull
|
||||
public static Method findDeclaredMethodByName(@NotNull Class<?> aClass, @NotNull String name) {
|
||||
Method result = findDeclaredMethodByNameOrNull(aClass, name);
|
||||
if (result == null) {
|
||||
throw new AssertionError("Method " + name + " is not found in " + aClass);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Method findDeclaredMethodByNameOrNull(@NotNull Class<?> aClass, @NotNull String name) {
|
||||
for (Method method : aClass.getDeclaredMethods()) {
|
||||
if (method.getName().equals(name)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Method " + name + " is not found in class " + aClass);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void assertIsCurrentTime(long returnValue) {
|
||||
|
||||
@@ -18,12 +18,12 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.assertIsCurrentTime;
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.findDeclaredMethodByName;
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.*;
|
||||
|
||||
public class PropertyGenTest extends CodegenTestCase {
|
||||
@Override
|
||||
@@ -236,4 +236,21 @@ public class PropertyGenTest extends CodegenTestCase {
|
||||
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testPrivateClassPropertyAccessors() throws Exception {
|
||||
loadFile("properties/privateClassPropertyAccessors.kt");
|
||||
Class<?> c = generateClass("C");
|
||||
findDeclaredMethodByName(c, "getValWithGet");
|
||||
findDeclaredMethodByName(c, "getVarWithGetSet");
|
||||
findDeclaredMethodByName(c, "setVarWithGetSet");
|
||||
findDeclaredMethodByName(c, "getDelegated");
|
||||
findDeclaredMethodByName(c, "setDelegated");
|
||||
findDeclaredMethodByName(c, "getExtension");
|
||||
findDeclaredMethodByName(c, "setExtension");
|
||||
|
||||
findDeclaredMethodByName(initializedClassLoader.loadClass("C" + JvmAbi.CLASS_OBJECT_SUFFIX), "getClassObjectVal");
|
||||
|
||||
assertNull("Property should not have a getter", findDeclaredMethodByNameOrNull(c, "getVarNoAccessors"));
|
||||
assertNull("Property should not have a setter", findDeclaredMethodByNameOrNull(c, "setVarNoAccessors"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4501,6 +4501,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("privatePropertyInConstructor.kt")
|
||||
public void testPrivatePropertyInConstructor() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("privatePropertyWithoutBackingField.kt")
|
||||
public void testPrivatePropertyWithoutBackingField() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/properties/privatePropertyWithoutBackingField.kt");
|
||||
|
||||
Reference in New Issue
Block a user