Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Plugin Development

Shaun Francis edited this page Sep 7, 2017 · 7 revisions

Class Generator Plugin

All Class Generator Plugins implement the ClassGeneratorPlugin interface:

public interface ClassGeneratorPlugin {

    TypeSpec.Builder generateWith(final TypeSpec.Builder typeSpecBuilder,
                                  final ClassDefinition classDefinition,
                                  final JavaGeneratorFactory javaGeneratorFactory,
                                  final ClassNameFactory classNameFactory,
                                  final GenerationContext generationContext);
}
  • TypeSpec.Builder - The Java Poet TypeSpec Builder use this to add new fields and methods that generate the Java Class. Should be the returned TypeSpec.Builder.
  • ClassDefinition - This has definition information about the Class being generated, the type class, and child definitions
  • JavaGeneratorFactory - Factory for converting child definitions into generators
  • ClassNameFactory - Returns the Java Poet TypeName for a child definition, this will also apply any TypeNamePlugins before returning the TypeName
  • GenerationContext - Can supply the source filename, package name, and output directory path.

Type Name Plugins

All Type Name Plugins implement the TypeNamePlugin interface:

public interface TypeNamePlugin {

    TypeName modifyTypeName(final TypeName typeName, final Definition definition);
}
  • TypeName - Java Poet TypeName this can be wrapped then returned, for example when creating Optionals, or a completely different TypeName can be returned.
  • Definition - The definition that requires a TypeName, this can be interrogated for type.
Clone this wiki locally