提交 f4b7913d 编写于 作者: M Michael Bogdanov

sanitizeAsJavaIdentifier function moved to JvmAbi

上级 d8be99a3
......@@ -235,9 +235,4 @@ public class JvmCodegenUtil {
av.visit(JvmAnnotationNames.MODULE_NAME_FIELD_NAME, name);
}
}
@NotNull
public static String sanitizeAsJavaIdentifier(@NotNull String str) {
return PackagePartClassUtils.sanitizeAsJavaIdentifier(str);
}
}
......@@ -880,7 +880,7 @@ public class JetTypeMapper {
}
if (!(descriptor instanceof ConstructorDescriptor) && descriptor.getVisibility() == Visibilities.INTERNAL) {
return name + "$" + JvmCodegenUtil.sanitizeAsJavaIdentifier(moduleName);
return name + "$" + JvmAbi.sanitizeAsJavaIdentifier(moduleName);
}
return name;
......
......@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.load.kotlin
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetFile
......@@ -38,10 +39,7 @@ public object PackagePartClassUtils {
if (str.isEmpty())
"_$PART_CLASS_NAME_SUFFIX"
else
capitalizeAsJavaClassName(sanitizeAsJavaIdentifier(str)) + PART_CLASS_NAME_SUFFIX
public @JvmStatic fun sanitizeAsJavaIdentifier(str: String): String =
str.replace("[^\\p{L}\\p{Digit}]".toRegex(), "_")
capitalizeAsJavaClassName(JvmAbi.sanitizeAsJavaIdentifier(str)) + PART_CLASS_NAME_SUFFIX
private @JvmStatic fun capitalizeAsJavaClassName(str: String): String =
// NB use Locale.ENGLISH so that build is locale-independent.
......
......@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.load.java;
import kotlin.StringsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.FqName;
......@@ -90,5 +91,10 @@ public final class JvmAbi {
char c = name.charAt(IS_PREFIX.length());
return !('a' <= c && c <= 'z');
}
@NotNull
public static String sanitizeAsJavaIdentifier(@NotNull String str) {
return StringsKt.replace(str, StringsKt.toRegex("[^\\p{L}\\p{Digit}]"), "_");
}
}
......@@ -120,7 +120,7 @@ internal sealed class JvmPropertySignature {
val sourceElement = containingDeclaration.source as KotlinJvmBinarySourceElement
val klass = (sourceElement.binaryClass as ReflectKotlinClass).klass
val moduleName = klass.getAnnotation(KotlinClass::class.java).moduleName
"$" + sanitizeAsJavaIdentifier(moduleName)
"$" + JvmAbi.sanitizeAsJavaIdentifier(moduleName)
}
else {
""
......@@ -129,9 +129,6 @@ internal sealed class JvmPropertySignature {
}
}
private fun sanitizeAsJavaIdentifier(str: String): String =
str.replace("[^\\p{L}\\p{Digit}]".toRegex(), "_")
override fun asString(): String = string
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册