Message Library IntelliJ Plugin
Experimentation in writing an IntelliJ plugin for an hypothetical message library.
Core Concept
The message library use JSon Schema to dynamically define message data model. Data is extracted from message using JSon Pointer defined as Java literal strings and, as Java has no knowledge of JSon Pointer, the plugin helps to validate the JSon Pointers by finding properties in JSon schema linked to message type.
Example
A schema is liked to a message type by Java annotation:
@SchemaFile("/MyType.json")
public class MyType implements MessageType {
}
Then data can be extracted from the message using JSon Pointer:
public void process(Message<MyType> message) {
System.out.println(message.getString("/address/mainStreet"));
}
The Plugin
The plugin uses two IntelliJ feature to validate JSon Pointer:
- an indexer (
com.github.madbrain.jschema.ClassSchemaIndex
) to build an index from class name to linked schema - an annotator (
com.github.madbrain.jschema.ExtractorSpecAnnotator
) to find calls toMessage.getString()
and validate the JSon pointer in the argument using the schema linked to the actual type of the the generic parameter.
Usage
- Import project in IntelliJ
- Run graddle task
runIde
- Use
example-project
as project in the runtime IDE
TODO
- the code is extremely dirty: better use the availables APIs?
- write tests using Annotator Test Tutorial
Links
This plugin is mostly based on: