Simplified method.
This commit is contained in:
@@ -50,7 +50,7 @@ public class CodegenBinding {
|
|||||||
|
|
||||||
public static final WritableSlice<ScriptDescriptor, ClassDescriptor> CLASS_FOR_SCRIPT = Slices.createSimpleSlice();
|
public static final WritableSlice<ScriptDescriptor, ClassDescriptor> CLASS_FOR_SCRIPT = Slices.createSimpleSlice();
|
||||||
|
|
||||||
public static final WritableSlice<DeclarationDescriptor, Type> ASM_TYPE = Slices.createSimpleSlice();
|
public static final WritableSlice<ClassDescriptor, Type> ASM_TYPE = Slices.createSimpleSlice();
|
||||||
|
|
||||||
public static final WritableSlice<ClassDescriptor, Boolean> ENUM_ENTRY_CLASS_NEED_SUBCLASS = Slices.createSimpleSetSlice();
|
public static final WritableSlice<ClassDescriptor, Boolean> ENUM_ENTRY_CLASS_NEED_SUBCLASS = Slices.createSimpleSetSlice();
|
||||||
|
|
||||||
@@ -288,73 +288,46 @@ public class CodegenBinding {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 2 accept ClassDescriptor and simplify
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Type getAsmType(@NotNull BindingTrace bindingTrace, @NotNull DeclarationDescriptor descriptor) {
|
public static Type getAsmType(@NotNull BindingTrace bindingTrace, @NotNull ClassDescriptor klass) {
|
||||||
descriptor = descriptor.getOriginal();
|
klass = (ClassDescriptor) klass.getOriginal();
|
||||||
Type alreadyComputedType = bindingTrace.getBindingContext().get(ASM_TYPE, descriptor);
|
Type alreadyComputedType = bindingTrace.getBindingContext().get(ASM_TYPE, klass);
|
||||||
if (alreadyComputedType != null) {
|
if (alreadyComputedType != null) {
|
||||||
return alreadyComputedType;
|
return alreadyComputedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type asmType = Type.getObjectType(getAsmTypeImpl(bindingTrace, descriptor));
|
Type asmType = Type.getObjectType(getAsmTypeImpl(bindingTrace, klass));
|
||||||
|
|
||||||
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, descriptor, asmType);
|
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, klass, asmType);
|
||||||
bindingTrace.record(ASM_TYPE, descriptor, asmType);
|
bindingTrace.record(ASM_TYPE, klass, asmType);
|
||||||
return asmType;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 2 accept ClassDescriptor and simplify
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static String getAsmTypeImpl(@NotNull BindingTrace bindingTrace, @NotNull DeclarationDescriptor descriptor) {
|
private static String getAsmTypeImpl(@NotNull BindingTrace bindingTrace, @NotNull ClassDescriptor klass) {
|
||||||
if (descriptor instanceof PackageFragmentDescriptor) {
|
DeclarationDescriptor container = klass.getContainingDeclaration();
|
||||||
throw new IllegalStateException("package is unexpected: " + descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptor instanceof FunctionDescriptor) {
|
|
||||||
throw new IllegalStateException("requested fq name for function: " + descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptor instanceof ModuleDescriptor) {
|
|
||||||
throw new IllegalStateException("module is unexpected: " + descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
|
||||||
if (container == null) {
|
|
||||||
throw new IllegalStateException("descriptor has no container: " + descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (container instanceof ScriptDescriptor) {
|
|
||||||
return descriptor.getName().getIdentifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (container instanceof PackageFragmentDescriptor) {
|
if (container instanceof PackageFragmentDescriptor) {
|
||||||
String shortName = descriptor.getName().getIdentifier();
|
String shortName = klass.getName().getIdentifier();
|
||||||
FqName fqName = ((PackageFragmentDescriptor) container).getFqName();
|
FqName fqName = ((PackageFragmentDescriptor) container).getFqName();
|
||||||
return fqName.isRoot() ? shortName : fqName.asString().replace('.', '/') + '/' + shortName;
|
return fqName.isRoot() ? shortName : fqName.asString().replace('.', '/') + '/' + shortName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
assert container instanceof ClassDescriptor : "Unexpected container: " + container + " for " + klass;
|
||||||
assert container instanceof ClassDescriptor : "Unexpected container: " + container + " for " + descriptor;
|
|
||||||
|
|
||||||
String containerInternalName = getAsmType(bindingTrace, container).getInternalName();
|
String containerInternalName = getAsmType(bindingTrace, (ClassDescriptor) container).getInternalName();
|
||||||
ClassDescriptor klass = (ClassDescriptor) descriptor;
|
if (klass.getKind() == ClassKind.OBJECT || klass.getKind() == ClassKind.CLASS_OBJECT) {
|
||||||
if (klass.getKind() == ClassKind.OBJECT || klass.getKind() == ClassKind.CLASS_OBJECT) {
|
if (isEnumClass(container)) {
|
||||||
if (isEnumClass(container)) {
|
return containerInternalName;
|
||||||
return containerInternalName;
|
}
|
||||||
}
|
else if (klass.getKind() == ClassKind.OBJECT) {
|
||||||
else if (klass.getKind() == ClassKind.OBJECT) {
|
return containerInternalName + "$" + klass.getName();
|
||||||
return containerInternalName + "$" + klass.getName();
|
}
|
||||||
}
|
else {
|
||||||
else {
|
return containerInternalName + JvmAbi.CLASS_OBJECT_SUFFIX;
|
||||||
return containerInternalName + JvmAbi.CLASS_OBJECT_SUFFIX;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return containerInternalName + "$" + descriptor.getName().getIdentifier();
|
|
||||||
}
|
}
|
||||||
|
return containerInternalName + "$" + klass.getName().getIdentifier();
|
||||||
throw new IllegalStateException("neither top-level nor nested class: " + descriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVarCapturedInClosure(BindingContext bindingContext, DeclarationDescriptor descriptor) {
|
public static boolean isVarCapturedInClosure(BindingContext bindingContext, DeclarationDescriptor descriptor) {
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
Type asmType = getAsmType(bindingTrace, descriptor);
|
Type asmType = getAsmType(bindingTrace, (ClassDescriptor) descriptor);
|
||||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
||||||
return asmType;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user