Customization - loicoudot/java4cpp-core GitHub Wiki

Customize proxies source code

Java4cpp use FreeMarker templates to generate source code. In the templates xml files, for each customized Java class, you can specify a list of FreeMarker templates files that will be used by java4cpp to generate corresponding source code.

For example, base-templates.xml define for all non customized Java class two FreeMarker template files:

<templates>
   ...
   <datatypes>
      <fallback>
         <sourceTemplates>
            <sourceTemplate>header-template.ftl</sourceTemplate>
            <sourceTemplate>source-template.ftl</sourceTemplate>
         </sourceTemplates>
         ...
     </fallback>
     ...
</templates>

When these templates files are evaluated by FreeMarker, the available data-model associated will be as follow:

  • cppFormatter: a macro to use for formatting generated code in a C++ style manner <@cppFormatter>...</@cppFormatter>
  • class: a ClassModel object

ClassModel

data-model containing all informations about the Java class being analyzed.

  • ClassType type: all the informations about the type of the Java class.
  • List<ClassModel> parameters: For parameterized type, contains the parameterized ClassModel.
  • ClassContent content: all the informations about the content of the class i.e. constructors, methods, fields, inner classes etc.

For example, while analyzing a java.util.List<java.util.Properties>, type contains informations about java.util.List<java.util.Properties>, parameters is a ClassModel of java.util.Properties, and content contains informations of constructors and methods of java.util.List.

ClassType

data-model containing all information about the type parts of a Java class.

  • String javaName: the full name of the Java class i.e. "java.lang.Double".
  • boolean isPrimitive: returns true for primitive int, boolean, double, etc.
  • boolean isEnum: returns true for enums.
  • boolean isArray: returns true for arrays.
  • boolean isInterface: returns true for interfaces.
  • boolean isInnerClass: returns true for inner classes.
  • boolean isThrowable: returns true if classes extends java.lang.Throwable.
  • boolean isCheckedException: returns true for checked exception classes.
  • boolean isCloneable: returns true if classes extends java.lang.Cloneable`.
  • boolean isAbstract: returns true for abstract classes.
  • String cppFullName: returns the full name of the corresponding C++ name after applying name mappings i.e. "java::lang::Object".
  • String cppShortName: returns the name of the corresponding C++ name without the namespace i.e. "Object".
  • ClassModel owner: For inner classes, contains the ClassModel of the owning Java class, for others contains the same ClassModel.
  • String javaSignature: returns the JNI signature i.e. "Ljava/lang/Object;", "double", "[Double" etc.
  • String jniSignature: returns the JNI types i.e. "jobject", "jarray", "jdouble" etc.
  • String jniMethodName: returns the name for the JNI APIs (CallxxxMethods, GetStaticxxxFields) "Object", "Int".
  • String cppType: returns the name of the corresponding C++ type i.e. "double", "const java::lang::Object&", "const std::string&", "boost::optional", etc.
  • String cppReturnType: return the name of the corresponding C++ type for return parameters i.e. "double", "java::lang::Object", "std::string", "boost::optional", etc.
  • ClassModel innerType: for arrays, returns the ClassModel of the next nested type i.e. double for double[], int[] for int[][] etc.
  • ClassModel finalInnerType: for arrays, returns the ClassModel of the final type i.e. double for double[], int for int[][] etc.
  • Map functions: returns a list of custom functions that are defined in the template.xml files. Used to delegate the generation of the translation source code inside each type definition.
  • TemplateMethod addIncludes: a method that can be called to add a list of header files to includes.
  • TemplateMethod addDependencies: a method that can be called to add a dependency.
  • Set<String> includes: lists all the needed includes header files.
  • Set<ClassModel> dependencies: lists all the ClassModel class that this class need.

ClassContent

data-model containing all information about the content parts of a Java class.

  • ClassModel superclass: returns the ClassModel of the corresponding superclass, null if none.
  • List<ClassModel> interfaces: returns the list of ClassModel for interfaces implemented by the class.
  • List<ClassModel> nestedClass: returns the list of ClassModel for classes declared inside the class.
  • List<ConstructorModel> constructors: returns the list of ConstructorModel for mapped constructors.
  • List<FieldModel> staticFields: returns the list of FieldModel for mapped fields.
  • List<MethodModel> methods: returns the list of MethodModel for mapped methods.
  • List<String> enumKeys: for enums, returns the list of declared values.

ConstructorModel

data-model for a constructor.

  • List<ClassModel> parameters: returns the list of ClassModel corresponding to the parameters of the constructor.

FieldModel

data-model for a field.

  • String javaName: returns the java name of the fields.
  • String cppName: returns the corresponding cpp name after applying name mappings.
  • ClassModel type: returns the ClassModel of the field type class.

MethodModel

data-model for a method.

  • String javaName: returns the java name of the method.
  • String cppName: returns the corresponding cpp name after applying name mappings.
  • boolean isStatic: returns true for static method.
  • ClassModel returnType: returns the ClassModel of the return type.
  • List<ClassModel> parameters: returns the list of ClassModel corresponding to the parameters of the method.

Customize data type

⚠️ **GitHub.com Fallback** ⚠️