Merge remote branch 'origin/master'
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JetSignatureUtils;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureWriter;
|
||||
@@ -184,21 +184,12 @@ public class BothSignatureWriter {
|
||||
signatureVisitor().visitTypeVariable(name);
|
||||
jetSignatureWriter.visitTypeVariable(name, nullable);
|
||||
}
|
||||
|
||||
private TypeInfoVariance translateVariance(Variance variance) {
|
||||
switch (variance) {
|
||||
case IN_VARIANCE: return TypeInfoVariance.IN;
|
||||
case OUT_VARIANCE: return TypeInfoVariance.OUT;
|
||||
case INVARIANT: return TypeInfoVariance.INVARIANT;
|
||||
default: throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeFormalTypeParameter(final String name, Variance variance) {
|
||||
checkTopLevel();
|
||||
|
||||
signatureVisitor().visitFormalTypeParameter(name);
|
||||
jetSignatureWriter.visitFormalTypeParameter(name, translateVariance(variance));
|
||||
jetSignatureWriter.visitFormalTypeParameter(name, JetSignatureUtils.translateVariance(variance));
|
||||
}
|
||||
|
||||
public void writeFormalTypeParameterEnd() {
|
||||
|
||||
@@ -1254,7 +1254,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
if(descriptor instanceof ClassReceiver) {
|
||||
Type exprType = asmType(descriptor.getType());
|
||||
ClassReceiver classReceiver = (ClassReceiver) descriptor;
|
||||
generateThisOrOuter((ClassDescriptor) classReceiver.getDeclarationDescriptor()).put(exprType, v);
|
||||
ClassDescriptor classReceiverDeclarationDescriptor = (ClassDescriptor) classReceiver.getDeclarationDescriptor();
|
||||
if(CodegenUtil.isClassObject(classReceiverDeclarationDescriptor)) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) classReceiverDeclarationDescriptor.getContainingDeclaration();
|
||||
Type classObjType = typeMapper.mapType(containingDeclaration.getDefaultType());
|
||||
v.getstatic(classObjType.getInternalName(), "$classobj", exprType.getDescriptor());
|
||||
}
|
||||
else {
|
||||
generateThisOrOuter(classReceiverDeclarationDescriptor).put(exprType, v);
|
||||
}
|
||||
if(type != null)
|
||||
StackValue.onStack(exprType).put(type, v);
|
||||
}
|
||||
|
||||
@@ -100,12 +100,12 @@ public class FunctionCodegen {
|
||||
}
|
||||
|
||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(start++, StdlibNames.JET_VALUE_PARAMETER_DESCRIPTOR, true);
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(start++, StdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
|
||||
av.visit(StdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$self");
|
||||
av.visitEnd();
|
||||
}
|
||||
if(receiverParameter.exists()) {
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(start++, StdlibNames.JET_VALUE_PARAMETER_DESCRIPTOR, true);
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(start++, StdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
|
||||
av.visit(StdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$receiver");
|
||||
if(receiverParameter.getType().isNullable()) {
|
||||
av.visit(StdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true);
|
||||
@@ -113,12 +113,12 @@ public class FunctionCodegen {
|
||||
av.visitEnd();
|
||||
}
|
||||
for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(start++, StdlibNames.JET_TYPE_PARAMETER_DESCRIPTOR, true);
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(start++, StdlibNames.JET_TYPE_PARAMETER.getDescriptor(), true);
|
||||
av.visit(StdlibNames.JET_TYPE_PARAMETER_NAME_FIELD, typeParameterDescriptor.getName());
|
||||
av.visitEnd();
|
||||
}
|
||||
for(int i = 0; i != paramDescrs.size(); ++i) {
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(i + start, StdlibNames.JET_VALUE_PARAMETER_DESCRIPTOR, true);
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(i + start, StdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
|
||||
ValueParameterDescriptor parameterDescriptor = paramDescrs.get(i);
|
||||
av.visit(StdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, parameterDescriptor.getName());
|
||||
if(parameterDescriptor.hasDefaultValue()) {
|
||||
|
||||
@@ -72,9 +72,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
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", signature.getKotlinGenericSignature());
|
||||
AnnotationVisitor annotationVisitor = v.newAnnotation(myClass, StdlibNames.JET_CLASS.getDescriptor(), true);
|
||||
annotationVisitor.visit(StdlibNames.JET_CLASS_SIGNATURE, signature.getKotlinGenericSignature());
|
||||
annotationVisitor.visitEnd();
|
||||
}
|
||||
}
|
||||
@@ -107,7 +106,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
|
||||
{ // superinterfaces
|
||||
superInterfacesLinkedHashSet.add(StdlibNames.JET_OBJECT_INTERNAL);
|
||||
superInterfacesLinkedHashSet.add(StdlibNames.JET_OBJECT.getInternalName());
|
||||
|
||||
for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) {
|
||||
JetType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
|
||||
+94
-11
@@ -17,6 +17,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureVisitor;
|
||||
@@ -124,9 +125,9 @@ public class JavaDescriptorResolver {
|
||||
resolveParentDescriptor(psiClass), psiClass.isInterface() ? ClassKind.TRAIT : ClassKind.CLASS
|
||||
);
|
||||
classDescriptor.setName(name);
|
||||
|
||||
|
||||
List<JetType> supertypes = new ArrayList<JetType>();
|
||||
List<TypeParameterDescriptor> typeParameters = makeUninitializedTypeParameters(classDescriptor, psiClass.getTypeParameters());
|
||||
List<TypeParameterDescriptor> typeParameters = resolveClassTypeParameters(psiClass, classDescriptor);
|
||||
classDescriptor.setTypeConstructor(new TypeConstructorImpl(
|
||||
classDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
@@ -144,8 +145,11 @@ public class JavaDescriptorResolver {
|
||||
classDescriptorCache.put(psiClass.getQualifiedName(), classDescriptor);
|
||||
classDescriptor.setUnsubstitutedMemberScope(new JavaClassMembersScope(classDescriptor, psiClass, semanticServices, false));
|
||||
|
||||
// UGLY HACK
|
||||
initializeTypeParameters(psiClass);
|
||||
// TODO: initialize
|
||||
if (psiClass.getModifierList().findAnnotation(StdlibNames.JET_CLASS.getFqName()) == null) {
|
||||
// UGLY HACK (Andrey Breslav is not sure what did he mean)
|
||||
initializeTypeParameters(psiClass);
|
||||
}
|
||||
|
||||
supertypes.addAll(getSupertypes(psiClass));
|
||||
if (psiClass.isInterface()) {
|
||||
@@ -197,6 +201,82 @@ public class JavaDescriptorResolver {
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
private List<TypeParameterDescriptor> resolveClassTypeParameters(PsiClass psiClass, JavaClassDescriptor classDescriptor) {
|
||||
for (PsiAnnotation annotation : psiClass.getModifierList().getAnnotations()) {
|
||||
if (annotation.getQualifiedName().equals(StdlibNames.JET_CLASS.getFqName())) {
|
||||
PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(StdlibNames.JET_CLASS_SIGNATURE);
|
||||
if (attributeValue != null) {
|
||||
String typeParametersString = (String) attributeValue.getValue();
|
||||
if (typeParametersString != null) {
|
||||
return resolveClassTypeParametersFromJetSignature(typeParametersString, classDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return makeUninitializedTypeParameters(classDescriptor, psiClass.getTypeParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #resolveMethodTypeParametersFromJetSignature(String, FunctionDescriptor)
|
||||
*/
|
||||
private List<TypeParameterDescriptor> resolveClassTypeParametersFromJetSignature(String jetSignature, final JavaClassDescriptor classDescriptor) {
|
||||
final List<TypeParameterDescriptor> r = new ArrayList<TypeParameterDescriptor>();
|
||||
new JetSignatureReader(jetSignature).accept(new JetSignatureExceptionsAdapter() {
|
||||
@Override
|
||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) {
|
||||
return new JetSignatureExceptionsAdapter() {
|
||||
int index = 0;
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitClassBound() {
|
||||
return new JetTypeJetSignatureReader(JavaDescriptorResolver.this, semanticServices.getJetSemanticServices().getStandardLibrary()) {
|
||||
@Override
|
||||
protected void done(@NotNull JetType jetType) {
|
||||
// TODO
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterfaceBound() {
|
||||
return new JetTypeJetSignatureReader(JavaDescriptorResolver.this, semanticServices.getJetSemanticServices().getStandardLibrary()) {
|
||||
@Override
|
||||
protected void done(@NotNull JetType jetType) {
|
||||
// TODO
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFormalTypeParameterEnd() {
|
||||
TypeParameterDescriptor typeParameter = TypeParameterDescriptor.createForFurtherModification(
|
||||
classDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO: wrong
|
||||
true, // TODO: wrong
|
||||
JetSignatureUtils.translateVariance(variance),
|
||||
name,
|
||||
++index);
|
||||
r.add(typeParameter);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitSuperclass() {
|
||||
// TODO
|
||||
return new JetSignatureAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterface() {
|
||||
// TODO
|
||||
return new JetSignatureAdapter();
|
||||
}
|
||||
});
|
||||
return r;
|
||||
}
|
||||
|
||||
private DeclarationDescriptor resolveParentDescriptor(PsiClass psiClass) {
|
||||
PsiClass containingClass = psiClass.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
@@ -381,7 +461,7 @@ public class JavaDescriptorResolver {
|
||||
PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
|
||||
attributes.toString();
|
||||
|
||||
if (annotation.getQualifiedName().equals(StdlibNames.JET_VALUE_PARAMETER_CLASS)) {
|
||||
if (annotation.getQualifiedName().equals(StdlibNames.JET_VALUE_PARAMETER.getFqName())) {
|
||||
PsiLiteralExpression nameExpression = (PsiLiteralExpression) annotation.findAttributeValue(StdlibNames.JET_VALUE_PARAMETER_NAME_FIELD);
|
||||
if (nameExpression != null) {
|
||||
name = (String) nameExpression.getValue();
|
||||
@@ -400,7 +480,7 @@ public class JavaDescriptorResolver {
|
||||
if (signatureExpression != null) {
|
||||
typeFromAnnotation = (String) signatureExpression.getValue();
|
||||
}
|
||||
} else if (annotation.getQualifiedName().equals(StdlibNames.JET_TYPE_PARAMETER_CLASS)) {
|
||||
} else if (annotation.getQualifiedName().equals(StdlibNames.JET_TYPE_PARAMETER.getFqName())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -531,7 +611,7 @@ public class JavaDescriptorResolver {
|
||||
|
||||
private List<TypeParameterDescriptor> resolveMethodTypeParameters(PsiMethod method, FunctionDescriptorImpl functionDescriptorImpl) {
|
||||
for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) {
|
||||
if (annotation.getQualifiedName().equals(StdlibNames.JET_METHOD_CLASS)) {
|
||||
if (annotation.getQualifiedName().equals(StdlibNames.JET_METHOD.getFqName())) {
|
||||
PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(StdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD);
|
||||
if (attributeValue != null) {
|
||||
String typeParametersString = (String) attributeValue.getValue();
|
||||
@@ -546,12 +626,15 @@ public class JavaDescriptorResolver {
|
||||
initializeTypeParameters(method);
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see #resolveClassTypeParametersFromJetSignature(String, JavaClassDescriptor)
|
||||
*/
|
||||
private List<TypeParameterDescriptor> resolveMethodTypeParametersFromJetSignature(String jetSignature, final FunctionDescriptor functionDescriptor) {
|
||||
final List<TypeParameterDescriptor> r = new ArrayList<TypeParameterDescriptor>();
|
||||
new JetSignatureReader(jetSignature).acceptFormalTypeParametersOnly(new JetSignatureExceptionsAdapter() {
|
||||
@Override
|
||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, TypeInfoVariance variance) {
|
||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) {
|
||||
|
||||
return new JetSignatureExceptionsAdapter() {
|
||||
int index = 0;
|
||||
@@ -582,7 +665,7 @@ public class JavaDescriptorResolver {
|
||||
functionDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO: wrong
|
||||
true, // TODO: wrong
|
||||
Variance.INVARIANT, // TOOD: wrong
|
||||
JetSignatureUtils.translateVariance(variance),
|
||||
name,
|
||||
++index);
|
||||
r.add(typeParameter);
|
||||
@@ -600,7 +683,7 @@ public class JavaDescriptorResolver {
|
||||
String returnTypeFromAnnotation = null;
|
||||
|
||||
for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) {
|
||||
if (annotation.getQualifiedName().equals(StdlibNames.JET_METHOD_CLASS)) {
|
||||
if (annotation.getQualifiedName().equals(StdlibNames.JET_METHOD.getFqName())) {
|
||||
PsiLiteralExpression nullableExpression = (PsiLiteralExpression) annotation.findAttributeValue(StdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD);
|
||||
if (nullableExpression != null) {
|
||||
nullable = (Boolean) nullableExpression.getValue();
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JetSignatureUtils {
|
||||
|
||||
static {
|
||||
if (Variance.INVARIANT.ordinal() != TypeInfoVariance.INVARIANT.ordinal())
|
||||
throw new IllegalStateException();
|
||||
if (Variance.IN_VARIANCE.ordinal() != TypeInfoVariance.IN.ordinal())
|
||||
throw new IllegalStateException();
|
||||
if (Variance.OUT_VARIANCE.ordinal() != TypeInfoVariance.OUT.ordinal())
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public static TypeInfoVariance translateVariance(Variance variance) {
|
||||
return TypeInfoVariance.values()[variance.ordinal()];
|
||||
}
|
||||
|
||||
public static Variance translateVariance(TypeInfoVariance variance) {
|
||||
return Variance.values()[variance.ordinal()];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JvmClassName {
|
||||
|
||||
private final String fqName;
|
||||
|
||||
public JvmClassName(@NotNull String fqName) {
|
||||
this.fqName = fqName;
|
||||
}
|
||||
|
||||
public String getFqName() {
|
||||
return fqName;
|
||||
}
|
||||
|
||||
private String internalName;
|
||||
|
||||
public String getInternalName() {
|
||||
if (internalName == null) {
|
||||
String descriptor = getDescriptor();
|
||||
internalName = descriptor.substring(1, descriptor.length() - 1);
|
||||
}
|
||||
return internalName;
|
||||
}
|
||||
|
||||
private String descriptor;
|
||||
|
||||
public String getDescriptor() {
|
||||
if (descriptor == null) {
|
||||
StringBuilder sb = new StringBuilder(fqName.length() + 2);
|
||||
sb.append('L');
|
||||
sb.append(fqName.replace('.', '/'));
|
||||
sb.append(';');
|
||||
descriptor = sb.toString();
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
@@ -7,32 +7,33 @@ import org.objectweb.asm.Type;
|
||||
*/
|
||||
public class StdlibNames {
|
||||
|
||||
public static final String JET_VALUE_PARAMETER_CLASS = "jet.typeinfo.JetValueParameter";
|
||||
public static final String JET_VALUE_PARAMETER_DESCRIPTOR = "Ljet/typeinfo/JetValueParameter;";
|
||||
|
||||
public static final JvmClassName JET_VALUE_PARAMETER = new JvmClassName("jet.typeinfo.JetValueParameter");
|
||||
|
||||
public static final String JET_VALUE_PARAMETER_NAME_FIELD = "name";
|
||||
public static final String JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD = "hasDefaultValue";
|
||||
public static final String JET_VALUE_PARAMETER_NULLABLE_FIELD = "nullable";
|
||||
public static final String JET_VALUE_PARAMETER_TYPE_FIELD = "type";
|
||||
|
||||
|
||||
public static final String JET_TYPE_PARAMETER_CLASS = "jet.typeinfo.JetTypeParameter";
|
||||
public static final String JET_TYPE_PARAMETER_DESCRIPTOR = "Ljet/typeinfo/JetTypeParameter;";
|
||||
|
||||
public static final JvmClassName JET_TYPE_PARAMETER = new JvmClassName("jet.typeinfo.JetTypeParameter");
|
||||
|
||||
public static final String JET_TYPE_PARAMETER_NAME_FIELD = "name";
|
||||
|
||||
|
||||
public static final String JET_METHOD_CLASS = "jet.typeinfo.JetMethod";
|
||||
public static final String JET_METHOD_DESCRIPTOR = "Ljet/typeinfo/JetMethod;";
|
||||
|
||||
public static final JvmClassName JET_METHOD = new JvmClassName("jet.typeinfo.JetMethod");
|
||||
|
||||
public static final String JET_METHOD_NULLABLE_RETURN_TYPE_FIELD = "nullableReturnType";
|
||||
public static final String JET_METHOD_RETURN_TYPE_FIELD = "returnType";
|
||||
public static final String JET_METHOD_TYPE_PARAMETERS_FIELD = "typeParameters";
|
||||
|
||||
|
||||
public static final String JET_OBJECT_INTERNAL = "jet/JetObject";
|
||||
public static final String JET_OBJECT_CLASS = "jet.JetObject";
|
||||
public static final String JET_OBJECT_DESCRIPTOR = "Ljet/JetObject;";
|
||||
public static final JvmClassName JET_CLASS = new JvmClassName("jet.typeinfo.JetClass");
|
||||
|
||||
public static final String JET_CLASS_SIGNATURE = "signature";
|
||||
|
||||
|
||||
public static final JvmClassName JET_OBJECT = new JvmClassName("jet.JetObject");
|
||||
|
||||
|
||||
private StdlibNames() {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace test
|
||||
|
||||
class Wine<in T>
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace test
|
||||
|
||||
class Juice<in T>
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace test
|
||||
|
||||
class Beer<T>
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace test
|
||||
|
||||
fun <in T> f() = 1
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace test
|
||||
|
||||
fun <out T> f() = 1
|
||||
@@ -153,16 +153,22 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
String bs = serializeContent((ClassDescriptor) b);
|
||||
|
||||
Assert.assertEquals(as, bs);
|
||||
System.out.println(a);
|
||||
System.out.println(as);
|
||||
}
|
||||
|
||||
private String serializeContent(ClassDescriptor klass) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ");
|
||||
|
||||
|
||||
serialize(klass, sb);
|
||||
|
||||
if (!klass.getTypeConstructor().getParameters().isEmpty()) {
|
||||
sb.append("<");
|
||||
serializeCommaSeparated(klass.getTypeConstructor().getParameters(), sb);
|
||||
sb.append(">");
|
||||
}
|
||||
|
||||
// TODO: supers
|
||||
// TODO: constructors
|
||||
|
||||
@@ -200,7 +206,6 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
|
||||
private static Object invoke(Method method, Object thiz, Object... args) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
return method.invoke(thiz, args);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("failed to invoke " + method + ": " + e, e);
|
||||
@@ -229,7 +234,7 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
sb.append("vararg ");
|
||||
serialize(valueParameter.getVarargElementType());
|
||||
} else {
|
||||
serialize(valueParameter.getOutType());
|
||||
serialize(valueParameter.getOutType(), sb);
|
||||
}
|
||||
if (valueParameter.hasDefaultValue()) {
|
||||
sb.append(" = ?");
|
||||
@@ -237,7 +242,12 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
private void serialize(Variance variance, StringBuilder sb) {
|
||||
sb.append(variance);
|
||||
if (variance == Variance.INVARIANT) {
|
||||
|
||||
} else {
|
||||
sb.append(variance);
|
||||
sb.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
private void serialize(JetType type, StringBuilder sb) {
|
||||
@@ -274,7 +284,7 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private void serialize(Object o, StringBuilder sb) {
|
||||
private Method getMethodToSerialize(Object o) {
|
||||
// TODO: cache
|
||||
for (Method method : ReadClassDataTest.class.getDeclaredMethods()) {
|
||||
if (!method.getName().equals("serialize")) {
|
||||
@@ -290,12 +300,17 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
continue;
|
||||
}
|
||||
if (method.getParameterTypes()[0].isInstance(o)) {
|
||||
invoke(method, this, o, sb);
|
||||
return;
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("don't know how to serialize " + o + " (of " + o.getClass() + ")");
|
||||
}
|
||||
|
||||
private void serialize(Object o, StringBuilder sb) {
|
||||
Method method = getMethodToSerialize(o);
|
||||
invoke(method, this, o, sb);
|
||||
}
|
||||
|
||||
private void serialize(ModuleDescriptor module, StringBuilder sb) {
|
||||
// nop
|
||||
@@ -318,9 +333,7 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
private void serialize(TypeParameterDescriptor param, StringBuilder sb) {
|
||||
if (param.getVariance() != Variance.INVARIANT) {
|
||||
serialize(param.getVariance(), sb);
|
||||
}
|
||||
serialize(param.getVariance(), sb);
|
||||
sb.append(param.getName());
|
||||
// TODO: serialize bounds
|
||||
}
|
||||
|
||||
@@ -166,6 +166,12 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
assertEquals(0xFF0000, rgbMethod.invoke(redValue));
|
||||
}
|
||||
|
||||
public void testClassObjFields() throws Exception {
|
||||
loadText("class A() { class object { val value = 10 } }\n" +
|
||||
"fun box() = if(A.value == 10) \"OK\" else \"fail\"");
|
||||
blackBox();
|
||||
}
|
||||
|
||||
public void testKt249() throws Exception {
|
||||
blackBoxFile("regressions/kt249.jet");
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*;
|
||||
* @url http://confluence.jetbrains.net/display/JET/Jet+Signatures
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JetSignature {
|
||||
String value();
|
||||
public @interface JetClass {
|
||||
String signature();
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.jet.rt;
|
||||
|
||||
import jet.typeinfo.JetSignature;
|
||||
import jet.typeinfo.JetClass;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import jet.typeinfo.TypeInfoProjection;
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
@@ -51,9 +51,9 @@ class TypeInfoParser {
|
||||
return signature;
|
||||
}
|
||||
|
||||
JetSignature annotation = (JetSignature) klass.getAnnotation(JetSignature.class);
|
||||
JetClass annotation = (JetClass) klass.getAnnotation(JetClass.class);
|
||||
if(annotation != null) {
|
||||
String value = annotation.value();
|
||||
String value = annotation.signature();
|
||||
if(value != null) {
|
||||
Class enclosingClass = klass.getEnclosingClass();
|
||||
Signature signature = new Signature(klass);
|
||||
|
||||
@@ -36,6 +36,10 @@ public class JetSignatureReader {
|
||||
pos = parseType(signature, pos, v.visitInterface());
|
||||
}
|
||||
}
|
||||
|
||||
if (pos != signature.length()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
public int acceptFormalTypeParameters(JetSignatureVisitor v) {
|
||||
|
||||
Reference in New Issue
Block a user