|
||
---|---|---|
.. | ||
README.md |
README.md
Matter Code Generator
This system generates Java classes for Matter clusters, device types, and related functionality. It uses Handlebars templates to transform Matter.js protocol definitions into Java code suitable for serialization.
Overview
The code generator consists of:
app.ts
: Main generator script that processes Matter.js definitions and generates Java code- Template files in
src/templates/
:cluster-class.hbs
: Template for individual cluster classesbase-cluster.hbs
: Template for the base cluster classcluster-constants.hbs
: Template for cluster constantscluster-registry.hbs
: Template for cluster registrydevice-types-class.hbs
: Template for device type definitionsdata-types-class.hbs
: Template for data type definitions
Main Generator (app.ts)
The generator script:
- Imports Matter.js protocol definitions
- Maps Matter.js data types to Java types
- Processes cluster inheritance and references between clusters
- Compiles Handlebars templates
- Generates Java code files in the
out/
directory
Templates
cluster-class.hbs
Generates individual cluster classes with:
- Cluster attributes
- Struct definitions
- Enum definitions
- Command methods
- toString() implementation
base-cluster.hbs
Generates the base cluster class with:
- Common fields and methods
- Global struct/enum definitions
cluster-constants.hbs
Generates constants for:
- Channel names
- Channel labels
- Channel IDs
- Channel type UIDs
note this is not currently used yet in the binding
cluster-registry.hbs
Generates a registry mapping cluster IDs to cluster classes
device-types-class.hbs
Generates device type definitions and mappings
Usage
- Install dependencies:
- Run the generator:
- Generated Java files will be in the
out/
directory
npm install && npm run start
Note the the maven pom.xml will execute these steps when building the project, including linting the generated files and moving them from the out directory to the primary addon src directory.
Handlebars Helpers
The generator includes several Handlebars helpers for string manipulation to assist in Java naming conventions:
asUpperCase
: Convert to uppercaseasLowerCase
: Convert to lowercaseasUpperCamelCase
: Convert to UpperCamelCaseasLowerCamelCase
: Convert to lowerCamelCaseasTitleCase
: Convert to Title CaseasEnumField
: Convert to ENUM_FIELD formatasHex
: Convert number to hex string- and many others