public class DocGenerator
extends java.lang.Object
Instances of this can read Annotation
s on
Class
es and/or Method
s to format
and document the command's they represent.
The most basic usage of this can be shown below:
@CommandInfo
(
name = {"MyCommand", "MC"},
usage = "MyCommand <Usage>",
description = "This is an example of CommandDoc's standard @CommandInfo annotation"
)
public class MyCommand {
// ...
}
Then...
DocGenerator generator = DocGenerator.getDefaultGenerator()
;
String documentation = generator.getDocForClass(MyCommand.class);
Note: This documentation system is universal, can be applied to any command system that uses Class and/or Method based commands, and works in any JVM language that supports annotations.
ConvertedBy
,
DocConverter
Constructor and Description |
---|
DocGenerator()
Gets a blank DocGenerator with no conversions loaded.
|
DocGenerator(int cacheSize)
Gets a blank DocGenerator with no conversions loaded,
and a cache with the specified max-size.
|
DocGenerator(java.lang.String separator,
int cacheSize)
Gets a blank DocGenerator with no conversions loaded
and with the specified separator, and a cache with the
specified max-size.
|
Modifier and Type | Method and Description |
---|---|
static DocGenerator |
getDefaultGenerator()
Gets a default DocGenerator with standard conversions loaded.
|
java.lang.String |
getDocFor(java.lang.Class<?> cla)
Reads CommandDoc from the provided
Class and returns
the String formatted and from it. |
java.lang.String |
getDocFor(java.lang.reflect.Method method)
Reads CommandDoc from the provided
Method
and returns the String formatted and from it. |
java.util.List<java.lang.String> |
getDocForMethods(java.lang.Class<?> cla)
Reads all
Method s from the
provided Class and returns a List
of CommandDoc of each. |
<T extends java.lang.annotation.Annotation> |
register(java.lang.Class<T> type,
DocConverter<T> converter)
Registers a CommandDoc
Annotation
to this DocGenerator with the provided DocConverter. |
<T extends java.lang.annotation.Annotation> |
register(java.lang.Class<T> type,
java.lang.Object... converterParams)
Registers a CommandDoc
Annotation
to this DocGenerator. |
public DocGenerator()
public DocGenerator(int cacheSize)
Calls to getDocFor(java.lang.Class)
,
getDocFor(java.lang.reflect.Method)
,
and getDocForMethods(java.lang.Class)
also cache the values retrieved
from the invocation as a way to reduce reflection overhead for
repeated calls.
cacheSize
- The of the cache size that contains previously generated CommandDoc
to reduce reflection overhead for repeated calls.public DocGenerator(java.lang.String separator, int cacheSize)
A separator will be appended to the documentation
returned by getDocFor(java.lang.Class)
inbetween
annotation conversions.
By default this is a double newline (\n\n).
Calls to getDocFor(java.lang.Class)
,
getDocFor(java.lang.reflect.Method)
,
and getDocForMethods(java.lang.Class)
also cache the values retrieved
from the invocation as a way to reduce reflection overhead for
repeated calls.
separator
- The separator that occurs inbetween
annotation conversions.cacheSize
- The of the cache size that contains previously generated CommandDoc
to reduce reflection overhead for repeated calls.public static DocGenerator getDefaultGenerator()
This is the simplest way to get a prebuilt working CommandDoc generator with standard annotations.
Additional annotations can be added using register(Class, Object...)
.
public java.lang.String getDocFor(java.lang.Class<?> cla)
Class
and returns
the String formatted and from it.cla
- The Class to get CommandDoc from.public java.lang.String getDocFor(java.lang.reflect.Method method)
Method
and returns the String formatted and from it.method
- The Method to get CommandDoc from.public java.util.List<java.lang.String> getDocForMethods(java.lang.Class<?> cla)
Method
s from the
provided Class
and returns a List
of CommandDoc of each.
Methods read that return empty Strings are not added to the list.
cla
- The Class to get CommandDoc from each methodpublic <T extends java.lang.annotation.Annotation> DocGenerator register(java.lang.Class<T> type, java.lang.Object... converterParams)
Annotation
to this DocGenerator.
An example of a custom CommandDoc conversion annotation can be found in the
DocConverter
documentation.
T
- The type of annotationtype
- The annotation Class type.converterParams
- The parameters necessary to instantiate the proper DocConverter.
java.lang.IllegalArgumentException
- The annotation class provided is not annotated with
@ConvertedBy
,
or an exception is thrown while instantiating the value said
ConvertedBy annotation.
public <T extends java.lang.annotation.Annotation> DocGenerator register(java.lang.Class<T> type, DocConverter<T> converter)
Annotation
to this DocGenerator with the provided DocConverter.
This is not recommended unless you for some reason want to pass an instance variable to the DocConverter you are providing.
An example of a custom CommandDoc conversion annotation can be found in the
DocConverter
documentation.
T
- The type of annotation.type
- The annotation Class type.converter
- The DocConverter to use.