Skip to content

Commit da7fc2c

Browse files
authored
move dontWarnForDuplicateProperty to SchemaBuilder public api (#110)
This was previously in CodeGen, but since the introduction of the codegen plugin, usage sites aren't exposed to the CodeGen any longer.
1 parent 534ece3 commit da7fc2c

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

codegen/src/main/scala/overflowdb/codegen/CodeGen.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ class CodeGen(schema: Schema) {
1414
val nodesPackage = s"$basePackage.nodes"
1515
val edgesPackage = s"$basePackage.edges"
1616
val traversalsPackage = s"$basePackage.traversal"
17-
private val noWarnList: mutable.Set[(AbstractNodeType, Property[_])] = mutable.Set.empty
18-
19-
def dontWarnForDuplicateProperty(nodeType: AbstractNodeType, property: Property[_]): CodeGen = {
20-
noWarnList.add((nodeType, property))
21-
this
22-
}
2317

2418
def run(outputDir: java.io.File): Seq[java.io.File] = {
2519
warnForDuplicatePropertyDefinitions()
@@ -43,7 +37,7 @@ class CodeGen(schema: Schema) {
4337
nodeType <- schema.allNodeTypes
4438
property <- nodeType.propertiesWithoutInheritance
4539
baseType <- nodeType.extendzRecursively
46-
if baseType.propertiesWithoutInheritance.contains(property) && !noWarnList.contains((nodeType, property))
40+
if baseType.propertiesWithoutInheritance.contains(property) && !schema.noWarnList.contains((nodeType, property))
4741
} yield s"[info]: $nodeType wouldn't need to have property `${property.name}` added explicitly - $baseType already brings it in"
4842

4943
if (warnings.size > 0) println(s"${warnings.size} warnings found:")

codegen/src/main/scala/overflowdb/schema/Schema.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class Schema(val domainShortName: String,
1616
val nodeTypes: Seq[NodeType],
1717
val edgeTypes: Seq[EdgeType],
1818
val constantsByCategory: Map[String, Seq[Constant]],
19-
val protoOptions: Option[ProtoOptions]) {
19+
val protoOptions: Option[ProtoOptions],
20+
val noWarnList: Set[(AbstractNodeType, Property[_])]) {
2021

2122
/** nodeTypes and nodeBaseTypes combined */
2223
lazy val allNodeTypes: Seq[AbstractNodeType] =

codegen/src/main/scala/overflowdb/schema/SchemaBuilder.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package overflowdb.schema
33
import overflowdb.codegen.DefaultNodeTypes
44
import overflowdb.codegen.Helpers._
55
import overflowdb.schema.Property.ValueType
6+
67
import scala.collection.mutable
78

89
class SchemaBuilder(domainShortName: String, basePackage: String) {
@@ -12,6 +13,7 @@ class SchemaBuilder(domainShortName: String, basePackage: String) {
1213
val edgeTypes = mutable.ListBuffer.empty[EdgeType]
1314
val constantsByCategory = mutable.Map.empty[String, Seq[Constant]]
1415
var protoOptions: Option[ProtoOptions] = None
16+
val noWarnList: mutable.Set[(AbstractNodeType, Property[_])] = mutable.Set.empty
1517

1618
/** root node trait for all nodes - use if you want to be explicitly unspecific
1719
* n.b. 1: this one allows for StoredNode and NewNode
@@ -62,6 +64,11 @@ class SchemaBuilder(domainShortName: String, basePackage: String) {
6264
this
6365
}
6466

67+
def dontWarnForDuplicateProperty(nodeType: AbstractNodeType, property: Property[_]): SchemaBuilder = {
68+
noWarnList.add((nodeType, property))
69+
this
70+
}
71+
6572
def build: Schema = {
6673
val schema = new Schema(
6774
domainShortName,
@@ -72,6 +79,7 @@ class SchemaBuilder(domainShortName: String, basePackage: String) {
7279
edgeTypes.sortBy(_.name.toLowerCase).toSeq,
7380
constantsByCategory.toMap,
7481
protoOptions,
82+
noWarnList.toSet,
7583
)
7684
verifyProtoIdsUnique(schema)
7785
schema

codegen/src/main/scala/overflowdb/schema/testschema1/TestSchema1.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ object TestSchema1 extends App {
209209
)
210210
)
211211

212+
builder.dontWarnForDuplicateProperty(file, order)
213+
builder.dontWarnForDuplicateProperty(namespaceBlock, order)
214+
212215
new CodeGen(builder.build)
213-
.dontWarnForDuplicateProperty(file, order)
214216
.run(new File("target"))
215217
}

0 commit comments

Comments
 (0)