ExampleGenerator

Class

This tool is able to generate examples for using elements.

Extends

Object

Modifiers

public

// Randomly-generated example
new ExampleGenerator(element).generateShort();
new ExampleGenerator(element).generateLong();

Constructors


new ExampleGenerator (AnnotatedElement)

Constructor
No description is available for this element.
IndexTypeName
1AnnotatedElementelement
Return Type

ExampleGenerator

Modifiers

public

// Randomly-generated example
final ExampleGenerator generator = new ExampleGenerator(element);
generator.generateShort();
generator.generateLong();

Fields


element

Field

The element for generation.

Type

AnnotatedElement

Modifiers

protected final

// Randomly-generated example
final AnnotatedElement element = generator.element;
assert element.isAnnotationPresent(annotationClass);
element.getAnnotation(clazz);
element.getAnnotationsByType(annotationClass);

builder

Field

The current builder being written to. This is replaced before every synchronised generate call.

Type

StringBuilder

Modifiers

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)

Method

Gets 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.

IndexTypeName
1Classtype
Return Type

String

Modifiers

protected

// Randomly-generated example
final String string = generator.getTypeName(type);
assert string.equals(anObject);
assert string.length() == 70;
string.toString();

generateConstructor (Constructor, boolean)

Method

Generates an example constructor access and uses the result in some way. All of this is generated based on what is available for the constructor.

IndexTypeName
1Constructorconstructor
2booleanextras
Return Type

void

Modifiers

protected

// Randomly-generated example
generator.generateConstructor(constructor, extras);

generateMethod (Method, boolean)

Method

Generates an example method call and uses the result in some way. All of this is generated based on what is available for the method.

IndexTypeName
1Methodmethod
2booleanextras
Return Type

void

Modifiers

protected

// Randomly-generated example
generator.generateMethod(method, extras);

generateField (Field, boolean)

Method

Generates an example field access and uses the result in some way. All of this is generated based on what is available for the field.

IndexTypeName
1Fieldfield
2booleanextras
Return Type

void

Modifiers

protected

// Randomly-generated example
generator.generateField(field, extras);

generateAnnotation (Class, boolean)

Method

Generates 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.

IndexTypeName
1Classtype
2booleanextras
Return Type

void

Modifiers

protected

// Randomly-generated example
generator.generateAnnotation(type, extras);

generateClass (Class, boolean)

Method

Generates 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.

IndexTypeName
1Classtype
2booleanextras
Return Type

void

Modifiers

protected

// Randomly-generated example
generator.generateClass(type, extras);

generateShort ()

Method

Generates 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.

Return Type

String

Modifiers

public synchronized

// Randomly-generated example
final String string = generator.generateShort();
assert string.equals(anObject);
assert string.length() == 73;
string.toString();

generateLong ()

Method

Generates 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.

Return Type

String

Modifiers

public synchronized

// Randomly-generated example
final String string = generator.generateLong();
assert string.equals(anObject);
assert string.length() == 83;
string.toString();