Interface EmitterContext
public interface EmitterContext
What an emitter is given to write one contract's classes.
-
Method Summary
Modifier and TypeMethodDescriptionRecords that a generated method cannot represent a construct, and returns the statement its body consists of instead: one that throwsUnsupportedOperationExceptionwith the reason and, where there is one, the remedy.default List<InvalidRequestCase> invalidRequestCases(String location) The invalid-request cases of an operation, in the order its generatedCASESlists them: what an emitter that renders cases shapes its code by.model()The contract.names()The core classes, whose names an emitter's companions follow.settings()How the project has asked for the classes to be generated.default voidWrites one file that belongs on no classpath -- a mapping file, part of an archive -- replacing any file already written at that path in this run.default voidWrites one text file that belongs on no classpath, UTF-8 encoded, aswriteFile(String, byte[])does.voidWrites one Java source file, replacing any file already written for that class in this run.voidwriteResource(String path, String content) Writes one resource file, replacing any file already written at that path in this run -- a properties file a generated or hand-written class reads throughgetResourceAsStream, for instance.
-
Method Details
-
model
ContractModel model()The contract.- Returns:
- the model
-
settings
Settings settings()How the project has asked for the classes to be generated.- Returns:
- the settings
-
names
ClassNames names()The core classes, whose names an emitter's companions follow.- Returns:
- the class names
-
writeJava
Writes one Java source file, replacing any file already written for that class in this run.- Parameters:
packageName- the packagesimpleName- the class's simple namesource- the whole compilation unit
-
writeResource
Writes one resource file, replacing any file already written at that path in this run -- a properties file a generated or hand-written class reads throughgetResourceAsStream, for instance.pathis/-separated and relative to the resource root, and may nest in directories, such as"META-INF/emitter/service.properties". It may not be absolute, and may not use empty,.or..segments.- Parameters:
path- the resource's path within the resource rootcontent- the resource's content, written UTF-8
-
writeFile
Writes one file that belongs on no classpath -- a mapping file, part of an archive -- replacing any file already written at that path in this run. The plugin packages these files; it never compiles them or puts them on a classpath.pathfollows the rules ofwriteResource(String, String):/-separated, relative, and without empty,.or..segments. Only an emitter whoseEmitter.produces(java.util.Map)includesOutput.FILESmay call it.- Parameters:
path- the file's path within the emitter's files directorycontent- the file's bytes- Throws:
UnsupportedOperationException- when this context has nowhere to write files: a generation run without a files directory
-
writeFile
Writes one text file that belongs on no classpath, UTF-8 encoded, aswriteFile(String, byte[])does.- Parameters:
path- the file's path within the emitter's files directorycontent- the file's text
-
degraded
Records that a generated method cannot represent a construct, and returns the statement its body consists of instead: one that throwsUnsupportedOperationExceptionwith the reason and, where there is one, the remedy. Every degraded method is reported at the end of generation.- Parameters:
className- the simple name of the class the method is inmethod- the method, as a reader would name it, such asbody(String)finding- the construct it cannot represent- Returns:
- a Java statement, without indentation
-
invalidRequestCases
The invalid-request cases of an operation, in the order its generatedCASESlists them: what an emitter that renders cases shapes its code by. The core derives them before any other emitter runs.- Parameters:
location- the JSON pointer of the operation, such as/paths/~1v1~1users/get- Returns:
- the cases; empty when the operation has none, or there is no such operation
-