merge Alex' work with mine, move internal classes to internal subpackage
This commit is contained in:
committed by
Nikolay Krasko
parent
a987d197f5
commit
e92dbff73a
@@ -52,6 +52,7 @@ public class BothSignatureWriter {
|
||||
|
||||
private JetSignatureWriter jetSignatureWriter;
|
||||
|
||||
private String kotlinClassParameters;
|
||||
private String kotlinClassSignature;
|
||||
|
||||
private List<String> kotlinParameterTypes = new ArrayList<String>();
|
||||
@@ -207,7 +208,16 @@ public class BothSignatureWriter {
|
||||
}
|
||||
|
||||
public void writeFormalTypeParametersEnd() {
|
||||
jetSignatureWriter.visitSuperclass(); // just to call endFormals
|
||||
|
||||
kotlinClassParameters = jetSignatureWriter.toString();
|
||||
|
||||
jetSignatureWriter = null;
|
||||
|
||||
if (DEBUG_SIGNATURE_WRITER) {
|
||||
new JetSignatureReader(kotlinClassParameters).acceptFormalTypeParametersOnly(new JetSignatureAdapter());
|
||||
}
|
||||
|
||||
checkState(State.TYPE_PARAMETERS);
|
||||
}
|
||||
|
||||
@@ -285,6 +295,11 @@ public class BothSignatureWriter {
|
||||
public void writeSupersEnd() {
|
||||
kotlinClassSignature = jetSignatureWriter.toString();
|
||||
jetSignatureWriter = null;
|
||||
|
||||
if (DEBUG_SIGNATURE_WRITER) {
|
||||
new JetSignatureReader(kotlinClassSignature).accept(new JetSignatureAdapter());
|
||||
}
|
||||
|
||||
transitionState(State.SUPERS, State.CLASS_END);
|
||||
}
|
||||
|
||||
@@ -344,7 +359,13 @@ public class BothSignatureWriter {
|
||||
@Nullable
|
||||
public String makeKotlinClassSignature() {
|
||||
checkState(State.CLASS_END);
|
||||
return kotlinClassSignature;
|
||||
if (kotlinClassParameters == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (kotlinClassSignature == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return kotlinClassParameters + kotlinClassSignature;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,9 +71,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
v.visitOuterClass(typeMapper.mapType(((ClassDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName(), null, null);
|
||||
}
|
||||
|
||||
if(myClass instanceof JetClass) {
|
||||
if(myClass instanceof JetClass && signature.getKotlinGenericSignature() != null) {
|
||||
AnnotationVisitor annotationVisitor = v.newAnnotation(myClass, "Ljet/typeinfo/JetSignature;", true);
|
||||
annotationVisitor.visit("value", SignatureUtil.classToSignature((JetClass)myClass, bindingContext, typeMapper));
|
||||
//annotationVisitor.visit("value", SignatureUtil.classToSignature((JetClass)myClass, bindingContext, typeMapper));
|
||||
annotationVisitor.visit("value", signature.getKotlinGenericSignature());
|
||||
annotationVisitor.visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class SignatureUtil {
|
||||
private SignatureUtil() {
|
||||
}
|
||||
|
||||
public static String classToSignature(JetClass type, BindingContext bindingContext, JetTypeMapper typeMapper) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
genTypeParams(type, sb);
|
||||
List<JetDelegationSpecifier> delegationSpecifiers = type.getDelegationSpecifiers();
|
||||
for (JetDelegationSpecifier specifier : delegationSpecifiers) {
|
||||
JetTypeReference typeReference = specifier.getTypeReference();
|
||||
JetType jetType = bindingContext.get(BindingContext.TYPE, typeReference);
|
||||
genJetType(sb, jetType, typeMapper);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void genJetType(StringBuilder sb, JetType jetType, JetTypeMapper typeMapper) {
|
||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if(descriptor instanceof ClassDescriptor) {
|
||||
JetType defaultType = ((ClassDescriptor) descriptor).getDefaultType();
|
||||
Type type = typeMapper.mapType(defaultType, OwnerKind.IMPLEMENTATION);
|
||||
if(JetTypeMapper.isPrimitive(type)) {
|
||||
type = JetTypeMapper.boxType(type);
|
||||
}
|
||||
sb.append(type.getDescriptor());
|
||||
}
|
||||
else {
|
||||
sb.append("T");
|
||||
JetType defaultType = ((ClassDescriptor) descriptor.getContainingDeclaration()).getDefaultType();
|
||||
Type type = typeMapper.mapType(defaultType, OwnerKind.IMPLEMENTATION);
|
||||
sb.append(type.getDescriptor());
|
||||
sb.append(descriptor.getName());
|
||||
sb.append(";");
|
||||
}
|
||||
if(!jetType.getArguments().isEmpty()) {
|
||||
sb.append("<");
|
||||
for (TypeProjection typeProjection : jetType.getArguments()) {
|
||||
if(typeProjection.getProjectionKind() == Variance.IN_VARIANCE)
|
||||
sb.append("in ");
|
||||
if(typeProjection.getProjectionKind() == Variance.OUT_VARIANCE)
|
||||
sb.append("out ");
|
||||
genJetType(sb, typeProjection.getType(), typeMapper);
|
||||
}
|
||||
sb.append(">");
|
||||
}
|
||||
if(jetType.isNullable())
|
||||
sb.append("?");
|
||||
}
|
||||
|
||||
private static void genTypeParams(JetClass type, StringBuilder sb) {
|
||||
List<JetTypeParameter> parameters = type.getTypeParameterList().getParameters();
|
||||
if (parameters.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
sb.append('<');
|
||||
for(JetTypeParameter param : parameters) {
|
||||
Variance variance = param.getVariance();
|
||||
if(variance == Variance.IN_VARIANCE)
|
||||
sb.append("in ");
|
||||
else if(variance == Variance.OUT_VARIANCE)
|
||||
sb.append("out ");
|
||||
sb.append(param.getName());
|
||||
sb.append(";");
|
||||
}
|
||||
sb.append('>');
|
||||
}
|
||||
}
|
||||
+3
-62
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
import jet.typeinfo.internal.signature.JetSignatureAdapter;
|
||||
import jet.typeinfo.internal.signature.JetSignatureExceptionsAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -20,7 +22,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public abstract class JetTypeJetSignatureReader implements JetSignatureVisitor {
|
||||
public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAdapter {
|
||||
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final JetStandardLibrary jetStandardLibrary;
|
||||
@@ -31,47 +33,6 @@ public abstract class JetTypeJetSignatureReader implements JetSignatureVisitor {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void visitFormalTypeParameter(String name, TypeInfoVariance variance) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitClassBound() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterfaceBound() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitSuperclass() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterface() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitParameterType() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitReturnType() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitExceptionType() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
private JetType getPrimitiveType(char descriptor, boolean nullable) {
|
||||
if (!nullable) {
|
||||
switch (descriptor) {
|
||||
@@ -124,16 +85,6 @@ public abstract class JetTypeJetSignatureReader implements JetSignatureVisitor {
|
||||
done(getPrimitiveType(descriptor, nullable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeVariable(String name, boolean nullable) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitArrayType(boolean nullable) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
||||
private ClassDescriptor classDescriptor;
|
||||
private boolean nullable;
|
||||
@@ -150,16 +101,6 @@ public abstract class JetTypeJetSignatureReader implements JetSignatureVisitor {
|
||||
this.typeArguments = new ArrayList<TypeProjection>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClassType(String name, boolean nullable) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeArgument() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
private static Variance parseVariance(char wildcard) {
|
||||
switch (wildcard) {
|
||||
case '=': return Variance.INVARIANT;
|
||||
|
||||
Reference in New Issue
Block a user