ExampleGenerator
Class
This tool is able to generate examples for using elements.
Object
public
// Randomly-generated example
new ExampleGenerator(element).generateShort();
new ExampleGenerator(element).generateLong();
Constructors
new ExampleGenerator (AnnotatedElement)
ConstructorIndex | Type | Name |
---|---|---|
1 | AnnotatedElement | element |
ExampleGenerator
public
// Randomly-generated example
final ExampleGenerator generator = new ExampleGenerator(element);
generator.generateShort();
generator.generateLong();
Fields
element
FieldThe element for generation.
AnnotatedElement
protected final
// Randomly-generated example
final AnnotatedElement element = generator.element;
assert element.isAnnotationPresent(annotationClass);
element.getAnnotation(clazz);
element.getAnnotationsByType(annotationClass);
builder
FieldThe current builder being written to. This is replaced before every synchronised generate call.
StringBuilder
protected transient volatile
// Randomly-generated example
generator.builder = new StringBuilder(sequence);
final StringBuilder builder = generator.builder;
builder.toString();
builder.append(s, start, end);
builder.append(str);
Methods
getTypeName (Class)
MethodGets the usable name of this type in source code.
For example, java.lang.String
would be converted to String
and my.thing.MyClass$Nested
would be converted to Nested
.
Index | Type | Name |
---|---|---|
1 | Class | type |
String
protected
// Randomly-generated example
final String string = generator.getTypeName(type);
assert string.equals(anObject);
assert string.length() == 70;
string.toString();
generateConstructor (Constructor, boolean)
MethodGenerates an example constructor access and uses the result in some way. All of this is generated based on what is available for the constructor.
Index | Type | Name |
---|---|---|
1 | Constructor | constructor |
2 | boolean | extras |
void
protected
// Randomly-generated example
generator.generateConstructor(constructor, extras);
generateMethod (Method, boolean)
MethodGenerates an example method call and uses the result in some way. All of this is generated based on what is available for the method.
Index | Type | Name |
---|---|---|
1 | Method | method |
2 | boolean | extras |
void
protected
// Randomly-generated example
generator.generateMethod(method, extras);
generateField (Field, boolean)
MethodGenerates an example field access and uses the result in some way. All of this is generated based on what is available for the field.
Index | Type | Name |
---|---|---|
1 | Field | field |
2 | boolean | extras |
void
protected
// Randomly-generated example
generator.generateField(field, extras);
generateAnnotation (Class, boolean)
MethodGenerates an example class access and uses the result in some way. All of this is generated based on what is available for the class.
This will attempt to generate a range of static and dynamic examples.
Index | Type | Name |
---|---|---|
1 | Class | type |
2 | boolean | extras |
void
protected
// Randomly-generated example
generator.generateAnnotation(type, extras);
generateClass (Class, boolean)
MethodGenerates an example class access and uses the result in some way. All of this is generated based on what is available for the class.
This will attempt to generate a range of static and dynamic examples.
Index | Type | Name |
---|---|---|
1 | Class | type |
2 | boolean | extras |
void
protected
// Randomly-generated example
generator.generateClass(type, extras);
generateShort ()
MethodGenerates an example of the element being used.
The result is not guaranteed to be valid (or even usable) but may provide some indication of how to use it.
This will always produce a short 1-to-2 line example.
String
public synchronized
// Randomly-generated example
final String string = generator.generateShort();
assert string.equals(anObject);
assert string.length() == 73;
string.toString();
generateLong ()
MethodGenerates an example of the element being used.
The result is not guaranteed to be valid (or even usable) but may provide some indication of how to use it.
The long example will try and include some uses of the result, such as storing and using the result of a method call, or creating a new instance with a constructor and then calling some methods from the class.
String
public synchronized
// Randomly-generated example
final String string = generator.generateLong();
assert string.equals(anObject);
assert string.length() == 83;
string.toString();