From 714221f4eec47c6ac9645497768b9b96da3de707 Mon Sep 17 00:00:00 2001 From: Markus Lottmann Date: Thu, 9 May 2019 19:43:41 +0200 Subject: [PATCH] Separate the extension namespaces for extending Cpg and Step class. (#160) This became necessary because we otherwise ended up with the Step extension methods as method on the Cpg class. Since this does not make sense it did not compile but was suggest in code completion and more important it ended up in the docs. --- .../scala/io/shiftleft/codepropertygraph/Cpg.scala | 8 +++----- .../ext/queryprimitives/Enrichable.scala | 2 +- .../ext/queryprimitivesext/Enrichable.scala | 11 +++++++++++ .../ext/securityprofile/Enrichable.scala | 11 +++++++++++ .../ext/semanticcpg/Enrichable.scala | 11 +++++++++++ .../ext/queryprimitives/package.scala | 4 ++-- .../io/shiftleft/queryprimitives/steps/Steps.scala | 1 - .../queryprimitives/steps/ext/Enrichable.scala | 0 .../steps/ext/dataflowengine/Enrichable.scala | 0 .../steps/ext/securityprofile/Enrichable.scala | 0 .../steps/ext/semanticcpg/Enrichable.scala | 0 11 files changed, 39 insertions(+), 9 deletions(-) rename codepropertygraph/src/main/scala/io/shiftleft/{queryprimitives/steps => codepropertygraph}/ext/queryprimitives/Enrichable.scala (88%) create mode 100644 codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitivesext/Enrichable.scala create mode 100644 codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/securityprofile/Enrichable.scala create mode 100644 codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/semanticcpg/Enrichable.scala rename query-primitives/src/main/scala/io/shiftleft/{queryprimitives/steps => codepropertygraph}/ext/queryprimitives/package.scala (83%) rename {codepropertygraph => query-primitives}/src/main/scala/io/shiftleft/queryprimitives/steps/ext/Enrichable.scala (100%) rename {codepropertygraph => query-primitives}/src/main/scala/io/shiftleft/queryprimitives/steps/ext/dataflowengine/Enrichable.scala (100%) rename {codepropertygraph => query-primitives}/src/main/scala/io/shiftleft/queryprimitives/steps/ext/securityprofile/Enrichable.scala (100%) rename {codepropertygraph => query-primitives}/src/main/scala/io/shiftleft/queryprimitives/steps/ext/semanticcpg/Enrichable.scala (100%) diff --git a/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/Cpg.scala b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/Cpg.scala index be681ace9..021bc21ef 100644 --- a/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/Cpg.scala +++ b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/Cpg.scala @@ -4,7 +4,6 @@ import gremlin.scala._ import io.shiftleft.codepropertygraph.generated.nodes import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph import shapeless.HNil -import io.shiftleft.queryprimitives.steps.ext object Cpg { @@ -36,11 +35,10 @@ object Cpg { @param graph the underlying graph. An empty graph is created if this parameter is omitted. */ class Cpg(val graph: Graph = Cpg.emptyGraph) - extends ext.Enrichable - with ext.queryprimitives.Enrichable + extends ext.queryprimitives.Enrichable + with ext.queryprimitivesext.Enrichable with ext.securityprofile.Enrichable - with ext.semanticcpg.Enrichable - with ext.dataflowengine.Enrichable { + with ext.semanticcpg.Enrichable { /** The underlying graph. diff --git a/codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/queryprimitives/Enrichable.scala b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitives/Enrichable.scala similarity index 88% rename from codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/queryprimitives/Enrichable.scala rename to codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitives/Enrichable.scala index 9fe2d9b97..159a504fd 100644 --- a/codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/queryprimitives/Enrichable.scala +++ b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitives/Enrichable.scala @@ -1,4 +1,4 @@ -package io.shiftleft.queryprimitives.steps.ext.queryprimitives +package io.shiftleft.codepropertygraph.ext.queryprimitives /** Sole purpose of this trait is to allow to enrich ('pimp') this DSL without the need of additional * imports a la `import x.y.z.Implicits._`. We're making use of the fact that package objects of diff --git a/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitivesext/Enrichable.scala b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitivesext/Enrichable.scala new file mode 100644 index 000000000..1354e2801 --- /dev/null +++ b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitivesext/Enrichable.scala @@ -0,0 +1,11 @@ +package io.shiftleft.codepropertygraph.ext.queryprimitivesext + +/** Sole purpose of this trait is to allow to enrich ('pimp') this DSL without the need of additional + * imports a la `import x.y.z.Implicits._`. We're making use of the fact that package objects of + * inherited traits are automatically part of implicit scope. This way, these extensions also show + * up in scaladoc. + * + * Important: this project should *not* define anything in the `ext` package object. If it does, + * it will be shadowed by enriching libraries. + */ +trait Enrichable {} diff --git a/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/securityprofile/Enrichable.scala b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/securityprofile/Enrichable.scala new file mode 100644 index 000000000..2a4f23cee --- /dev/null +++ b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/securityprofile/Enrichable.scala @@ -0,0 +1,11 @@ +package io.shiftleft.codepropertygraph.ext.securityprofile + +/** Sole purpose of this trait is to allow to enrich ('pimp') this DSL without the need of additional + * imports a la `import x.y.z.Implicits._`. We're making use of the fact that package objects of + * inherited traits are automatically part of implicit scope. This way, these extensions also show + * up in scaladoc. + * + * Important: this project should *not* define anything in the `ext` package object. If it does, + * it will be shadowed by enriching libraries. + */ +trait Enrichable {} diff --git a/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/semanticcpg/Enrichable.scala b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/semanticcpg/Enrichable.scala new file mode 100644 index 000000000..f8cb530b3 --- /dev/null +++ b/codepropertygraph/src/main/scala/io/shiftleft/codepropertygraph/ext/semanticcpg/Enrichable.scala @@ -0,0 +1,11 @@ +package io.shiftleft.codepropertygraph.ext.semanticcpg + +/** Sole purpose of this trait is to allow to enrich ('pimp') this DSL without the need of additional + * imports a la `import x.y.z.Implicits._`. We're making use of the fact that package objects of + * inherited traits are automatically part of implicit scope. This way, these extensions also show + * up in scaladoc. + * + * Important: this project should *not* define anything in the `ext` package object. If it does, + * it will be shadowed by enriching libraries. + */ +trait Enrichable {} diff --git a/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/queryprimitives/package.scala b/query-primitives/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitives/package.scala similarity index 83% rename from query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/queryprimitives/package.scala rename to query-primitives/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitives/package.scala index b440b75bc..17fec4289 100644 --- a/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/queryprimitives/package.scala +++ b/query-primitives/src/main/scala/io/shiftleft/codepropertygraph/ext/queryprimitives/package.scala @@ -1,10 +1,10 @@ -package io.shiftleft.queryprimitives.steps.ext +package io.shiftleft.codepropertygraph.ext import io.shiftleft.codepropertygraph.Cpg import io.shiftleft.queryprimitives.steps.starters.NodeTypeStarters package object queryprimitives { - implicit def toNodeTypeStarters(cpg: Cpg): NodeTypeStarters = new NodeTypeStarters(cpg) + } diff --git a/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/Steps.scala b/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/Steps.scala index 4960c8998..0d9a46c81 100644 --- a/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/Steps.scala +++ b/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/Steps.scala @@ -22,7 +22,6 @@ import shapeless.ops.product.ToHList */ class Steps[NodeType, Labels <: HList](val raw: GremlinScala.Aux[NodeType, Labels]) extends ext.Enrichable - with ext.queryprimitives.Enrichable with ext.securityprofile.Enrichable with ext.semanticcpg.Enrichable with ext.dataflowengine.Enrichable { diff --git a/codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/Enrichable.scala b/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/Enrichable.scala similarity index 100% rename from codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/Enrichable.scala rename to query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/Enrichable.scala diff --git a/codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/dataflowengine/Enrichable.scala b/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/dataflowengine/Enrichable.scala similarity index 100% rename from codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/dataflowengine/Enrichable.scala rename to query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/dataflowengine/Enrichable.scala diff --git a/codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/securityprofile/Enrichable.scala b/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/securityprofile/Enrichable.scala similarity index 100% rename from codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/securityprofile/Enrichable.scala rename to query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/securityprofile/Enrichable.scala diff --git a/codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/semanticcpg/Enrichable.scala b/query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/semanticcpg/Enrichable.scala similarity index 100% rename from codepropertygraph/src/main/scala/io/shiftleft/queryprimitives/steps/ext/semanticcpg/Enrichable.scala rename to query-primitives/src/main/scala/io/shiftleft/queryprimitives/steps/ext/semanticcpg/Enrichable.scala