Minor refactoring of writeOuterClass()
This commit is contained in:
@@ -46,7 +46,6 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
|||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.resolve.java.*;
|
import org.jetbrains.jet.lang.resolve.java.*;
|
||||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
@@ -176,7 +175,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
);
|
);
|
||||||
v.visitSource(myClass.getContainingFile().getName(), null);
|
v.visitSource(myClass.getContainingFile().getName(), null);
|
||||||
|
|
||||||
writeOuterClass();
|
writeEnclosingMethod();
|
||||||
|
|
||||||
writeInnerClasses();
|
writeInnerClasses();
|
||||||
|
|
||||||
@@ -185,43 +184,41 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
writeClassSignatureIfNeeded(signature);
|
writeClassSignatureIfNeeded(signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeOuterClass() {
|
private void writeEnclosingMethod() {
|
||||||
//JVMS7: A class must have an EnclosingMethod attribute if and only if it is a local class or an anonymous class.
|
//JVMS7: A class must have an EnclosingMethod attribute if and only if it is a local class or an anonymous class.
|
||||||
DeclarationDescriptor parentDescriptor = descriptor.getContainingDeclaration();
|
DeclarationDescriptor parentDescriptor = descriptor.getContainingDeclaration();
|
||||||
|
|
||||||
boolean isObjectLiteral = descriptor.getName().isSpecial() && descriptor.getKind() == ClassKind.OBJECT;
|
boolean isObjectLiteral = DescriptorUtils.isAnonymous(descriptor);
|
||||||
|
|
||||||
boolean isLocalOrAnonymousClass = isObjectLiteral ||
|
boolean isLocalOrAnonymousClass = isObjectLiteral ||
|
||||||
!(parentDescriptor instanceof NamespaceDescriptor || parentDescriptor instanceof ClassDescriptor);
|
!(parentDescriptor instanceof NamespaceDescriptor || parentDescriptor instanceof ClassDescriptor);
|
||||||
if (isLocalOrAnonymousClass) {
|
if (isLocalOrAnonymousClass) {
|
||||||
String outerClassName = getOuterClassName(descriptor, typeMapper, bindingContext);
|
String outerClassName = getOuterClassName(descriptor, typeMapper);
|
||||||
FunctionDescriptor function = DescriptorUtils.getParentOfType(descriptor, FunctionDescriptor.class);
|
FunctionDescriptor function = DescriptorUtils.getParentOfType(descriptor, FunctionDescriptor.class);
|
||||||
|
|
||||||
//Function descriptor could be null only for object literal in package namespace
|
if (function != null) {
|
||||||
assert (!isObjectLiteral && function != null) || isObjectLiteral:
|
Method method = typeMapper.mapSignature(function.getName(), function).getAsmMethod();
|
||||||
"Function descriptor should be present: " + descriptor.getName();
|
v.visitOuterClass(outerClassName, method.getName(), method.getDescriptor());
|
||||||
|
}
|
||||||
Name functionName = function != null ? function.getName() : null;
|
else {
|
||||||
|
assert isObjectLiteral
|
||||||
v.visitOuterClass(outerClassName,
|
: "Function descriptor could be null only for object literal in package namespace: " + descriptor.getName();
|
||||||
functionName != null ? functionName.getName() : null,
|
v.visitOuterClass(outerClassName, null, null);
|
||||||
functionName != null ? typeMapper.mapSignature(functionName, function).getAsmMethod().getDescriptor() : null);
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getOuterClassName(
|
private static String getOuterClassName(
|
||||||
@NotNull ClassDescriptor classDescriptor,
|
@NotNull ClassDescriptor classDescriptor,
|
||||||
@NotNull JetTypeMapper typeMapper,
|
@NotNull JetTypeMapper typeMapper
|
||||||
@NotNull BindingContext bindingContext
|
|
||||||
) {
|
) {
|
||||||
ClassDescriptor container = DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
|
ClassDescriptor container = DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
|
||||||
if (container != null) {
|
if (container != null) {
|
||||||
return typeMapper.mapType(container.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName();
|
return typeMapper.mapType(container.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetFile containingFile = BindingContextUtils.getContainingFile(bindingContext, classDescriptor);
|
JetFile containingFile = BindingContextUtils.getContainingFile(typeMapper.getBindingContext(), classDescriptor);
|
||||||
assert containingFile != null : "Containing file should be present for " + classDescriptor;
|
assert containingFile != null : "Containing file should be present for " + classDescriptor;
|
||||||
return NamespaceCodegen.getNamespacePartInternalName(containingFile);
|
return NamespaceCodegen.getNamespacePartInternalName(containingFile);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user