dukeify / fake-jni

An implementation of the JNI and JVMTI with support for direct interaction between natively registered classes and JVM objects.
Other
27 stars 10 forks source link

Support inner classes #37

Open Matthewacon opened 5 years ago

Matthewacon commented 5 years ago

When defining an inner class, the first parameter for each constructor must be an instance pointer to the encapsulating class:

using namespace FakeJni;

class Outer : public JObject {
public:
 DEFINE_CLASS_NAME("com/example/Outer")

 class Inner : public JObject {
 public:
  DEFINE_CLASS_NAME("com/example/Outer$Inner")
  const Outer& outer;

  explicit Inner(Outer * const inst) :
    outer(*inst)
  {}
 };
};

BEGIN_NATIVE_DESCRIPTOR(Outer)
 {Constructor<Outer> {}}
END_NATIVE_DESCRIPTOR

BEGIN_NATIVE_DESCRIPTOR(Outer::Inner)
 {Constructor<Outer::Inner, Outer *> {}}
END_NATIVE_DESCRIPTOR

For the purposes of JVM functionality compliance, all Outer::Inner instances will be constrained to an encapsulating instance of Outer.

meme commented 5 years ago

As a nit-pick, is the class identifier not delimited by a $?

Matthewacon commented 5 years ago

As a nit-pick, is the class identifier not delimited by a $?

Yup, completely forgot about that :+1: