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);
}
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));
}
Aggregations