writing class signature
P. S. I'm going to refactor/cleanup code after feature is implemented
This commit is contained in:
@@ -16,6 +16,9 @@ import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.objectweb.asm.commons.Method;
|
||||
import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
import org.objectweb.asm.util.CheckSignatureAdapter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -75,7 +78,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
? Opcodes.ACC_INTERFACE
|
||||
: 0/*Opcodes.ACC_SUPER*/),
|
||||
jvmName(),
|
||||
null,
|
||||
genericSignature(),
|
||||
superClass,
|
||||
interfaces.toArray(new String[interfaces.size()])
|
||||
);
|
||||
@@ -92,6 +95,31 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String genericSignature() {
|
||||
List<TypeParameterDescriptor> typeParameters = descriptor.getTypeConstructor().getParameters();
|
||||
|
||||
SignatureWriter signatureWriter = new SignatureWriter();
|
||||
SignatureVisitor signatureVisitor = JetTypeMapper.DEBUG_SIGNATURE_WRITER
|
||||
? new CheckSignatureAdapter(CheckSignatureAdapter.CLASS_SIGNATURE, signatureWriter)
|
||||
: signatureWriter;
|
||||
for (TypeParameterDescriptor typeParameter : typeParameters) {
|
||||
signatureVisitor.visitFormalTypeParameter(typeParameter.getName());
|
||||
SignatureVisitor classBoundVisitor = signatureVisitor.visitClassBound();
|
||||
// TODO: wrong
|
||||
JetTypeMapper.visitAsmType(classBoundVisitor, JetTypeMapper.TYPE_OBJECT);
|
||||
}
|
||||
SignatureVisitor superclassSignatureVisitor = signatureVisitor.visitSuperclass();
|
||||
// TODO: wrong
|
||||
superclassSignatureVisitor.visitClassType("java/lang/Object");
|
||||
// TODO: add interfaces
|
||||
superclassSignatureVisitor.visitEnd();
|
||||
|
||||
// TODO: return null if class is not generic and does not have generic superclasses
|
||||
|
||||
return signatureWriter.toString();
|
||||
}
|
||||
|
||||
private String jvmName() {
|
||||
return typeMapper.mapType(descriptor.getDefaultType(), kind).getInternalName();
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ public class JetTypeMapper {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
private void visitAsmType(SignatureVisitor visitor, Type asmType) {
|
||||
public static void visitAsmType(SignatureVisitor visitor, Type asmType) {
|
||||
switch (asmType.getSort()) {
|
||||
case Type.OBJECT:
|
||||
visitor.visitClassType(asmType.getInternalName());
|
||||
@@ -379,7 +379,7 @@ public class JetTypeMapper {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
private static final boolean DEBUG_SIGNATURE_WRITER = true;
|
||||
public static final boolean DEBUG_SIGNATURE_WRITER = true;
|
||||
|
||||
public CallableMethod mapToCallableMethod(FunctionDescriptor functionDescriptor, boolean superCall, OwnerKind kind) {
|
||||
if(functionDescriptor == null)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
class Simple {
|
||||
{
|
||||
jet.typeinfo.TypeInfo blabla = null;
|
||||
new Impossible<String>(blabla);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
class Impossible<P>()
|
||||
Reference in New Issue
Block a user