From 6269cb807b8efceb607875019d9e35c498f947f0 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 15 Oct 2013 21:23:14 +0400 Subject: [PATCH] Minor, extract test for synthetic methods for properties --- .../inClass.kt} | 0 .../topLevel.kt} | 0 .../jet/codegen/PropertyGenTest.java | 43 ---------- ...eticMethodForAnnotatedPropertyGenTest.java | 80 +++++++++++++++++++ 4 files changed, 80 insertions(+), 43 deletions(-) rename compiler/testData/codegen/properties/{annotatedClassPropertyNoField.kt => syntheticMethod/inClass.kt} (100%) rename compiler/testData/codegen/properties/{annotatedPackagePropertyNoField.kt => syntheticMethod/topLevel.kt} (100%) create mode 100644 compiler/tests/org/jetbrains/jet/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java diff --git a/compiler/testData/codegen/properties/annotatedClassPropertyNoField.kt b/compiler/testData/codegen/properties/syntheticMethod/inClass.kt similarity index 100% rename from compiler/testData/codegen/properties/annotatedClassPropertyNoField.kt rename to compiler/testData/codegen/properties/syntheticMethod/inClass.kt diff --git a/compiler/testData/codegen/properties/annotatedPackagePropertyNoField.kt b/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt similarity index 100% rename from compiler/testData/codegen/properties/annotatedPackagePropertyNoField.kt rename to compiler/testData/codegen/properties/syntheticMethod/topLevel.kt diff --git a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java index 2790ba90913..bc4b5bc329c 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java @@ -19,12 +19,7 @@ package org.jetbrains.jet.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Opcodes; import org.jetbrains.jet.ConfigurationKind; -import org.jetbrains.jet.lang.resolve.java.JvmAbi; -import org.jetbrains.jet.lang.resolve.java.PackageClassUtils; -import org.jetbrains.jet.lang.resolve.name.FqName; -import org.jetbrains.jet.lang.resolve.name.Name; -import java.lang.annotation.Annotation; import java.lang.reflect.*; import static org.jetbrains.jet.codegen.CodegenTestUtil.assertIsCurrentTime; @@ -264,42 +259,4 @@ public class PropertyGenTest extends CodegenTestCase { throw new RuntimeException(e); } } - - private static final String TEST_SYNTHETIC_METHOD_NAME = - JvmAbi.getSyntheticMethodSignatureForAnnotatedProperty(Name.identifier("property"), null).getName(); - - public void testAnnotatedClassPropertyNoField() { - loadFile("properties/annotatedClassPropertyNoField.kt"); - assertClassHasAnnotatedSyntheticMethod(generateClass("A")); - } - - public void testAnnotatedPackagePropertyNoField() { - loadFile("properties/annotatedPackagePropertyNoField.kt"); - String packageClassName = PackageClassUtils.getPackageClassName(FqName.ROOT); - for (String fileName : generateClassesInFile().files()) { - if (fileName.startsWith(packageClassName) && !fileName.equals(packageClassName + ".class")) { - // This should be package$src class - Class a = generateClass(fileName.substring(0, fileName.length() - ".class".length())); - assertClassHasAnnotatedSyntheticMethod(a); - } - } - } - - private static void assertClassHasAnnotatedSyntheticMethod(@NotNull Class a) { - for (Method method : a.getDeclaredMethods()) { - if (TEST_SYNTHETIC_METHOD_NAME.equals(method.getName())) { - assertTrue(method.isSynthetic()); - int modifiers = method.getModifiers(); - assertTrue(Modifier.isFinal(modifiers)); - assertTrue(Modifier.isStatic(modifiers)); - assertTrue(Modifier.isPrivate(modifiers)); - - Annotation[] annotations = method.getDeclaredAnnotations(); - assertSize(1, annotations); - assertEquals("@SomeAnnotation(value=OK)", annotations[0].toString()); - return; - } - } - fail("Synthetic method for annotated property not found: " + TEST_SYNTHETIC_METHOD_NAME); - } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java new file mode 100644 index 00000000000..11c441c87f6 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2010-2013 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.jet.codegen; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.ConfigurationKind; +import org.jetbrains.jet.lang.resolve.java.JvmAbi; +import org.jetbrains.jet.lang.resolve.java.PackageClassUtils; +import org.jetbrains.jet.lang.resolve.name.FqName; +import org.jetbrains.jet.lang.resolve.name.Name; + +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.getSyntheticMethodSignatureForAnnotatedProperty(Name.identifier("property"), null).getName(); + + public void testInClass() { + loadFile(); + assertClassHasAnnotatedSyntheticMethod(generateClass("A")); + } + + public void testTopLevel() { + loadFile(); + String packageClassName = PackageClassUtils.getPackageClassName(FqName.ROOT); + for (String fileName : generateClassesInFile().files()) { + if (fileName.startsWith(packageClassName) && !fileName.equals(packageClassName + ".class")) { + // This should be package$src class + Class a = generateClass(fileName.substring(0, fileName.length() - ".class".length())); + assertClassHasAnnotatedSyntheticMethod(a); + } + } + } + + private static void assertClassHasAnnotatedSyntheticMethod(@NotNull Class a) { + for (Method method : a.getDeclaredMethods()) { + if (TEST_SYNTHETIC_METHOD_NAME.equals(method.getName())) { + assertTrue(method.isSynthetic()); + int modifiers = method.getModifiers(); + assertTrue(Modifier.isFinal(modifiers)); + assertTrue(Modifier.isStatic(modifiers)); + assertTrue(Modifier.isPrivate(modifiers)); + + Annotation[] annotations = method.getDeclaredAnnotations(); + assertSize(1, annotations); + assertEquals("@SomeAnnotation(value=OK)", annotations[0].toString()); + return; + } + } + fail("Synthetic method for annotated property not found: " + TEST_SYNTHETIC_METHOD_NAME); + } +}