Search in sources :

Example 1 with JvmMetadataVersion

use of org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion in project kotlin by JetBrains.

the class KotlinSyntheticClassAnnotationTest method assertAnnotatedWithMetadata.

private void assertAnnotatedWithMetadata(@NotNull Class<?> aClass) {
    String annotationFqName = METADATA_FQ_NAME.asString();
    Class<? extends Annotation> annotationClass = loadAnnotationClassQuietly(annotationFqName);
    assertTrue("No annotation " + annotationFqName + " found in " + aClass, aClass.isAnnotationPresent(annotationClass));
    Annotation annotation = aClass.getAnnotation(annotationClass);
    int[] version = (int[]) CodegenTestUtil.getAnnotationAttribute(annotation, METADATA_VERSION_FIELD_NAME);
    assertNotNull(version);
    assertTrue("Annotation " + annotationFqName + " is written with an unsupported format", new JvmMetadataVersion(version).isCompatible());
}
Also used : JvmMetadataVersion(org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion) Annotation(java.lang.annotation.Annotation)

Example 2 with JvmMetadataVersion

use of org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method doTestKotlinLibraryWithWrongMetadataVersion.

private void doTestKotlinLibraryWithWrongMetadataVersion(@NotNull String libraryName, @Nullable final Function2<String, Object, Object> additionalTransformation, @NotNull String... additionalOptions) throws Exception {
    final int[] version = new JvmMetadataVersion(42, 0, 0).toArray();
    File library = transformJar(compileLibrary(libraryName), new Function2<String, byte[], byte[]>() {

        @Override
        public byte[] invoke(String name, byte[] bytes) {
            return WrongBytecodeVersionTest.Companion.transformMetadataInClassFile(bytes, new Function2<String, Object, Object>() {

                @Override
                public Object invoke(String name, Object value) {
                    if (additionalTransformation != null) {
                        Object result = additionalTransformation.invoke(name, value);
                        if (result != null)
                            return result;
                    }
                    return JvmAnnotationNames.METADATA_VERSION_FIELD_NAME.equals(name) ? version : null;
                }
            });
        }
    });
    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, Arrays.asList(additionalOptions), library);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
}
Also used : JvmMetadataVersion(org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) DescriptorUtils.isObject(org.jetbrains.kotlin.resolve.DescriptorUtils.isObject) Function2(kotlin.jvm.functions.Function2) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Aggregations

JvmMetadataVersion (org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion)2 File (java.io.File)1 Annotation (java.lang.annotation.Annotation)1 JarFile (java.util.jar.JarFile)1 Function2 (kotlin.jvm.functions.Function2)1 ExitCode (org.jetbrains.kotlin.cli.common.ExitCode)1 DescriptorUtils.isObject (org.jetbrains.kotlin.resolve.DescriptorUtils.isObject)1 RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile)1