Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
minor codegen updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Sobolev committed Oct 31, 2017
1 parent dd45f6c commit ab6edca
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
Expand Up @@ -33,8 +33,8 @@ public final class NameString_Type_MapAsmImpl

private NameString_Type_MapAsmImpl() {
super(
NameString::create,
Function2.identity1(),
NameString::create,
TypeAsmImpl.INSTANCE
);
}
Expand Down
Expand Up @@ -42,8 +42,8 @@ public class AsmBasedBooksReadOperation extends AbstractReadOperation {

BookId_BookRecord_Map.Value value =
new BookId_BookRecord_MapAsm<>(
Function.identity(), // key converter
Function2.identity1(), // map extractor
Function.identity(), // key converter
BookRecordAsmImpl.INSTANCE // items assembler
).assemble(BooksBackend.getBooks(), projection.dataProjection(), new AsmContext());

Expand Down
Expand Up @@ -87,7 +87,7 @@ ${JavaGenUtils.generateImports(importManager.imports)}
${JavaGenUtils.generatedAnnotation(this)}
public class $shortClassName<D, I> implements $assembler<D, $notNull $projectionName, $notNull $t.Value> {
${if (hasTails) s" private final $notNull $func<? super D, ? extends Type> typeExtractor;\n" else "" }\
private final $notNull $func<D, $iterable<? extends I>> itemsExtractor;
private final $notNull $func<D, ? extends $iterable<? extends I>> itemsExtractor;
private final $notNull $itemAsmType itemAsm;
${if (hasTails) tps.map { tp => s" private final $notNull ${tp.assemblerType} ${tp.assembler};"}.mkString("\n //tail assemblers\n","\n","") else "" }\
${if (hasMeta) s" //meta assembler\n private final $notNull $metaAsmType metaAsm;" else ""}
Expand All @@ -103,7 +103,7 @@ ${if (hasMeta) s"\n * @param metaAsm metadata assembler" else ""}
*/
public $shortClassName(
${if (hasTails) s" $notNull $func<? super D, ? extends Type> typeExtractor,\n" else "" }\
$notNull $func<D, $iterable<? extends I>> itemsExtractor,
$notNull $func<D, ? extends $iterable<? extends I>> itemsExtractor,
$notNull $itemAsmType itemAsm\
${if (hasTails) tps.map { tp => s" $notNull ${tp.assemblerType} ${tp.assembler}"}.mkString(",\n", ",\n", "") else ""}\
${if (hasMeta) s",\n $notNull $metaAsmType metaAsm" else ""}
Expand Down
Expand Up @@ -96,8 +96,8 @@ ${JavaGenUtils.generateImports(importManager.imports)}
${JavaGenUtils.generatedAnnotation(this)}
public class $shortClassName<D, K, V> implements $assembler<D, $notNull $projectionName, $notNull $t.Value> {
${if (hasTails) s" private final $notNull $func<? super D, ? extends Type> typeExtractor;\n" else "" }\
private final $notNull $fun2<D, $projectionName, ? extends $mp<K, ? extends V>> mapExtractor;
private final $notNull $keysConverterType keyConverter;
private final $notNull $fun2<D, $projectionName, $mp<K, ? extends V>> mapExtractor;
private final $notNull $itemAsmType itemAsm;
${if (hasTails) tps.map { tp => s" private final $notNull ${tp.assemblerType} ${tp.assembler};"}.mkString("\n //tail assemblers\n","\n","") else "" }\
${if (hasMeta) s" //meta assembler\n private final $notNull $metaAsmType metaAsm;" else ""}
Expand All @@ -106,23 +106,23 @@ ${if (hasMeta) s" //meta assembler\n private final $notNull $metaAsmType metaA
* Asm constructor
*
${if (hasTails) s" * @param typeExtractor data type extractor, used to determine DTO type\n" else ""}\
* @param keyConverter key converter
* @param mapExtractor map extractor
* @param keyConverter key converter
* @param itemAsm items assembler\
${if (hasTails) tps.map { tp => s" * @param ${tp.javadoc}"}.mkString("\n","\n","") else "" }\
${if (hasMeta) s"\n * @param metaAsm metadata assembler" else ""}
*/
public $shortClassName(
${if (hasTails) s" $notNull $func<? super D, ? extends Type> typeExtractor,\n" else "" }\
$notNull $fun2<D, $projectionName, ? extends $mp<K, ? extends V>> mapExtractor,
$notNull $keysConverterType keyConverter,
$notNull $fun2<D, $projectionName, $mp<K, ? extends V>> mapExtractor,
$notNull $itemAsmType itemAsm\
${if (hasTails) tps.map { tp => s" $notNull ${tp.assemblerType} ${tp.assembler}"}.mkString(",\n", ",\n", "") else ""}\
${if (hasMeta) s",\n $notNull $metaAsmType metaAsm" else ""}
) {
${if (hasTails) s" this.typeExtractor = typeExtractor;\n" else "" }\
this.keyConverter = keyConverter;
this.mapExtractor = mapExtractor;
this.keyConverter = keyConverter;
this.itemAsm = itemAsm;\
${if (hasTails) tps.map { tp => s" this.${tp.assembler} = ${tp.assembler};"}.mkString("\n","\n","") else ""}\
${if (hasMeta) s"\n this.metaAsm = metaAsm;" else ""}
Expand Down
4 changes: 4 additions & 0 deletions java/core/src/main/java/ws/epigraph/assembly/Asm.java
Expand Up @@ -24,6 +24,10 @@
* Base interface for generated data assemblers. Builds Epigraph
* data instance based on data transfer object and request projection.
*
* @param <R> result type
* @param <D> source data type
* @param <P> projection type
*
* @author <a href="mailto:konstantin.sobolev@gmail.com">Konstantin Sobolev</a>
*/
@FunctionalInterface
Expand Down
10 changes: 10 additions & 0 deletions todo.md
Expand Up @@ -40,6 +40,16 @@
- [ ] req projections codegen: a lot of code duplication, move stuff up (but don't kill extras like 'required' and 'replace')
- [x] codegen bug: see `childProjectionWithUnusedParent.epigraph` and `tests-schema-java.gradle`
- [x] codegen bug: impossible to have tail type as a field, see `childUsedByParent.epigraph`
- [ ] codegen: a hierarchy of `N` record types with `N` new fields each will result in `N^3` lines of code, since
every new type assembler has to include all parent field assemblers. Proposed way out:
- introduce `final` fields/tags
- codegen `$TypeFinalFieldAssemblers` interfaces with inheritance
- make `$TypeAsm` take final field assemblers using this interface, the rest - directly, like it is now

Will make it possible to do
```
BFinalFieldsAssemberImpl extends AFinalFieldsAssemberImpl implements BFinalFieldsAssember { /* only new fields here */ }
```


# Type system
Expand Down

0 comments on commit ab6edca

Please sign in to comment.