PointerIO
getInstance(Type type) {
if (type == null)
return null;
- PointerIO io = ios.get(type);
+ PointerIO io = null;
+
+ if( type instanceof ResolvedType ) {
+ io = ios.get(((ResolvedType) type).getErasedType());
+ }
+ if( io == null ) {
+ io = ios.get(type);
+ }
if (io == null) {
final Class> cl = Utils.getClass(type);
if (cl != null) {
- if (cl == Pointer.class)
- io = getPointerInstance(((ParameterizedType)type).getActualTypeArguments()[0]);
+ if (cl == Pointer.class) {
+ if( type instanceof ResolvedType ) {
+ io = getPointerInstance(((ResolvedType)type).getTypeParameters().get(0));
+ } else {
+ io = getPointerInstance(((ParameterizedType)type).getActualTypeArguments()[0]);
+ }
+ }
else if (StructObject.class.isAssignableFrom(cl))
io = getInstance(StructIO.getInstance((Class)cl, type));
else if (Callback.class.isAssignableFrom(cl))
@@ -162,7 +178,11 @@ else if (Callback.class.isAssignableFrom(cl))
else if (NativeObject.class.isAssignableFrom(cl))
io = new CommonPointerIOs.NativeObjectPointerIO(type);
else if (IntValuedEnum.class.isAssignableFrom(cl)) {
- if (type instanceof ParameterizedType) {
+ if (type instanceof ResolvedType) {
+ ResolvedType enumType = ((ResolvedType)type).getTypeParameters().get(0);
+ io = new CommonPointerIOs.IntValuedEnumPointerIO(enumType.getErasedType());
+ }
+ else if (type instanceof ParameterizedType) {
Type enumType = ((ParameterizedType)type).getActualTypeArguments()[0];
if (enumType instanceof Class)
io = new CommonPointerIOs.IntValuedEnumPointerIO((Class)enumType);
diff --git a/src/main/velocity/org/bridj/StructIO.java b/src/main/velocity/org/bridj/StructIO.java
index 7a6394c7..e07e7a6b 100644
--- a/src/main/velocity/org/bridj/StructIO.java
+++ b/src/main/velocity/org/bridj/StructIO.java
@@ -131,14 +131,14 @@ public final void writeFieldsToNative(StructObject struct) {
if (fd.isArray)
continue;
- Object value = fd.field.get(struct);
+ Object value = fd.field.getRawMember().get(struct);
if (value instanceof NativeObject) {//fd.isNativeObject) {
if (value != null)
BridJ.writeToNative((NativeObject)value);
continue;
}
Pointer ptr = struct.peer.offset(fd.byteOffset);
- Type tpe = fd.isNativeObject || fd.isArray ? fd.nativeTypeOrPointerTargetType : fd.field.getGenericType();
+ Type tpe = fd.isNativeObject || fd.isArray ? fd.nativeTypeOrPointerTargetType : fd.field.getType();
ptr = ptr.as(tpe);
ptr = fixIntegralTypeIOToMatchLength(ptr, fd.byteLength, fd.arrayLength);
@@ -166,7 +166,7 @@ public final void readFieldsFromNative(StructObject struct) {
continue;
Pointer ptr = struct.peer.offset(fd.byteOffset);
- Type tpe = fd.isNativeObject || fd.isArray ? fd.nativeTypeOrPointerTargetType : fd.field.getGenericType();
+ Type tpe = fd.isNativeObject || fd.isArray ? fd.nativeTypeOrPointerTargetType : fd.field.getType();
ptr = ptr.as(tpe);
ptr = fixIntegralTypeIOToMatchLength(ptr, fd.byteLength, fd.arrayLength);
Object value;
@@ -176,7 +176,7 @@ public final void readFieldsFromNative(StructObject struct) {
} else {
value = ptr.get();
}
- fd.field.set(struct, value);
+ fd.field.getRawMember().set(struct, value);
if (value instanceof NativeObject) {//if (fd.isNativeObject) {
if (value != null)
diff --git a/src/test/java/org/bridj/StructFieldDeclarationTest.java b/src/test/java/org/bridj/StructFieldDeclarationTest.java
new file mode 100644
index 00000000..45102fbc
--- /dev/null
+++ b/src/test/java/org/bridj/StructFieldDeclarationTest.java
@@ -0,0 +1,30 @@
+package org.bridj;
+
+import java.util.List;
+
+import org.bridj.ann.Field;
+import org.junit.Test;
+import static org.hamcrest.MatcherAssert.*;
+import static org.hamcrest.CoreMatchers.*;
+
+public class StructFieldDeclarationTest {
+
+ public static class BasicFieldStruct extends StructObject {
+ @Field(0)
+ public int intField;
+ }
+
+ public static class StaticNestedStruct extends StructObject {
+ @Field(0)
+ public BasicFieldStruct structField;
+ }
+
+ public static class GenericNestedStruct extends StructObject {
+ @Field(0)
+ public S structField;
+ }
+
+ public static class NestedStructOfBasicFieldStruct
+ extends GenericNestedStruct> extends StructObject {
+ @Field(0)
+ public S getStruct() {
+ return io.getNativeObjectField(this, 0);
+ }
+
+ public T setStruct( S struct ) {
+ io.setNativeObjectField(this, 0, struct);
+ return (T)this;
+ }
+ }
+
+ public static class StructOfInteger extends StructObject {
+ @Field(0)
+ public int getField() {
+ return io.getIntField(this, 0);
+ }
+
+ public StructOfInteger setField( int field ) {
+ io.setIntField(this, 0, field);
+ return this;
+ }
+ }
+
+ public static class NestedStructOfInteger
+ extends AbstractStructField