Delete JetTypeMapperMode.TRAIT_IMPL
The code is much easier with a simple method mapTraitImpl
This commit is contained in:
@@ -161,8 +161,7 @@ public final class ClassFileFactory extends GenerationStateAware {
|
||||
|
||||
@NotNull
|
||||
public ClassBuilder forTraitImplementation(@NotNull ClassDescriptor aClass, @NotNull GenerationState state, @NotNull PsiFile file) {
|
||||
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
||||
return newVisitor(type, file);
|
||||
return newVisitor(state.getTypeMapper().mapTraitImpl(aClass), file);
|
||||
}
|
||||
|
||||
private static Collection<File> toIoFilesIgnoringNonPhysical(Collection<? extends PsiFile> psiFiles) {
|
||||
|
||||
@@ -1502,9 +1502,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
Type type = getTraitImplThisParameterType(containingClass, typeMapper);
|
||||
String functionDescriptor = methodInTrait.getDescriptor().replace("(", "(" + type.getDescriptor());
|
||||
|
||||
Type tImplType = typeMapper.mapType(containingClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
||||
|
||||
iv.invokestatic(tImplType.getInternalName(), methodToGenerate.getName(), functionDescriptor);
|
||||
iv.invokestatic(typeMapper.mapTraitImpl(containingClass).getInternalName(), methodToGenerate.getName(), functionDescriptor);
|
||||
StackValue.onStack(methodInTrait.getReturnType()).put(returnType, iv);
|
||||
iv.areturn(returnType);
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.commons.Method;
|
||||
import org.jetbrains.jet.codegen.context.ClassContext;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
@@ -47,7 +46,7 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
|
||||
protected void generateDeclaration() {
|
||||
v.defineClass(myClass, V1_6,
|
||||
ACC_PUBLIC | ACC_FINAL,
|
||||
jvmName(),
|
||||
typeMapper.mapTraitImpl(descriptor).getInternalName(),
|
||||
null,
|
||||
"java/lang/Object",
|
||||
new String[0]
|
||||
@@ -73,9 +72,4 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String jvmName() {
|
||||
return typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,23 +66,17 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type getOwner(DeclarationDescriptor descriptor, OwnerKind kind, boolean isInsideModule) {
|
||||
JetTypeMapperMode mapTypeMode = ownerKindToMapTypeMode(kind);
|
||||
|
||||
public Type getOwner(@NotNull DeclarationDescriptor descriptor, @NotNull OwnerKind kind, boolean isInsideModule) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
return asmTypeForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
|
||||
}
|
||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
if (classDescriptor.getKind() == ClassKind.OBJECT) {
|
||||
mapTypeMode = JetTypeMapperMode.IMPL;
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
return mapTraitImpl(classDescriptor);
|
||||
}
|
||||
Type asmType = mapType(classDescriptor.getDefaultType(), mapTypeMode);
|
||||
if (asmType.getSort() != Type.OBJECT) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return asmType;
|
||||
return mapType(classDescriptor.getDefaultType(), JetTypeMapperMode.IMPL);
|
||||
}
|
||||
else if (containingDeclaration instanceof ScriptDescriptor) {
|
||||
return asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) containingDeclaration);
|
||||
@@ -92,18 +86,6 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
}
|
||||
|
||||
private static JetTypeMapperMode ownerKindToMapTypeMode(OwnerKind kind) {
|
||||
if (kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.NAMESPACE) {
|
||||
return JetTypeMapperMode.IMPL;
|
||||
}
|
||||
else if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
return JetTypeMapperMode.TRAIT_IMPL;
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("must not call this method with kind = " + kind);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JavaNamespaceKind getNsKind(@NotNull NamespaceDescriptor ns) {
|
||||
JavaNamespaceKind javaNamespaceKind = bindingContext.get(JavaBindingContext.JAVA_NAMESPACE_KIND, ns);
|
||||
@@ -273,9 +255,6 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
else if (kind == JetTypeMapperMode.TYPE_PARAMETER || kind == JetTypeMapperMode.SUPER_TYPE) {
|
||||
return mapKnownAsmType(jetType, boxType(known), signatureVisitor, howThisTypeIsUsed, arrayParameter, projectionsAllowed);
|
||||
}
|
||||
else if (kind == JetTypeMapperMode.TRAIT_IMPL) {
|
||||
throw new IllegalStateException("TRAIT_IMPL is not possible for " + jetType);
|
||||
}
|
||||
else if (kind == JetTypeMapperMode.IMPL) {
|
||||
// TODO: enable and fix tests
|
||||
//throw new IllegalStateException("must not map known type to IMPL when not compiling builtins: " + jetType);
|
||||
@@ -330,17 +309,8 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
Type descriptorAsmType = getAsmType(bindingTrace, descriptor);
|
||||
Type asmType;
|
||||
if (kind == JetTypeMapperMode.TRAIT_IMPL) {
|
||||
asmType = Type.getObjectType(descriptorAsmType.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||
}
|
||||
else {
|
||||
asmType = descriptorAsmType;
|
||||
}
|
||||
|
||||
Type asmType = getAsmType(bindingTrace, descriptor);
|
||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
||||
|
||||
return asmType;
|
||||
}
|
||||
|
||||
@@ -356,6 +326,11 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
throw new UnsupportedOperationException("Unknown type " + jetType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type mapTraitImpl(@NotNull ClassDescriptor descriptor) {
|
||||
return Type.getObjectType(getAsmType(bindingTrace, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||
}
|
||||
|
||||
private String generateErrorMessageForErrorType(@NotNull DeclarationDescriptor descriptor) {
|
||||
PsiElement declarationElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||
PsiElement parentDeclarationElement = null;
|
||||
|
||||
@@ -21,10 +21,6 @@ public enum JetTypeMapperMode {
|
||||
* foo.Bar is mapped to Lfoo/Bar;
|
||||
*/
|
||||
IMPL,
|
||||
/**
|
||||
* foo.Bar is mapped to Lfoo/Bar$TImpl;
|
||||
*/
|
||||
TRAIT_IMPL,
|
||||
/**
|
||||
* jet.Int is mapped to I
|
||||
*/
|
||||
|
||||
@@ -169,14 +169,12 @@ public class JetPositionManager implements PositionManager {
|
||||
if (classDescriptor == null) {
|
||||
return null;
|
||||
}
|
||||
JetTypeMapperMode mode;
|
||||
|
||||
if (jetClass instanceof JetClass && ((JetClass) jetClass).isTrait()) {
|
||||
mode = JetTypeMapperMode.TRAIT_IMPL;
|
||||
return typeMapper.mapTraitImpl(classDescriptor).getInternalName();
|
||||
}
|
||||
else {
|
||||
mode = JetTypeMapperMode.IMPL;
|
||||
}
|
||||
return typeMapper.mapType(classDescriptor.getDefaultType(), mode).getInternalName();
|
||||
|
||||
return typeMapper.mapType(classDescriptor.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName();
|
||||
}
|
||||
|
||||
private JetTypeMapper prepareTypeMapper(final JetFile file) {
|
||||
|
||||
Reference in New Issue
Block a user