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.Type;
|
||||||
import org.objectweb.asm.commons.InstructionAdapter;
|
import org.objectweb.asm.commons.InstructionAdapter;
|
||||||
import org.objectweb.asm.commons.Method;
|
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.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -75,7 +78,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
? Opcodes.ACC_INTERFACE
|
? Opcodes.ACC_INTERFACE
|
||||||
: 0/*Opcodes.ACC_SUPER*/),
|
: 0/*Opcodes.ACC_SUPER*/),
|
||||||
jvmName(),
|
jvmName(),
|
||||||
null,
|
genericSignature(),
|
||||||
superClass,
|
superClass,
|
||||||
interfaces.toArray(new String[interfaces.size()])
|
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() {
|
private String jvmName() {
|
||||||
return typeMapper.mapType(descriptor.getDefaultType(), kind).getInternalName();
|
return typeMapper.mapType(descriptor.getDefaultType(), kind).getInternalName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ public class JetTypeMapper {
|
|||||||
return asmType;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void visitAsmType(SignatureVisitor visitor, Type asmType) {
|
public static void visitAsmType(SignatureVisitor visitor, Type asmType) {
|
||||||
switch (asmType.getSort()) {
|
switch (asmType.getSort()) {
|
||||||
case Type.OBJECT:
|
case Type.OBJECT:
|
||||||
visitor.visitClassType(asmType.getInternalName());
|
visitor.visitClassType(asmType.getInternalName());
|
||||||
@@ -379,7 +379,7 @@ public class JetTypeMapper {
|
|||||||
return asmType;
|
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) {
|
public CallableMethod mapToCallableMethod(FunctionDescriptor functionDescriptor, boolean superCall, OwnerKind kind) {
|
||||||
if(functionDescriptor == null)
|
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