Skip to content

Commit 6601010

Browse files
authored
Generate .copy and .copyMetas function for generated classes (#53)
1 parent 7ac7c5d commit 6601010

File tree

7 files changed

+1942
-17
lines changed

7 files changed

+1942
-17
lines changed

pig-runtime/src/org/partiql/pig/runtime/DomainNode.kt

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ interface DomainNode {
2424
/** This node's collection of metadata. */
2525
val metas: MetaContainer
2626

27+
/** Creates a copy of the current node with [newMetas] as the new metas. */
28+
fun copyMetas(newMetas : MetaContainer): DomainNode
29+
2730
/** Creates a copy of the current node with the specified [key] and [value] as metadata.*/
2831
fun withMeta(metaKey: String, metaValue: Any): DomainNode
2932

pig-runtime/src/org/partiql/pig/runtime/LongPrimitive.kt

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class LongPrimitive(val value: Long, override val metas: MetaContainer) : Domain
3131
fun copy(value: Long = this.value, metas: MetaContainer = this.metas): LongPrimitive =
3232
LongPrimitive(value, metas)
3333

34+
/** Creates a copy of the current [LongPrimitive] with [newMetas] as the new metas. */
35+
override fun copyMetas(newMetas: MetaContainer): LongPrimitive =
36+
LongPrimitive(value, newMetas)
37+
3438
/** Creates a copy of the current [LongPrimitive] with the specified additional meta. */
3539
override fun withMeta(metaKey: String, metaValue: Any): LongPrimitive =
3640
LongPrimitive(this.value, metas + metaContainerOf(metaKey to metaValue))

pig-runtime/src/org/partiql/pig/runtime/SymbolPrimitive.kt

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class SymbolPrimitive(val text: String, override val metas: MetaContainer) : Dom
3131
fun copy(text: String = this.text, metas: MetaContainer = this.metas): SymbolPrimitive =
3232
SymbolPrimitive(text, metas)
3333

34+
/** Creates a copy of the current [SymbolPrimitive] with [newMetas] as the new metas. */
35+
override fun copyMetas(newMetas: MetaContainer): SymbolPrimitive =
36+
SymbolPrimitive(text, newMetas)
37+
3438
/** Creates a copy of the current [SymbolPrimitive] with the specified additional meta. */
3539
override fun withMeta(metaKey: String, metaValue: Any): SymbolPrimitive =
3640
SymbolPrimitive(text, metas + metaContainerOf(metaKey to metaValue))

pig-runtime/test/org/partiql/pig/runtime/IonElementTransformerBaseTests.kt

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class IonElementTransformerBaseTests {
3131
abstract class DummyDomainNode : DomainNode
3232

3333
data class CorrectDomainNode(val someString: String, override val metas: MetaContainer = emptyMetaContainer()): DummyDomainNode() {
34+
override fun copyMetas(newMetas: MetaContainer): DomainNode {
35+
error("does not need to be implemented for tests")
36+
}
37+
3438
override fun withMeta(metaKey: String, metaValue: Any): DomainNode {
3539
error("does not need to be implemented for tests")
3640
}
@@ -40,6 +44,10 @@ class IonElementTransformerBaseTests {
4044
}
4145

4246
data class IncorrectDomainNode(val someString: String): DummyDomainNode() {
47+
override fun copyMetas(newMetas: MetaContainer): DomainNode {
48+
error("does not need to be implemented for tests")
49+
}
50+
4351
override fun withMeta(metaKey: String, metaValue: Any): DomainNode {
4452
error("does not need to be implemented for tests")
4553
}

0 commit comments

Comments
 (0)