Skip to content

Commit

Permalink
Documented the models of CodeGen
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyknic committed Aug 6, 2015
1 parent 63a03e3 commit 1198a2c
Show file tree
Hide file tree
Showing 41 changed files with 406 additions and 55 deletions.
Expand Up @@ -19,11 +19,21 @@
import java.util.function.Consumer;

/**
*
* Trait for code generator models that can be called.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface Callable<T> {

/**
* Calls the specified {@link Consumer} with this object as the parameter.
* This method exists so that methods can operate on an object without
* breaking the flow.
*
* @param procedure the procedure to call
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default public T call(Consumer<T> procedure) {
procedure.accept((T) this);
Expand Down
Expand Up @@ -17,10 +17,17 @@
package com.speedment.codegen.lang.interfaces;

/**
*
* Trait for code generator models that can be deep-copied.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface Copyable<T extends Copyable<T>> {

/**
* Create a deep copy of this model.
*
* @return the copy
*/
public T copy();
}
Expand Up @@ -20,17 +20,31 @@
import java.util.List;

/**
*
* A trait for models that contains {@link AnnotationUsage} components.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasAnnotationUsage<T extends HasAnnotationUsage<T>> {

/**
* Adds the specified {@link AnnotationUsage} to this model.
*
* @param annotation the new child
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(final AnnotationUsage annotation) {
getAnnotations().add(annotation);
return (T) this;
}

/**
* Returns a list of all the annotation usages in this model.
* <p>
* The list returned must be mutable for changes!
*
* @return the annotations.
*/
List<AnnotationUsage> getAnnotations();
}
Expand Up @@ -21,23 +21,44 @@
import java.util.List;

/**
*
* A trait for models that contain {@link ClassOrInterface} components.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasClasses<T extends HasClasses<T>> {

/**
* Adds the specified {@link ClassOrInterface} to this model.
*
* @param member the new child
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(ClassOrInterface<?> member) {
getClasses().add(member);
return (T) this;
}

/**
* Adds all the specified {@link ClassOrInterface} members to this model.
*
* @param members the new children
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T addAllClasses(Collection<? extends ClassOrInterface<?>> members) {
getClasses().addAll(members);
return (T) this;
}

/**
* Returns a list of all the classes, interfaces and enumerations in this
* model.
* <p>
* The list returned must be mutable for changes!
*
* @return all the classes
*/
List<ClassOrInterface<?>> getClasses();
}
29 changes: 28 additions & 1 deletion src/main/java/com/speedment/codegen/lang/interfaces/HasCode.java
Expand Up @@ -16,20 +16,47 @@
*/
package com.speedment.codegen.lang.interfaces;

import java.util.Collections;
import java.util.List;

/**
*
* A trait for models that contains code.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasCode<T extends HasCode<T>> {

/**
* Adds the specified row of code to this model.
*
* @param row the row
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(String row) {
getCode().add(row);
return (T) this;
}

/**
* Adds all the specified rows to this model.
*
* @param rows the rows
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(String... rows) {
Collections.addAll(getCode(), rows);
return (T) this;
}

/**
* Returns a list of the code rows of this model.
* <p>
* The list returned must be mutable for changes!
*
* @return the code rows
*/
List<String> getCode();
}
Expand Up @@ -19,11 +19,25 @@
import java.util.Optional;

/**
*
* A trait for models that can have a comment.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasComment<T extends HasComment<T>> {

/**
* If a comment is attached to this model, return it. Else <code>empty</code>.
*
* @return the comment or empty
*/
Optional<String> getComment();

/**
* Sets the comment of this model. The comment may have multiple rows.
*
* @param comment the comment
* @return a reference to this
*/
T setComment(String comment);
}
Expand Up @@ -20,17 +20,31 @@
import java.util.List;

/**
*
* A trait for models that contain {@link Constructor} components.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasConstructors<T extends HasConstructors<T>> {

/**
* Adds the specified {@link Constructor} to this model.
*
* @param constr the new child
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(final Constructor constr) {
getConstructors().add(constr);
return (T) this;
}

/**
* Returns a list of all the constructors of this model.
* <p>
* The list returned must be mutable for changes!
*
* @return the constructors
*/
List<Constructor> getConstructors();
}
Expand Up @@ -21,23 +21,43 @@
import java.util.List;

/**
*
* A trait for models that contain {@link Field} components.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasFields<T extends HasFields<T>> {

/**
* Adds the specified {@link Field} to this model.
*
* @param field the new child
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(final Field field) {
getFields().add(field);
return (T) this;
}

/**
* Adds all the specified {@link Field} members to this model.
*
* @param fields the new children
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T addAllFields(final Collection<? extends Field> fields) {
getFields().addAll(fields);
return (T) this;
}

/**
* Returns a list of all the fields in this model.
* <p>
* The list returned must be mutable for changes!
*
* @return all the fields
*/
List<Field> getFields();
}
Expand Up @@ -20,17 +20,31 @@
import java.util.List;

/**
*
* A trait for models that contain {@link Generic} components.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasGenerics<T extends HasGenerics<T>> {

/**
* Adds the specified {@link Generic} to this model.
*
* @param generic the new child
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(final Generic generic) {
getGenerics().add(generic);
return (T) this;
}

/**
* Returns a list of all the generics in this model.
* <p>
* The list returned must be mutable for changes!
*
* @return the generics
*/
List<Generic> getGenerics();
}
Expand Up @@ -20,17 +20,32 @@
import java.util.List;

/**
*
* A trait for models that have interfaces as supertypes.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasImplements<T extends HasImplements<T>> {

/**
* Adds the specified supertype to this model. The type should represent
* an interface.
*
* @param interf the new child
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(final Type interf) {
getInterfaces().add(interf);
return (T) this;
}

/**
* Returns a list of all the interfaces implemented by this model.
* <p>
* The list returned must be mutable for changes!
*
* @return the interfaces
*/
List<Type> getInterfaces();
}
Expand Up @@ -20,17 +20,31 @@
import java.util.List;

/**
*
* A trait for models that contain {@link Import} components.
*
* @author Emil Forslund
* @param <T> The extending type
*/
public interface HasImports<T extends HasImports<T>> {

/**
* Adds the specified {@link Import} to this model.
*
* @param dep the new child
* @return a reference to this
*/
@SuppressWarnings("unchecked")
default T add(final Import dep) {
getImports().add(dep);
return (T) this;
}

/**
* Returns a list of all imports in this model.
* <p>
* The list returned must be mutable for changes!
*
* @return the imports
*/
List<Import> getImports();
}

0 comments on commit 1198a2c

Please sign in to comment.