Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generator-translator: Introduce functional interfaces to make transla…
…tor creation more typesafe
- Loading branch information
Emil Forslund
committed
Jun 11, 2018
1 parent
c5a7650
commit 140044c
Showing
8 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...or/src/main/java/com/speedment/generator/translator/component/function/GenerateClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
package com.speedment.generator.translator.component.function; | |||
|
|||
import com.speedment.common.codegen.model.Class; | |||
import com.speedment.runtime.config.trait.HasMainInterface; | |||
import com.speedment.runtime.config.trait.HasName; | |||
|
|||
/** | |||
* Specialization of {@link GeneratorFunction} that produces a CodeGen | |||
* {@code Class}. | |||
* | |||
* @author Emil Forslund | |||
* @since 3.1.4 | |||
*/ | |||
@FunctionalInterface | |||
public interface GenerateClass<DOC extends HasName & HasMainInterface> | |||
extends GeneratorFunction<DOC, Class> {} |
16 changes: 16 additions & 0 deletions
16
...tor/src/main/java/com/speedment/generator/translator/component/function/GenerateEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
package com.speedment.generator.translator.component.function; | |||
|
|||
import com.speedment.common.codegen.model.Enum; | |||
import com.speedment.runtime.config.trait.HasMainInterface; | |||
import com.speedment.runtime.config.trait.HasName; | |||
|
|||
/** | |||
* Specialization of {@link GeneratorFunction} that produces a CodeGen | |||
* {@code Enum}. | |||
* | |||
* @author Emil Forslund | |||
* @since 3.1.4 | |||
*/ | |||
@FunctionalInterface | |||
public interface GenerateEnum<DOC extends HasName & HasMainInterface> | |||
extends GeneratorFunction<DOC, Enum> {} |
16 changes: 16 additions & 0 deletions
16
...rc/main/java/com/speedment/generator/translator/component/function/GenerateInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
package com.speedment.generator.translator.component.function; | |||
|
|||
import com.speedment.common.codegen.model.Interface; | |||
import com.speedment.runtime.config.trait.HasMainInterface; | |||
import com.speedment.runtime.config.trait.HasName; | |||
|
|||
/** | |||
* Specialization of {@link GeneratorFunction} that produces a CodeGen | |||
* {@code Interface}. | |||
* | |||
* @author Emil Forslund | |||
* @since 3.1.4 | |||
*/ | |||
@FunctionalInterface | |||
public interface GenerateInterface<DOC extends HasName & HasMainInterface> | |||
extends GeneratorFunction<DOC, Interface> {} |
43 changes: 43 additions & 0 deletions
43
...rc/main/java/com/speedment/generator/translator/component/function/GeneratorFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
package com.speedment.generator.translator.component.function; | |||
|
|||
import com.speedment.common.codegen.model.Class; | |||
import com.speedment.common.codegen.model.ClassOrInterface; | |||
import com.speedment.common.codegen.model.Enum; | |||
import com.speedment.common.codegen.model.Interface; | |||
import com.speedment.runtime.config.Project; | |||
import com.speedment.runtime.config.Table; | |||
import com.speedment.runtime.config.trait.HasMainInterface; | |||
import com.speedment.runtime.config.trait.HasName; | |||
|
|||
/** | |||
* Specialized function that takes a Speedment configuration document (like | |||
* {@link Project}, {@link Table}, etc) and returns a CodeGen model (like | |||
* {@link Class}, {@link Interface} or {@link Enum}). | |||
* | |||
* @author Emil Forslund | |||
* @since 3.1.4 | |||
*/ | |||
@FunctionalInterface | |||
public interface GeneratorFunction<DOC extends HasName & HasMainInterface, T extends ClassOrInterface<T>> { | |||
|
|||
/** | |||
* Generates a CodeGen model from the specified document. | |||
* | |||
* @param document the document to generate from | |||
* @return the created codegen model | |||
*/ | |||
T generate(DOC document); | |||
|
|||
/** | |||
* Returns {@code true} if classes created by this generator should be | |||
* placed in the {@code .generated}-folder that is regenerated each time | |||
* Speedment is invoked. | |||
* <p> | |||
* The default value of this method is {@code false}. | |||
* | |||
* @return {@code true} if results should be put in the generated package | |||
*/ | |||
default boolean inGeneratedPackage() { | |||
return false; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters