Search in sources :

Example 1 with Function2

use of kotlin.jvm.functions.Function2 in project kotlin by JetBrains.

the class JvmClassName method byClassId.

@NotNull
public static JvmClassName byClassId(@NotNull ClassId classId, @Nullable TypeMappingConfiguration<?> typeMappingConfiguration) {
    FqName packageFqName = classId.getPackageFqName();
    String[] relativeClassNameSegments = classId.getRelativeClassName().asString().split(Pattern.quote("."));
    String relativeClassName;
    if (relativeClassNameSegments.length == 1) {
        relativeClassName = relativeClassNameSegments[0];
    } else if (relativeClassNameSegments.length > 1 && typeMappingConfiguration != null) {
        Function2<String, String, String> innerClassNameFactory = typeMappingConfiguration.getInnerClassNameFactory();
        relativeClassName = innerClassNameFactory.invoke(relativeClassNameSegments[0], relativeClassNameSegments[1]);
        for (int i = 2; i < relativeClassNameSegments.length; ++i) {
            relativeClassName = innerClassNameFactory.invoke(relativeClassName, relativeClassNameSegments[i]);
        }
    } else {
        // Default behavior if we don't have an inner class name factory
        relativeClassName = classId.getRelativeClassName().asString().replace('.', '$');
    }
    return packageFqName.isRoot() ? new JvmClassName(relativeClassName) : new JvmClassName(packageFqName.asString().replace('.', '/') + "/" + relativeClassName);
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) Function2(kotlin.jvm.functions.Function2) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Function2

use of kotlin.jvm.functions.Function2 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

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