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

Commit

Permalink
record projection codegen fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Sobolev committed Oct 30, 2017
1 parent 823ee1a commit dd45f6c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ trait ReqEntityProjectionGen extends ReqTypeProjectionGen {

protected def genShortClassName(prefix: String, suffix: String): String = genShortClassName(prefix, suffix, cType)

override def children: Iterable[JavaGen] =
tagGenerators.values ++ /*tailGenerators.values ++*/
override def children: Iterable[JavaGen]
= {
if (invalidParentClassGenerator)
Iterable()
else
tagGenerators.values
} ++
/*tailGenerators.values ++*/
normalizedTailGenerators/*.filterKeys(p => p.referenceName() == null)*/ .values // filter out named generators

override protected val cType: CEntityTypeDef = toCType(op.`type`()).asInstanceOf[CEntityTypeDef]
Expand All @@ -61,11 +67,11 @@ trait ReqEntityProjectionGen extends ReqTypeProjectionGen {
t: CEntityTypeDef): Map[String, (Option[ReqEntityProjectionGen], OpTagProjectionEntryType)] = {
val op = g.op

val parentOverridingTagProjections = g.parentClassGenOpt.map(
pg => tagProjections(
pg.asInstanceOf[ReqEntityProjectionGen], t
)
).getOrElse(Map())
// val parentOverridingTagProjections = g.parentClassGenOpt.map(
// pg => tagProjections(
// pg.asInstanceOf[ReqEntityProjectionGen], t
// )
// ).getOrElse(Map())

val gOverridingTagProjections = op.tagProjections().toSeq.toListMap
.filter { case (tn, tp) =>
Expand All @@ -83,7 +89,8 @@ trait ReqEntityProjectionGen extends ReqTypeProjectionGen {
)
}

parentOverridingTagProjections ++ gOverridingTagProjections
// parentOverridingTagProjections ++ gOverridingTagProjections
gOverridingTagProjections
}

/** tag projections: should only include new or overridden tags, should not include inherited */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ trait ReqRecordModelProjectionGen extends ReqModelProjectionGen {

protected val cRecordType: CRecordTypeDef = cType.asInstanceOf[CRecordTypeDef]

/** get field projections from `g.op` if they override fields from `t` */
/** get field projections from `g.op` if they are overridden in type `t` */
def overridingFieldProjections(
g: ReqRecordModelProjectionGen,
t: CRecordTypeDef): Map[String, (Option[ReqRecordModelProjectionGen], OpFieldProjectionType)] = {

val p = g.op

val parentOverridingFieldProjections = g.parentClassGenOpt.map(
pg => overridingFieldProjections(pg.asInstanceOf[ReqRecordModelProjectionGen], t)
).getOrElse(Map())
// val parentOverridingFieldProjections = g.parentClassGenOpt.map(
// pg => overridingFieldProjections(pg.asInstanceOf[ReqRecordModelProjectionGen], t)
// ).getOrElse(Map())

val gOverridingFieldProjections = p.fieldProjections().toSeq.toListMap
.filter { case (fieldName, fieldProjection) =>
Expand All @@ -75,7 +75,8 @@ trait ReqRecordModelProjectionGen extends ReqModelProjectionGen {
)
}

parentOverridingFieldProjections ++ gOverridingFieldProjections
// parentOverridingFieldProjections ++ gOverridingFieldProjections
gOverridingFieldProjections
}

/**
Expand Down Expand Up @@ -104,8 +105,9 @@ trait ReqRecordModelProjectionGen extends ReqModelProjectionGen {
}

override def children: Iterable[JavaGen] = super.children ++ {
// exclude (overriden) fields taken from parent generator
if (ReqFieldProjectionGen.generateFieldProjections)
if (invalidParentClassGenerator)
Iterable()
else if (ReqFieldProjectionGen.generateFieldProjections)
fieldGenerators.values
else
fieldGenerators.values.flatMap(_.children)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ trait ReqTypeProjectionGen extends ReqProjectionGen {
}

protected def invalidParentClassGenerator: Boolean =
parentClassGenOpt.isEmpty && normalizedFromGenOpt.isDefined
parentClassGenOpt match {
case Some(parentGen) => parentGen.invalidParentClassGenerator
case None => normalizedFromGenOpt.isDefined
}

protected def generate0: String
}
Expand Down
3 changes: 2 additions & 1 deletion tests/schema-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ epigraph {
"ws.epigraph.tests.users",
"ws.epigraph.tests.codegenstress.namedDoubleTail",
"ws.epigraph.tests.codegenstress.childWithUnusedParent",
"ws.epigraph.tests.codegenstress.childUsedByParent"
"ws.epigraph.tests.codegenstress.childUsedByParent",
// "com.sumologic.som.folders"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ namespace ws.epigraph.tests.codegenstress
// resource output projection uses normalized $child projection
// while $parent projection is never used

entity SomeParentEntity {
record SomeParent {
id: Long
me: SomeParent
}
entity SomeChildEntity extends SomeParentEntity {
record SomeChild extends SomeParent {
name: String
override me: SomeChild
}

outputProjection parent: SomeParentEntity = :( id ) :~ SomeChildEntity $child = :( name )
record SomeChild2 extends SomeChild {
child2: String
}

outputProjection parent: SomeParent = ( id, me )
~ SomeChild $child = ( name )
~ SomeChild2 ( child2 )

resource childWithUnusedParent : SomeChildEntity {
resource childWithUnusedParent : SomeChild {
read {
outputProjection $child
}
Expand Down

0 comments on commit dd45f6c

Please sign in to comment.