Convert SyntheticMethodForAnnotatedPropertyGenTest to a box test
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
// !LANGUAGE: +UseGetterNameForPropertyAnnotationsMethodOnJvm
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// FULL_JDK
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
annotation class Anno(val value: String)
|
||||||
|
|
||||||
|
class A {
|
||||||
|
@Anno("OK") val property: Int
|
||||||
|
get() = 42
|
||||||
|
}
|
||||||
|
|
||||||
|
interface T {
|
||||||
|
@Anno("OK") val property: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
@Anno("OK") val property: Int
|
||||||
|
get() = 42
|
||||||
|
|
||||||
|
fun check(clazz: Class<*>, expected: Boolean = true) {
|
||||||
|
for (method in clazz.getDeclaredMethods()) {
|
||||||
|
if (method.getName() == "getProperty\$annotations") {
|
||||||
|
if (!expected) {
|
||||||
|
fail("Synthetic method for annotated property found, but not expected: $method")
|
||||||
|
}
|
||||||
|
assertTrue(method.isSynthetic())
|
||||||
|
assertTrue(Modifier.isStatic(method.modifiers))
|
||||||
|
assertTrue(Modifier.isPublic(method.modifiers))
|
||||||
|
assertEquals("[@Anno(value=OK)]", method.declaredAnnotations.toList().toString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (expected) {
|
||||||
|
fail("Synthetic method for annotated property expected, but not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
check(Class.forName("A"))
|
||||||
|
check(Class.forName("SyntheticMethodForPropertyKt"))
|
||||||
|
check(Class.forName("T"), expected = false)
|
||||||
|
check(Class.forName("T\$DefaultImpls"))
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class SomeAnnotation(val value: String)
|
|
||||||
|
|
||||||
class A {
|
|
||||||
@SomeAnnotation("OK") val property: Int
|
|
||||||
get() = 42
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class SomeAnnotation(val value: String)
|
|
||||||
|
|
||||||
interface T {
|
|
||||||
@SomeAnnotation("OK") val property: Int
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
annotation class SomeAnnotation(val value: String)
|
|
||||||
|
|
||||||
@SomeAnnotation("OK") val property: Int
|
|
||||||
get() = 42
|
|
||||||
@@ -383,11 +383,6 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
protected GeneratedClassLoader generateAndCreateClassLoader() {
|
|
||||||
return generateAndCreateClassLoader(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected GeneratedClassLoader generateAndCreateClassLoader(boolean reportProblems) {
|
protected GeneratedClassLoader generateAndCreateClassLoader(boolean reportProblems) {
|
||||||
if (initializedClassLoader != null) {
|
if (initializedClassLoader != null) {
|
||||||
|
|||||||
+5
@@ -181,6 +181,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("syntheticMethodForProperty.kt")
|
||||||
|
public void testSyntheticMethodForProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("typeAnnotationOnJdk6.kt")
|
@TestMetadata("typeAnnotationOnJdk6.kt")
|
||||||
public void testTypeAnnotationOnJdk6() throws Exception {
|
public void testTypeAnnotationOnJdk6() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
||||||
|
|||||||
+5
@@ -186,6 +186,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("syntheticMethodForProperty.kt")
|
||||||
|
public void testSyntheticMethodForProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("typeAnnotationOnJdk6.kt")
|
@TestMetadata("typeAnnotationOnJdk6.kt")
|
||||||
public void testTypeAnnotationOnJdk6() throws Exception {
|
public void testTypeAnnotationOnJdk6() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
||||||
|
|||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.codegen;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase {
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected String getPrefix() {
|
|
||||||
return "properties/syntheticMethod";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String TEST_SYNTHETIC_METHOD_NAME = JvmAbi.getSyntheticMethodNameForAnnotatedProperty("property");
|
|
||||||
|
|
||||||
public void testInClass() {
|
|
||||||
loadFile();
|
|
||||||
assertAnnotatedSyntheticMethodExistence(true, generateClass("A"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testTopLevel() {
|
|
||||||
loadFile();
|
|
||||||
Class<?> a = generateClass("TopLevelKt");
|
|
||||||
assertAnnotatedSyntheticMethodExistence(true, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInTrait() throws ClassNotFoundException {
|
|
||||||
loadFile();
|
|
||||||
GeneratedClassLoader loader = generateAndCreateClassLoader();
|
|
||||||
assertAnnotatedSyntheticMethodExistence(false, loader.loadClass("T"));
|
|
||||||
assertAnnotatedSyntheticMethodExistence(true, loader.loadClass("T" + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void assertAnnotatedSyntheticMethodExistence(boolean expected, @NotNull Class<?> clazz) {
|
|
||||||
for (Method method : clazz.getDeclaredMethods()) {
|
|
||||||
if (TEST_SYNTHETIC_METHOD_NAME.equals(method.getName())) {
|
|
||||||
if (!expected) {
|
|
||||||
fail("Synthetic method for annotated property found, but not expected: " + method);
|
|
||||||
}
|
|
||||||
assertTrue(method.isSynthetic());
|
|
||||||
int modifiers = method.getModifiers();
|
|
||||||
assertTrue(Modifier.isStatic(modifiers));
|
|
||||||
assertTrue(Modifier.isPublic(modifiers));
|
|
||||||
|
|
||||||
Annotation[] annotations = method.getDeclaredAnnotations();
|
|
||||||
assertSize(1, annotations);
|
|
||||||
assertEquals("@SomeAnnotation(value=OK)", annotations[0].toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (expected) {
|
|
||||||
fail("Synthetic method for annotated property expected, but not found: " + TEST_SYNTHETIC_METHOD_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
@@ -181,6 +181,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("syntheticMethodForProperty.kt")
|
||||||
|
public void testSyntheticMethodForProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("typeAnnotationOnJdk6.kt")
|
@TestMetadata("typeAnnotationOnJdk6.kt")
|
||||||
public void testTypeAnnotationOnJdk6() throws Exception {
|
public void testTypeAnnotationOnJdk6() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
||||||
|
|||||||
+5
@@ -181,6 +181,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("syntheticMethodForProperty.kt")
|
||||||
|
public void testSyntheticMethodForProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("typeAnnotationOnJdk6.kt")
|
@TestMetadata("typeAnnotationOnJdk6.kt")
|
||||||
public void testTypeAnnotationOnJdk6() throws Exception {
|
public void testTypeAnnotationOnJdk6() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user