Class CodeWriter
java.lang.Object
net.codecrete.windowsapi.writer.CodeWriter
Generates Java code for a given scope of types, functions, and constants.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe Java class name of the current Java fileprotected final net.codecrete.windowsapi.writer.GenerationContextShared generation context.protected NamespaceNamespace of the current Java fileprotected StringThe Java package name of the current Java fileprotected TypeThe metadata type for the current Java file (if any)protected final PrimitiveVoid type.protected PrintWriterPrint writer for the current Java file -
Constructor Summary
ConstructorsConstructorDescriptionCodeWriter(Metadata metadata, Path outputDirectory, EventListener eventListener) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected intReturns the next bit field number and increases it.protected net.codecrete.windowsapi.writer.GenerationContextGets the code generation context.voidsetBasePackage(String basePackage) Sets the base package.voidsetDryRun(boolean isDryRun) Sets if this code writer should execute a dry run without creating files and directories.protected StringtoJavaPackageName(String namespace) Converts the namespace name to a Java package name.protected voidCreates a new Java source file for the specified package and class name and executes the action.voidWrites the Java code for the specified scope of types, functions, and constants.voidwriteAll()Writes the Java code for all types, functions, and constants.protected voidwriteCommentWithNotes(String comment, String... notes) Writes a comment with notes.protected voidwriteDocumentationUrl(Type type) Writes the type's documentation URL to the top level comment (if available).
-
Field Details
-
generationContext
protected final net.codecrete.windowsapi.writer.GenerationContext generationContextShared generation context. -
voidType
Void type. -
writer
Print writer for the current Java file -
namespace
Namespace of the current Java file -
type
The metadata type for the current Java file (if any) -
packageName
The Java package name of the current Java file -
className
The Java class name of the current Java file
-
-
Constructor Details
-
CodeWriter
Creates a new instance.- Parameters:
metadata- the metadataoutputDirectory- the output directoryeventListener- the event listener to notify about events
-
-
Method Details
-
setBasePackage
Sets the base package.The base package is prepended to all package names derived from Microsoft's namespace. The default is an empty string, i.e., no further package name is added.
- Parameters:
basePackage- the base package name
-
setDryRun
public void setDryRun(boolean isDryRun) Sets if this code writer should execute a dry run without creating files and directories.Initially, it is set to
false.- Parameters:
isDryRun-truefor dry run,falsefor real run
-
write
Writes the Java code for the specified scope of types, functions, and constants.- Parameters:
scope- the scope
-
writeAll
public void writeAll()Writes the Java code for all types, functions, and constants.This method is used for tests.
-
generationContext
protected net.codecrete.windowsapi.writer.GenerationContext generationContext()Gets the code generation context.- Returns:
- the generation context
-
withFile
Creates a new Java source file for the specified package and class name and executes the action.While the action is executed, the namespace, type, package name, class name and the print writer are available through instance variables.
If the action is successful, the event listener is notified that a new file has been created.
- Parameters:
namespace- the namespacetype- the metadata type that is the basis for the Java file (ornull).className- the Java class nameaction- the action to execute
-
consumeBitFieldNumber
protected int consumeBitFieldNumber()Returns the next bit field number and increases it.- Returns:
- the bit field number
-
toJavaPackageName
-
writeCommentWithNotes
-
writeDocumentationUrl
Writes the type's documentation URL to the top level comment (if available).- Parameters:
type- the type
-