Skip to content

Commit

Permalink
Documented JavaGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyknic committed Aug 6, 2015
1 parent 39ea9fd commit dab5ea6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 53 deletions.
54 changes: 11 additions & 43 deletions src/main/java/com/speedment/codegen/base/DefaultGenerator.java
Expand Up @@ -22,8 +22,7 @@
import java.util.stream.Stream;

/**
* A generator that can have multiple transform factories. Step-wise generation
* will be handled by concatenating transform into a <code>BridgeTransform</code>.
* The default implementation of the {@link Generator} interface.
*
* @author Emil Forslund
*/
Expand All @@ -34,10 +33,11 @@ public class DefaultGenerator implements Generator {
private final DefaultRenderStack renderStack;

/**
* Creates a new generator. This constructor will use a <code>DefaultDependnecyManager</code>
* with no parameters to handle any dependencies.
* Creates a new generator. This constructor will use a
* {@link DefaultDependencyManager} with no parameters to handle any
* dependencies.
*
* @param factories The factories to use.
* @param factories the factories to use
*/
public DefaultGenerator(TransformFactory... factories) {
this(new DefaultDependencyManager(), factories);
Expand All @@ -46,8 +46,8 @@ public DefaultGenerator(TransformFactory... factories) {
/**
* Creates a new generator.
*
* @param mgr The dependency manager to use.
* @param factories The factories to use.
* @param mgr the dependency manager to use
* @param factories the factories to use
*/
public DefaultGenerator(DependencyManager mgr, TransformFactory... factories) {
this.factories = Arrays.asList(factories);
Expand All @@ -56,47 +56,23 @@ public DefaultGenerator(DependencyManager mgr, TransformFactory... factories) {
}

/**
* @return the dependency manager.
* {@inheritDoc}
*/
@Override
public DependencyManager getDependencyMgr() {
return mgr;
}

/**
* Returns the current rendering stack. The top element will be the one most
* recent rendered and the bottom one will be the element that was first
* passed to the generator. Elements are removed from the stack once they
* have finished rendering.
*
* If an element needs to access its parent, it can call this method and
* peek on the second element from the top.
*
* The elements in the Stack will be of Object type. That is because the
* framework doesn't put any constraints on what can be rendered.
* The elements should not be cast directly to the model class but rather
* to an interface describing the properties you need to read. That way,
* the design remains dynamic even if the exact implementation isn't the
* same.
*
* The returned Stack will be immutable.
*
* @return the current rendering stack.
* {@inheritDoc}
*/
@Override
public RenderStack getRenderStack() {
return renderStack;
}

/**
* Renders the specified model into a stream of code models. This is used
* internally to provide the other interface methods.
*
* @param <A> The input type.
* @param <B> The expected output type.
* @param from The model to generate.
* @param to The model type to transform to.
* @return A stream of meta objects.
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
Expand All @@ -117,15 +93,7 @@ public <A, B> Stream<Meta<A, B>> metaOn(A from, Class<B> to) {
}

/**
* Transforms the specified model using the specified transform from the
* specified installer.
*
* @param <A> The input type.
* @param <B> The expected output type.
* @param transform The transform to use.
* @param model The inputed model.
* @param factory The factory used when instantiating the transform.
* @return The meta object if successful, else empty.
* {@inheritDoc}
*/
@Override
public <A, B> Optional<Meta<A, B>> transform(Transform<A, B> transform, A model, TransformFactory factory) {
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/com/speedment/codegen/base/Generator.java
Expand Up @@ -42,16 +42,10 @@ public interface Generator {
* recent rendered and the bottom one will be the element that was first
* passed to the generator. Elements are removed from the stack once they
* have finished rendering.
*
* <p>
* If an element needs to access its parent, it can call this method and
* peek on the second element from the top.
*
* The elements in the Stack will be of Object type. That is because the
* framework doesn't put any constraints on what can be rendered. The
* elements should not be cast directly to the model class but rather to an
* interface describing the properties you need to read. That way, the
* design remains dynamic even if the exact implementation isn't the same.
*
* @return the current rendering stack
*
* @see RenderStack
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/com/speedment/codegen/java/JavaGenerator.java
Expand Up @@ -21,7 +21,13 @@
import com.speedment.codegen.base.DefaultGenerator;

/**
*
* A hook to the generator that can be passed to various stages in the pipeline.
* Contains multiple methods for generating model-to-model or model-to-text.
* <p>
* The <code>JavaGenerator</code> comes with all the basic types
* of the java language and the 'java.lang'-package ignored in imports and
* has views of all the basic language concepts preinstalled.
*
* @author Emil Forslund
*/
public class JavaGenerator extends DefaultGenerator {
Expand All @@ -31,11 +37,23 @@ public class JavaGenerator extends DefaultGenerator {
"double", "boolean"
};

/**
* Instantiates the JavaGenerator.
*/
public JavaGenerator() {
this(new JavaTransformFactory());
}

public JavaGenerator(TransformFactory... installers) {
super(new DefaultDependencyManager("java.lang", types), installers);
/**
* Instantiates the JavaGenerator using an array of custom
* {@link TransformFactory}.
* <p>
* Warning! If you use this constructor, no transforms will be installed
* by default!
*
* @param factories an array of the factories to use
*/
public JavaGenerator(TransformFactory... factories) {
super(new DefaultDependencyManager("java.lang", types), factories);
}
}

0 comments on commit dab5ea6

Please sign in to comment.