Skip to content

codegen: add some type aliases so that the domain-specific code can avoid referencing the overflow namespace #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions codegen/src/main/scala/overflowdb/codegen/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,28 @@ class CodeGen(schema: Schema) {
val srcFile = nodeType.className + ".scala"
results.append(baseDir.createChild(srcFile).write(src))
}


val packageObject = {
val lastSeparatorIdx = basePackage.lastIndexOf('.')
val packageParent = basePackage.take(lastSeparatorIdx)
val packageSimpleName = basePackage.drop(lastSeparatorIdx + 1)

s"""package $packageParent
|
|package object $packageSimpleName {
| // some type aliases so that the domain-specific code can avoid referencing the `overflowdb` namespace
|
| object help {
| type Doc = _root_.overflowdb.traversal.help.Doc
| type Traversal = _root_.overflowdb.traversal.help.Traversal
| type TraversalSource = _root_.overflowdb.traversal.help.TraversalSource
| }
|}
|""".stripMargin
}
results.append(baseDir.createChild("package.scala").write(packageObject))

results.toSeq
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/schemas/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ generateDomainClasses := Def.taskDyn {
}
} else {
Def.task {
val invoked = (Compile/runMain).toTask(s" CodegenForAllSchemas").value
val invoked = (Compile/runMain).toTask(s" overflowdb.integrationtests.CodegenForAllSchemas").value
lastSchemaMd5(currentSchemaMd5)
FileUtils.listFilesRecursively(outputRoot)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

import overflowdb.codegen.CodeGen

import java.io.File
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

import overflowdb.schema.SchemaBuilder

trait TestSchema {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

import overflowdb.schema.Property.ValueType
import overflowdb.schema._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

import overflowdb.schema.Property.ValueType
import overflowdb.schema._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

/** complex scenario with multiple layers of base nodes
* similar to what we use in docker-ext schema extension
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

import overflowdb.schema.Property._

/** For testing default values on properties with Cardinality.One: we have type-dependent defaults,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

import overflowdb.schema.Property._

/** testing all property types with Cardinality.ZeroOrOne */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package overflowdb.integrationtests

import overflowdb.schema.Property.ValueType
import overflowdb.schema._

Expand Down
5 changes: 3 additions & 2 deletions integration-tests/tests/src/test/scala/Schema01Test.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import overflowdb.{BatchedUpdate, Config, Graph}
import overflowdb.integrationtests.testschema01
import testschema01._
import testschema01.nodes._
import testschema01.edges._
import testschema01.traversal._
import scala.jdk.CollectionConverters.IteratorHasAsScala

class Schema01Test extends AnyWordSpec with Matchers {
import testschema01.traversal._
import overflowdb.integrationtests.testschema01.traversal._
"constants" in {
PropertyNames.NAME shouldBe "NAME"
Properties.Order.name shouldBe "ORDER"
Expand Down Expand Up @@ -109,7 +110,7 @@ class Schema01Test extends AnyWordSpec with Matchers {
}
}
"work around scala bug 4762, ie generate no extraneous fields" in {
Class.forName("testschema01.nodes.Node1").getDeclaredFields.length shouldBe 0
Class.forName("overflowdb.integrationtests.testschema01.nodes.Node1").getDeclaredFields.length shouldBe 0
}

}
1 change: 1 addition & 0 deletions integration-tests/tests/src/test/scala/Schema02Test.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import overflowdb.SchemaViolationException
import overflowdb.integrationtests.testschema02
import testschema02._
import testschema02.edges._
import testschema02.nodes._
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/tests/src/test/scala/Schema03Test.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import overflowdb.traversal._
import overflowdb.integrationtests.testschema03a
import overflowdb.integrationtests.testschema03b
import overflowdb.integrationtests.testschema03c

class Schema03aTest {
import testschema03a._
Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/src/test/scala/Schema04Test.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import overflowdb.Graph
import overflowdb.integrationtests.testschema04
import testschema04._
import testschema04.edges._
import testschema04.nodes._
Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/src/test/scala/Schema05Test.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import overflowdb.{Config, Graph}
import overflowdb.integrationtests.testschema05
import testschema05._
import testschema05.edges._
import testschema05.nodes._
Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/src/test/scala/Schema06Test.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import overflowdb.{BatchedUpdate, Config, Graph}
import overflowdb.integrationtests.testschema06
import testschema06._
import testschema06.nodes._
import testschema06.edges._
Expand Down
Loading