|
@@ -262,14 +262,16 @@ public class JavaNativeModule {
|
262
|
262
|
compiled.setFieldInfo(member, new JavaField(javaClass, field.getName(), getDescriptor(field.getType())));
|
263
|
263
|
}
|
264
|
264
|
|
265
|
|
- for (Method method : cls.getDeclaredMethods()) {
|
266
|
|
- ZenCodeType.Constructor constructorAnnotation = method.getAnnotation(ZenCodeType.Constructor.class);
|
267
|
|
- if (constructorAnnotation != null || (!annotated && method.getName().equals("<init>"))) {
|
268
|
|
- ConstructorMember member = asConstructor(definition, method);
|
|
265
|
+ for (java.lang.reflect.Constructor constructor : cls.getConstructors()) {
|
|
266
|
+ ZenCodeType.Constructor constructorAnnotation = (ZenCodeType.Constructor)constructor.getAnnotation(ZenCodeType.Constructor.class);
|
|
267
|
+ if (constructorAnnotation != null || !annotated) {
|
|
268
|
+ ConstructorMember member = asConstructor(definition, constructor);
|
269
|
269
|
definition.addMember(member);
|
270
|
|
- compiled.setMethodInfo(member, getMethod(javaClass, method, BasicTypeID.VOID.stored));
|
|
270
|
+ compiled.setMethodInfo(member, getMethod(javaClass, constructor));
|
271
|
271
|
}
|
272
|
|
-
|
|
272
|
+ }
|
|
273
|
+
|
|
274
|
+ for (Method method : cls.getDeclaredMethods()) {
|
273
|
275
|
ZenCodeType.Method methodAnnotation = method.getAnnotation(ZenCodeType.Method.class);
|
274
|
276
|
if (methodAnnotation != null) {
|
275
|
277
|
MethodMember member = asMethod(definition, method, methodAnnotation);
|
|
@@ -338,12 +340,12 @@ public class JavaNativeModule {
|
338
|
340
|
return name;
|
339
|
341
|
}
|
340
|
342
|
|
341
|
|
- private ConstructorMember asConstructor(HighLevelDefinition definition, Method method) {
|
|
343
|
+ private ConstructorMember asConstructor(HighLevelDefinition definition, java.lang.reflect.Constructor method) {
|
342
|
344
|
FunctionHeader header = getHeader(method);
|
343
|
345
|
return new ConstructorMember(
|
344
|
346
|
CodePosition.NATIVE,
|
345
|
347
|
definition,
|
346
|
|
- getMethodModifiers(method),
|
|
348
|
+ Modifiers.PUBLIC,
|
347
|
349
|
header,
|
348
|
350
|
null);
|
349
|
351
|
}
|
|
@@ -412,16 +414,35 @@ public class JavaNativeModule {
|
412
|
414
|
return new CasterMember(CodePosition.NATIVE, definition, modifiers, toType, null);
|
413
|
415
|
}
|
414
|
416
|
|
|
417
|
+ private FunctionHeader getHeader(java.lang.reflect.Constructor constructor) {
|
|
418
|
+ return getHeader(
|
|
419
|
+ null,
|
|
420
|
+ constructor.getAnnotatedParameterTypes(),
|
|
421
|
+ constructor.getTypeParameters(),
|
|
422
|
+ constructor.getAnnotatedExceptionTypes());
|
|
423
|
+ }
|
|
424
|
+
|
415
|
425
|
private FunctionHeader getHeader(Method method) {
|
416
|
|
- StoredType returnType = loadStoredType(method.getAnnotatedReturnType());
|
417
|
|
-
|
418
|
|
- FunctionParameter[] parameters = new FunctionParameter[method.getParameterCount()];
|
419
|
|
- AnnotatedType[] parameterTypes = method.getAnnotatedParameterTypes();
|
|
426
|
+ return getHeader(
|
|
427
|
+ method.getAnnotatedReturnType(),
|
|
428
|
+ method.getAnnotatedParameterTypes(),
|
|
429
|
+ method.getTypeParameters(),
|
|
430
|
+ method.getAnnotatedExceptionTypes());
|
|
431
|
+ }
|
|
432
|
+
|
|
433
|
+ private FunctionHeader getHeader(
|
|
434
|
+ AnnotatedType javaReturnType,
|
|
435
|
+ AnnotatedType[] parameterTypes,
|
|
436
|
+ TypeVariable<Method>[] javaTypeParameters,
|
|
437
|
+ AnnotatedType[] exceptionTypes)
|
|
438
|
+ {
|
|
439
|
+ StoredType returnType = javaReturnType == null ? BasicTypeID.VOID.stored : loadStoredType(javaReturnType);
|
|
440
|
+
|
|
441
|
+ FunctionParameter[] parameters = new FunctionParameter[parameterTypes.length];
|
420
|
442
|
for (int i = 0; i < parameters.length; i++) {
|
421
|
443
|
parameters[i] = new FunctionParameter(loadStoredType(parameterTypes[i]));
|
422
|
444
|
}
|
423
|
445
|
|
424
|
|
- TypeVariable<Method>[] javaTypeParameters = method.getTypeParameters();
|
425
|
446
|
TypeParameter[] typeParameters = new TypeParameter[javaTypeParameters.length];
|
426
|
447
|
for (int i = 0; i < javaTypeParameters.length; i++) {
|
427
|
448
|
TypeVariable<Method> javaTypeParameter = javaTypeParameters[i];
|
|
@@ -431,7 +452,6 @@ public class JavaNativeModule {
|
431
|
452
|
typeParameters[i].addBound(new ParameterTypeBound(CodePosition.NATIVE, loadType(bound)));
|
432
|
453
|
}
|
433
|
454
|
|
434
|
|
- AnnotatedType[] exceptionTypes = method.getAnnotatedExceptionTypes();
|
435
|
455
|
if (exceptionTypes.length > 1)
|
436
|
456
|
throw new IllegalArgumentException("A method can only throw a single exception type!");
|
437
|
457
|
|
|
@@ -518,10 +538,25 @@ public class JavaNativeModule {
|
518
|
538
|
return org.objectweb.asm.Type.getDescriptor(cls);
|
519
|
539
|
}
|
520
|
540
|
|
|
541
|
+ private static String getMethodDescriptor(java.lang.reflect.Constructor constructor) {
|
|
542
|
+ return org.objectweb.asm.Type.getConstructorDescriptor(constructor);
|
|
543
|
+ }
|
|
544
|
+
|
521
|
545
|
private static String getMethodDescriptor(Method method) {
|
522
|
546
|
return org.objectweb.asm.Type.getMethodDescriptor(method);
|
523
|
547
|
}
|
524
|
548
|
|
|
549
|
+ private static JavaMethod getMethod(JavaClass cls, java.lang.reflect.Constructor constructor) {
|
|
550
|
+ return new JavaMethod(
|
|
551
|
+ cls,
|
|
552
|
+ JavaMethod.Kind.CONSTRUCTOR,
|
|
553
|
+ "<init>",
|
|
554
|
+ false,
|
|
555
|
+ getMethodDescriptor(constructor),
|
|
556
|
+ constructor.getModifiers(),
|
|
557
|
+ false);
|
|
558
|
+ }
|
|
559
|
+
|
525
|
560
|
private static JavaMethod getMethod(JavaClass cls, Method method, StoredType result) {
|
526
|
561
|
JavaMethod.Kind kind;
|
527
|
562
|
if (method.getName().equals("<init>"))
|