Generating your own custom classes

In the case you need to generate custom classes, there are a few things to consider.

First, the class pool (of type RPool, obtained via API.getClassPool()) is the object offering the service of making a new class based on a string of source code. Look at the makeClass(..) methods.

You need to give a name to the class. Two important things are:

  1. The class must be located in a package that is loaded by the Reflex class loader.
  2. You may need to give a unique name to each of your generated classes in a systematic manner.

For point (1), you need to put your generated classes in the reflex.gen package (so the fully-qualified name of your generated classes must start with this package name). Otherwise, make sure the generated classes are part of your working set. But since the working set may change between different runs, and you always want generated classes to be accessible, we strongly recommend that you systematically generate classes in a reflex.gen subpackage of your choice.

For point (2), the Tools class of Reflex offers a service to generate unique names, based on a prefix. For instance:

Tools.generateUniqueIdentifier("reflex.gen.myfwk.GenClass_");

The above will return a unique name for your class, locating it in the appropriate package, and prefixing the simple name of your classes with GenClass_.