Delete JvmClassName.byClassDescriptor

It only worked correctly by coincidence: mapping from the Kotlin world to the
JVM world should always be done through JetTypeMapper
This commit is contained in:
Alexander Udalov
2013-09-26 20:35:47 +04:00
parent ead8833a88
commit 6aab9fe04e
4 changed files with 8 additions and 36 deletions
@@ -103,7 +103,7 @@ public class ClosureCodegen extends GenerationStateAware {
}
else {
interfaceFunction = SingleAbstractMethodUtils.getAbstractMethodOfSamInterface(samInterface);
superInterfaces = new String[] {JvmClassName.byClassDescriptor(samInterface).getInternalName()};
superInterfaces = new String[] { typeMapper.mapType(samInterface).getInternalName() };
}
cv.defineClass(fun,
@@ -1095,6 +1095,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
//This field are always static and final so if it has constant initializer don't do anything in clinit,
//field would be initialized via default value in v.newField(...) - see JVM SPEC Ch.4
// TODO: test this code
if (state.getClassBuilderMode() == ClassBuilderMode.FULL && propertyInfo.defaultValue == null) {
ExpressionCodegen codegen = createOrGetClInitCodegen();
int classObjectIndex = putClassObjectInLocalVar(codegen);
@@ -1122,7 +1123,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ExpressionCodegen codegen = createOrGetClInitCodegen();
StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, false, null);
property.put(property.type, codegen.v);
StackValue.Field field = StackValue.field(property.type, JvmClassName.byClassDescriptor(descriptor),
StackValue.Field field = StackValue.field(property.type, JvmClassName.byType(classAsmType),
propertyDescriptor.getName().asString(), true);
field.store(field.type, codegen.v);
}
@@ -70,7 +70,7 @@ public class SamWrapperCodegen extends GenerationStateAware {
name.getInternalName(),
null,
OBJECT_TYPE.getInternalName(),
new String[]{JvmClassName.byClassDescriptor(samInterface).getInternalName()}
new String[]{ typeMapper.mapType(samInterface).getInternalName() }
);
cv.visitSource(file.getName(), null);
@@ -19,15 +19,8 @@ package org.jetbrains.jet.lang.resolve.java;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.ArrayList;
import java.util.List;
public class JvmClassName {
@NotNull
@@ -63,40 +56,18 @@ public class JvmClassName {
return byFqNameWithoutInnerClasses(new FqName(klass.getCanonicalName()));
}
private static String encodeSpecialNames(String str) {
@NotNull
private static String encodeSpecialNames(@NotNull String str) {
String encodedObjectNames = StringUtil.replace(str, JvmAbi.CLASS_OBJECT_CLASS_NAME, CLASS_OBJECT_REPLACE_GUARD);
return StringUtil.replace(encodedObjectNames, JvmAbi.TRAIT_IMPL_CLASS_NAME, TRAIT_IMPL_REPLACE_GUARD);
}
private static String decodeSpecialNames(String str) {
@NotNull
private static String decodeSpecialNames(@NotNull String str) {
String decodedObjectNames = StringUtil.replace(str, CLASS_OBJECT_REPLACE_GUARD, JvmAbi.CLASS_OBJECT_CLASS_NAME);
return StringUtil.replace(decodedObjectNames, TRAIT_IMPL_REPLACE_GUARD, JvmAbi.TRAIT_IMPL_CLASS_NAME);
}
@NotNull
private static JvmClassName byFqNameAndInnerClassList(@NotNull FqName fqName, @NotNull List<String> innerClassList) {
String outerClassName = fqNameToInternalName(fqName);
StringBuilder sb = new StringBuilder(outerClassName);
for (String innerClassName : innerClassList) {
sb.append("$").append(innerClassName);
}
return new JvmClassName(sb.toString());
}
@NotNull
public static JvmClassName byClassDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
DeclarationDescriptor descriptor = classDescriptor;
List<String> innerClassNames = new ArrayList<String>();
while (descriptor.getContainingDeclaration() instanceof ClassDescriptor) {
innerClassNames.add(descriptor.getName().asString());
descriptor = descriptor.getContainingDeclaration();
assert descriptor != null;
}
return byFqNameAndInnerClassList(DescriptorUtils.getFQName(descriptor).toSafe(), innerClassNames);
}
@NotNull
private static String fqNameToInternalName(@NotNull FqName fqName) {
return fqName.asString().replace('.', '/');