replace String with JvmClassName
This commit is contained in:
@@ -64,7 +64,7 @@ public class ClassFileFactory {
|
||||
FqName fqName = JetPsiUtil.getFQName(file);
|
||||
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
||||
if (codegen == null) {
|
||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName) + ".class");
|
||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName).getInternalName() + ".class");
|
||||
codegen = new NamespaceCodegen(builder, fqName, state, file.getContainingFile());
|
||||
ns2codegen.put(fqName, codegen);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public abstract class CodegenContext {
|
||||
while(!(descriptor instanceof NamespaceDescriptor)) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
}
|
||||
return NamespaceCodegen.getJVMClassNameForKotlinNs(DescriptorUtils.getFQName(descriptor).toSafe());
|
||||
return NamespaceCodegen.getJVMClassNameForKotlinNs(DescriptorUtils.getFQName(descriptor).toSafe()).getInternalName();
|
||||
}
|
||||
|
||||
public OwnerKind getContextKind() {
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.objectweb.asm.Label;
|
||||
@@ -331,18 +332,18 @@ public class FunctionCodegen {
|
||||
|
||||
int flags = ACC_PUBLIC | ACC_SYNTHETIC; // TODO.
|
||||
|
||||
String ownerInternalName;
|
||||
JvmClassName ownerInternalName;
|
||||
if (contextClass instanceof NamespaceDescriptor) {
|
||||
ownerInternalName = NamespaceCodegen.getJVMClassNameForKotlinNs(DescriptorUtils.getFQName(contextClass).toSafe());
|
||||
}
|
||||
else {
|
||||
ownerInternalName = state.getInjector().getJetTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), MapTypeMode.IMPL).getInternalName();
|
||||
ownerInternalName = JvmClassName.byType(state.getInjector().getJetTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), MapTypeMode.IMPL));
|
||||
}
|
||||
|
||||
String descriptor = jvmSignature.getDescriptor().replace(")","I)");
|
||||
boolean isConstructor = "<init>".equals(jvmSignature.getName());
|
||||
if(!isStatic && !isConstructor)
|
||||
descriptor = descriptor.replace("(","(L" + ownerInternalName + ";");
|
||||
descriptor = descriptor.replace("(", "(" + ownerInternalName.getDescriptor());
|
||||
final MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC), isConstructor ? "<init>" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, descriptor, null, null);
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||
@@ -425,17 +426,17 @@ public class FunctionCodegen {
|
||||
|
||||
if(!isStatic) {
|
||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
||||
iv.invokeinterface(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
iv.invokeinterface(ownerInternalName.getInternalName(), jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
}
|
||||
else {
|
||||
if(!isConstructor)
|
||||
iv.invokevirtual(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
iv.invokevirtual(ownerInternalName.getInternalName(), jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
else
|
||||
iv.invokespecial(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
iv.invokespecial(ownerInternalName.getInternalName(), jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
}
|
||||
}
|
||||
else {
|
||||
iv.invokestatic(ownerInternalName, jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
iv.invokestatic(ownerInternalName.getInternalName(), jvmSignature.getName(), jvmSignature.getDescriptor());
|
||||
}
|
||||
|
||||
iv.areturn(jvmSignature.getReturnType());
|
||||
|
||||
@@ -149,7 +149,7 @@ public class JetTypeMapper {
|
||||
String owner;
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
owner = jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration);
|
||||
owner = jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration).getInternalName();
|
||||
}
|
||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
@@ -207,7 +207,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String jvmClassNameForNamespace(@NotNull NamespaceDescriptor namespace) {
|
||||
private JvmClassName jvmClassNameForNamespace(@NotNull NamespaceDescriptor namespace) {
|
||||
|
||||
StringBuilder r = new StringBuilder();
|
||||
|
||||
@@ -242,7 +242,7 @@ public class JetTypeMapper {
|
||||
throw new IllegalStateException("internal error: failed to generate classname for " + namespace);
|
||||
}
|
||||
|
||||
return r.toString();
|
||||
return JvmClassName.byInternalName(r.toString());
|
||||
}
|
||||
|
||||
@NotNull public Type mapReturnType(@NotNull final JetType jetType) {
|
||||
@@ -541,7 +541,7 @@ public class JetTypeMapper {
|
||||
ClassDescriptor thisClass;
|
||||
if (functionParent instanceof NamespaceDescriptor) {
|
||||
assert !superCall;
|
||||
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent);
|
||||
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent).getInternalName();
|
||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
||||
invokeOpcode = INVOKESTATIC;
|
||||
thisClass = null;
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
@@ -44,7 +45,7 @@ public class NamespaceCodegen {
|
||||
|
||||
v.defineClass(sourceFile, V1_6,
|
||||
ACC_PUBLIC/*|ACC_SUPER*/,
|
||||
getJVMClassNameForKotlinNs(fqName),
|
||||
getJVMClassNameForKotlinNs(fqName).getInternalName(),
|
||||
null,
|
||||
//"jet/lang/Namespace",
|
||||
"java/lang/Object",
|
||||
@@ -137,9 +138,10 @@ public class NamespaceCodegen {
|
||||
v.done();
|
||||
}
|
||||
|
||||
public static String getJVMClassNameForKotlinNs(@NotNull FqName fqName) {
|
||||
@NotNull
|
||||
public static JvmClassName getJVMClassNameForKotlinNs(@NotNull FqName fqName) {
|
||||
if (fqName.isRoot()) {
|
||||
return JvmAbi.PACKAGE_CLASS;
|
||||
return JvmClassName.byInternalName(JvmAbi.PACKAGE_CLASS);
|
||||
}
|
||||
|
||||
String name = fqName.getFqName().replace('.', '/');
|
||||
@@ -147,6 +149,6 @@ public class NamespaceCodegen {
|
||||
name = name.substring(JavaDescriptorResolver.JAVA_ROOT.length() + 1, name.length());
|
||||
}
|
||||
name += "/" + JvmAbi.PACKAGE_CLASS;
|
||||
return name;
|
||||
return JvmClassName.byInternalName(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,14 @@ public class JvmClassName {
|
||||
return r;
|
||||
}
|
||||
|
||||
public static JvmClassName byType(@NotNull Type type) {
|
||||
if (type.getSort() != Type.OBJECT) {
|
||||
throw new IllegalArgumentException(
|
||||
"must be an object to be converted to " + JvmClassName.class.getSimpleName());
|
||||
}
|
||||
return byInternalName(type.getInternalName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FqName getFqName() {
|
||||
return fqName;
|
||||
|
||||
@@ -119,7 +119,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
GeneratedClassLoader loader = createClassLoader(codegens);
|
||||
|
||||
try {
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile)).replace("/", ".");
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile)).getFqName().getFqName();
|
||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
return (String) method.invoke(null);
|
||||
@@ -163,7 +163,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
}
|
||||
|
||||
protected Class loadRootNamespaceClass(@NotNull ClassFileFactory state) {
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile)).replace("/", ".");
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile)).getFqName().getFqName();
|
||||
try {
|
||||
return createClassLoader(state).loadClass(fqName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
@@ -146,7 +146,7 @@ public class StdlibTest extends CodegenTestCase {
|
||||
GeneratedClassLoader loader = createClassLoader(codegens);
|
||||
|
||||
try {
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile)).replace("/", ".");
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile)).getFqName().getFqName();
|
||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||
Method method = namespaceClass.getMethod("box", Method.class);
|
||||
method.setAccessible(true);
|
||||
|
||||
@@ -137,10 +137,10 @@ public class JetPositionManager implements PositionManager {
|
||||
else {
|
||||
JetFile namespace = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetFile.class);
|
||||
if (namespace != null) {
|
||||
names.add(NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(namespace)));
|
||||
names.add(NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(namespace)).getInternalName());
|
||||
}
|
||||
else {
|
||||
names.add(NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(file)));
|
||||
names.add(NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(file)).getInternalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user