reading constructors from binary classes
This commit is contained in:
@@ -393,9 +393,35 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
int flags = Opcodes.ACC_PUBLIC; // TODO
|
||||
final MethodVisitor mv = v.newMethod(myClass, flags, "<init>", constructorMethod.getDescriptor(), null, null);
|
||||
final MethodVisitor mv = v.newMethod(myClass, flags, constructorMethod.getName(), constructorMethod.getDescriptor(), null, null);
|
||||
if (!v.generateCode()) return;
|
||||
|
||||
AnnotationVisitor jetConstructorVisitor = mv.visitAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getDescriptor(), true);
|
||||
if (constructorDescriptor == null) {
|
||||
jetConstructorVisitor.visit(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD, true);
|
||||
}
|
||||
jetConstructorVisitor.visitEnd();
|
||||
|
||||
if (constructorDescriptor != null) {
|
||||
int i = 0;
|
||||
|
||||
if (CodegenUtil.hasThis0(descriptor)) {
|
||||
i++;
|
||||
}
|
||||
|
||||
if (CodegenUtil.requireTypeInfoConstructorArg(descriptor.getDefaultType())) {
|
||||
// TODO
|
||||
i++;
|
||||
}
|
||||
|
||||
for (ValueParameterDescriptor valueParameter : constructorDescriptor.getValueParameters()) {
|
||||
AnnotationVisitor jetValueParameterAnnotation =
|
||||
mv.visitParameterAnnotation(i++, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true);
|
||||
jetValueParameterAnnotation.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, valueParameter.getName());
|
||||
jetValueParameterAnnotation.visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
mv.visitCode();
|
||||
|
||||
List<ValueParameterDescriptor> paramDescrs = constructorDescriptor != null
|
||||
|
||||
+12
@@ -260,6 +260,18 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
else {
|
||||
for (PsiMethod constructor : psiConstructors) {
|
||||
PsiAnnotation jetConstructorAnnotation =
|
||||
constructor.getModifierList().findAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getFqName());
|
||||
if (jetConstructorAnnotation != null) {
|
||||
PsiLiteralExpression hiddenExpresson = (PsiLiteralExpression) jetConstructorAnnotation.findAttributeValue(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD);
|
||||
if (hiddenExpresson != null) {
|
||||
boolean hidden = (Boolean) hiddenExpresson.getValue();
|
||||
if (hidden) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
||||
classData.classDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
|
||||
@@ -29,6 +29,10 @@ public class JvmStdlibNames {
|
||||
|
||||
public static final JvmClassName JET_PROPERTY = new JvmClassName("jet.runtime.typeinfo.JetProperty");
|
||||
|
||||
public static final JvmClassName JET_CONSTRUCTOR = new JvmClassName("jet.runtime.typeinfo.JetConstructor");
|
||||
|
||||
public static final String JET_CONSTRUCTOR_HIDDEN_FIELD = "hidden";
|
||||
|
||||
|
||||
public static final JvmClassName JET_CLASS = new JvmClassName("jet.runtime.typeinfo.JetClass");
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
class ClassWithConstructor0()
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
class ClassWithConstructor1(p: Int)
|
||||
@@ -186,6 +186,12 @@ public class ReadClassDataTest extends TestCaseWithTmpdir {
|
||||
}
|
||||
|
||||
List<String> memberStrings = new ArrayList<String>();
|
||||
|
||||
for (ConstructorDescriptor constructor : klass.getConstructors()) {
|
||||
StringBuilder constructorSb = new StringBuilder();
|
||||
new Serializer(constructorSb).serialize(constructor);
|
||||
memberStrings.add(constructorSb.toString());
|
||||
}
|
||||
|
||||
JetScope memberScope = klass.getMemberScope(typeArguments);
|
||||
for (DeclarationDescriptor member : memberScope.getAllDescriptors()) {
|
||||
@@ -244,6 +250,9 @@ public class ReadClassDataTest extends TestCaseWithTmpdir {
|
||||
serialize(fun.getModality());
|
||||
sb.append(" ");
|
||||
|
||||
if (fun instanceof ConstructorDescriptor) {
|
||||
sb.append("/*constructor*/ ");
|
||||
}
|
||||
sb.append("fun ");
|
||||
if (!fun.getTypeParameters().isEmpty()) {
|
||||
sb.append("<");
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package jet.runtime.typeinfo;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public @interface JetConstructor {
|
||||
}
|
||||
Reference in New Issue
Block a user