nativelibs4java / BridJ

BridJ: blazing fast Java / C / C++ interop
https://code.google.com/archive/p/bridj/
Other
289 stars 77 forks source link

Improve Type Resolution #91

Open ctrimble opened 7 years ago

ctrimble commented 7 years ago

NOTE: This PR is not complete, but the test suite is passing. Looking for feedback. Also, it is based on #90, so that should be merged before this PR, or this PR should be rebased.

This PR aims to rework type resolution in BridJ, so that resolution code is off loaded to a third party library and to support more complex generics in classes extending StructObject. Once merged, the following struct will work with BridJ:

  public static abstract class AbstractStructField<S extends StructObject, T extends AbstractStructField<S, T>> 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;
    }
  }

  // this is the struct that will now work as expected.
  public static class NestedStructOfInteger
    extends AbstractStructField<StructOfInteger, NestedStructOfInteger> {}

Status: Code to support generic resolution has been introduced and a test called StructGenericsTest has been added to verify that structures of this type now work.

TODO: Remove dead code dealing directly with Java's type classes.

Build Changes:

Fixes #59

ctrimble commented 7 years ago

I scanned the code base for ParameterizedType and attempted to remove it. There is still a lot of resolution code happening in CRuntime and its subclasses. I would like to remove ParameterizedType, TypeVariable, etc from the codebase, to make sure resolution is consistent, but it may need to happen over several PRs.