Skip to content

Commit

Permalink
generate NodeXyz.Label and NodeXyz.PropertyKinds statics (#102)
Browse files Browse the repository at this point in the history
* refactor

* generate static NodeName.Label

* generate NodeXyz.PropertyKinds statics
  • Loading branch information
mpollmeier authored Nov 13, 2023
1 parent 5d6abc9 commit 26ddf50
Show file tree
Hide file tree
Showing 45 changed files with 721 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,22 @@ class DomainClassesGenerator(schema: Schema) {
nodeTypes.iterator.zipWithIndex.foreach { case (nodeType, kind) =>
val newExtendz = newExtendzMap(nodeType)
val newProperties = newPropsAtNodeList(nodeType)
val staticTyp =
(s"""trait ${nodeType.className}EMT extends AnyRef""" +: newExtendz.map { b => s"${b.className}EMT" } ++: newProperties.map { p =>
s"Has${p.className}EMT"
}).mkString(" with ")

val base = (s"""trait ${nodeType.className}Base extends AbstractNode""" +: newExtendz
.map { base => base.className + "Base" } ++: List(s"StaticType[${nodeType.className}EMT]")).mkString(" with ")

val stored =
(s"""class ${nodeType.className}(graph_4762: odb2.Graph, seq_4762: Int) extends StoredNode(graph_4762, ${kind}.toShort , seq_4762)""" :: s"${nodeType.className}Base" +: newExtendz
.map { base => base.className } ++: List(s"StaticType[${nodeType.className}EMT]")).mkString(" with ")
// val base = (s"""class ${nodeType.className}""")

val erasedMarkerType = {
val mixins = newExtendz.map(b => s"${b.className}EMT") ++ newProperties.map(p => s"Has${p.className}EMT")
s"""trait ${nodeType.className}EMT extends AnyRef""" +: mixins
}.mkString(" with ")

val baseTrait = {
val mixins = newExtendz.map(base => base.className + "Base") :+ s"StaticType[${nodeType.className}EMT]"
s"""trait ${nodeType.className}Base extends AbstractNode""" +: mixins
}.mkString(" with ")

val storedNode = {
val mixins = s"${nodeType.className}Base" +: newExtendz.map(_.className) :+ s"StaticType[${nodeType.className}EMT]"
s"""class ${nodeType.className}(graph_4762: odb2.Graph, seq_4762: Int) extends StoredNode(graph_4762, $kind.toShort , seq_4762)""" +: mixins
}.mkString(" with ")

val newNodeProps = mutable.ArrayBuffer.empty[String]
val newNodeFluent = mutable.ArrayBuffer.empty[String]
val storedNodeProps = mutable.ArrayBuffer.empty[String]
Expand Down Expand Up @@ -357,6 +361,14 @@ class DomainClassesGenerator(schema: Schema) {
}
.mkString("\n")

val propertyKinds = nodeType.properties
.map(_.name)
.map { name =>
val camelCase = Helpers.camelCaseCaps(name)
s"""val $camelCase = $basePackage.PropertyKinds.$name"""
}
.mkString("\n")

val newNode =
s"""object New${nodeType.className}{def apply(): New${nodeType.className} = new New${nodeType.className}}
|class New${nodeType.className} extends NewNode(${nodeKindByNodeType(nodeType)}.toShort) with ${nodeType.className}Base {
Expand Down Expand Up @@ -398,12 +410,21 @@ class DomainClassesGenerator(schema: Schema) {
|import io.shiftleft.codepropertygraph.generated.v2.Language.*
|import scala.collection.immutable.{IndexedSeq, ArraySeq}
|
|$staticTyp
|$base {
|$erasedMarkerType
|
|$baseTrait {
| ${baseNodeProps.mkString("\n")}
| $propDictItemsSource
|}
|$stored {
|
|object ${nodeType.className} {
| val Label = "${nodeType.name}"
| object PropertyKinds {
| $propertyKinds
| }
|}
|
|$storedNode {
| ${storedNodeProps.mkString("\n")}
|
| override def productElementName(n: Int): String =
Expand All @@ -423,6 +444,7 @@ class DomainClassesGenerator(schema: Schema) {
|
| override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[${nodeType.className}]
|}
|
|$newNode
|""".stripMargin
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.shiftleft.codepropertygraph.generated.v2.Language.*
import scala.collection.immutable.{IndexedSeq, ArraySeq}

trait AnnotationEMT extends AnyRef with ExpressionEMT with HasFullNameEMT with HasNameEMT

trait AnnotationBase extends AbstractNode with ExpressionBase with StaticType[AnnotationEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -21,6 +22,21 @@ trait AnnotationBase extends AbstractNode with ExpressionBase with StaticType[An
res
}
}

object Annotation {
val Label = "ANNOTATION"
object PropertyKinds {
val ArgumentIndex = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_INDEX
val ArgumentName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_NAME
val Code = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.CODE
val ColumnNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.COLUMN_NUMBER
val FullName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.FULL_NAME
val LineNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.LINE_NUMBER
val Name = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.NAME
val Order = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ORDER
}
}

class Annotation(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 0.toShort, seq_4762)
with AnnotationBase
Expand Down Expand Up @@ -58,6 +74,7 @@ class Annotation(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[Annotation]
}

object NewAnnotation { def apply(): NewAnnotation = new NewAnnotation }
class NewAnnotation extends NewNode(0.toShort) with AnnotationBase {
type RelatedStored = Annotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.shiftleft.codepropertygraph.generated.v2.Language.*
import scala.collection.immutable.{IndexedSeq, ArraySeq}

trait AnnotationLiteralEMT extends AnyRef with ExpressionEMT with HasNameEMT

trait AnnotationLiteralBase extends AbstractNode with ExpressionBase with StaticType[AnnotationLiteralEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -20,6 +21,20 @@ trait AnnotationLiteralBase extends AbstractNode with ExpressionBase with Static
res
}
}

object AnnotationLiteral {
val Label = "ANNOTATION_LITERAL"
object PropertyKinds {
val ArgumentIndex = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_INDEX
val ArgumentName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_NAME
val Code = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.CODE
val ColumnNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.COLUMN_NUMBER
val LineNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.LINE_NUMBER
val Name = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.NAME
val Order = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ORDER
}
}

class AnnotationLiteral(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 1.toShort, seq_4762)
with AnnotationLiteralBase
Expand Down Expand Up @@ -55,6 +70,7 @@ class AnnotationLiteral(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[AnnotationLiteral]
}

object NewAnnotationLiteral { def apply(): NewAnnotationLiteral = new NewAnnotationLiteral }
class NewAnnotationLiteral extends NewNode(1.toShort) with AnnotationLiteralBase {
type RelatedStored = AnnotationLiteral
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.shiftleft.codepropertygraph.generated.v2.Language.*
import scala.collection.immutable.{IndexedSeq, ArraySeq}

trait AnnotationParameterEMT extends AnyRef with AstNodeEMT

trait AnnotationParameterBase extends AbstractNode with AstNodeBase with StaticType[AnnotationParameterEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -17,6 +18,17 @@ trait AnnotationParameterBase extends AbstractNode with AstNodeBase with StaticT
res
}
}

object AnnotationParameter {
val Label = "ANNOTATION_PARAMETER"
object PropertyKinds {
val Code = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.CODE
val ColumnNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.COLUMN_NUMBER
val LineNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.LINE_NUMBER
val Order = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ORDER
}
}

class AnnotationParameter(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 2.toShort, seq_4762)
with AnnotationParameterBase
Expand Down Expand Up @@ -46,6 +58,7 @@ class AnnotationParameter(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[AnnotationParameter]
}

object NewAnnotationParameter { def apply(): NewAnnotationParameter = new NewAnnotationParameter }
class NewAnnotationParameter extends NewNode(2.toShort) with AnnotationParameterBase {
type RelatedStored = AnnotationParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.shiftleft.codepropertygraph.generated.v2.Language.*
import scala.collection.immutable.{IndexedSeq, ArraySeq}

trait AnnotationParameterAssignEMT extends AnyRef with AstNodeEMT

trait AnnotationParameterAssignBase extends AbstractNode with AstNodeBase with StaticType[AnnotationParameterAssignEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -17,6 +18,17 @@ trait AnnotationParameterAssignBase extends AbstractNode with AstNodeBase with S
res
}
}

object AnnotationParameterAssign {
val Label = "ANNOTATION_PARAMETER_ASSIGN"
object PropertyKinds {
val Code = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.CODE
val ColumnNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.COLUMN_NUMBER
val LineNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.LINE_NUMBER
val Order = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ORDER
}
}

class AnnotationParameterAssign(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 3.toShort, seq_4762)
with AnnotationParameterAssignBase
Expand Down Expand Up @@ -46,6 +58,7 @@ class AnnotationParameterAssign(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[AnnotationParameterAssign]
}

object NewAnnotationParameterAssign { def apply(): NewAnnotationParameterAssign = new NewAnnotationParameterAssign }
class NewAnnotationParameterAssign extends NewNode(3.toShort) with AnnotationParameterAssignBase {
type RelatedStored = AnnotationParameterAssign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.shiftleft.codepropertygraph.generated.v2.Language.*
import scala.collection.immutable.{IndexedSeq, ArraySeq}

trait ArrayInitializerEMT extends AnyRef with ExpressionEMT

trait ArrayInitializerBase extends AbstractNode with ExpressionBase with StaticType[ArrayInitializerEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -19,6 +20,19 @@ trait ArrayInitializerBase extends AbstractNode with ExpressionBase with StaticT
res
}
}

object ArrayInitializer {
val Label = "ARRAY_INITIALIZER"
object PropertyKinds {
val ArgumentIndex = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_INDEX
val ArgumentName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_NAME
val Code = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.CODE
val ColumnNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.COLUMN_NUMBER
val LineNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.LINE_NUMBER
val Order = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ORDER
}
}

class ArrayInitializer(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 4.toShort, seq_4762)
with ArrayInitializerBase
Expand Down Expand Up @@ -52,6 +66,7 @@ class ArrayInitializer(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[ArrayInitializer]
}

object NewArrayInitializer { def apply(): NewArrayInitializer = new NewArrayInitializer }
class NewArrayInitializer extends NewNode(4.toShort) with ArrayInitializerBase {
type RelatedStored = ArrayInitializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.shiftleft.codepropertygraph.generated.v2.Language.*
import scala.collection.immutable.{IndexedSeq, ArraySeq}

trait BindingEMT extends AnyRef with HasMethodFullNameEMT with HasNameEMT with HasSignatureEMT

trait BindingBase extends AbstractNode with StaticType[BindingEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -16,6 +17,16 @@ trait BindingBase extends AbstractNode with StaticType[BindingEMT] {
res
}
}

object Binding {
val Label = "BINDING"
object PropertyKinds {
val MethodFullName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.METHOD_FULL_NAME
val Name = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.NAME
val Signature = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.SIGNATURE
}
}

class Binding(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 5.toShort, seq_4762)
with BindingBase
Expand All @@ -42,6 +53,7 @@ class Binding(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[Binding]
}

object NewBinding { def apply(): NewBinding = new NewBinding }
class NewBinding extends NewNode(5.toShort) with BindingBase {
type RelatedStored = Binding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.shiftleft.codepropertygraph.generated.v2.Language.*
import scala.collection.immutable.{IndexedSeq, ArraySeq}

trait BlockEMT extends AnyRef with ExpressionEMT with HasDynamicTypeHintFullNameEMT with HasPossibleTypesEMT with HasTypeFullNameEMT

trait BlockBase extends AbstractNode with ExpressionBase with StaticType[BlockEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -23,6 +24,22 @@ trait BlockBase extends AbstractNode with ExpressionBase with StaticType[BlockEM
res
}
}

object Block {
val Label = "BLOCK"
object PropertyKinds {
val ArgumentIndex = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_INDEX
val ArgumentName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_NAME
val Code = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.CODE
val ColumnNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.COLUMN_NUMBER
val DynamicTypeHintFullName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.DYNAMIC_TYPE_HINT_FULL_NAME
val LineNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.LINE_NUMBER
val Order = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ORDER
val PossibleTypes = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.POSSIBLE_TYPES
val TypeFullName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.TYPE_FULL_NAME
}
}

class Block(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 6.toShort, seq_4762)
with BlockBase
Expand Down Expand Up @@ -62,6 +79,7 @@ class Block(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[Block]
}

object NewBlock { def apply(): NewBlock = new NewBlock }
class NewBlock extends NewNode(6.toShort) with BlockBase {
type RelatedStored = Block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait CallEMT
with HasMethodFullNameEMT
with HasPossibleTypesEMT
with HasTypeFullNameEMT

trait CallBase extends AbstractNode with CallReprBase with ExpressionBase with StaticType[CallEMT] {

override def propertiesMap: java.util.Map[String, Any] = {
Expand All @@ -35,6 +36,26 @@ trait CallBase extends AbstractNode with CallReprBase with ExpressionBase with S
res
}
}

object Call {
val Label = "CALL"
object PropertyKinds {
val ArgumentIndex = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_INDEX
val ArgumentName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ARGUMENT_NAME
val Code = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.CODE
val ColumnNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.COLUMN_NUMBER
val DispatchType = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.DISPATCH_TYPE
val DynamicTypeHintFullName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.DYNAMIC_TYPE_HINT_FULL_NAME
val LineNumber = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.LINE_NUMBER
val MethodFullName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.METHOD_FULL_NAME
val Name = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.NAME
val Order = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.ORDER
val PossibleTypes = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.POSSIBLE_TYPES
val Signature = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.SIGNATURE
val TypeFullName = io.shiftleft.codepropertygraph.generated.v2.PropertyKinds.TYPE_FULL_NAME
}
}

class Call(graph_4762: odb2.Graph, seq_4762: Int)
extends StoredNode(graph_4762, 7.toShort, seq_4762)
with CallBase
Expand Down Expand Up @@ -83,6 +104,7 @@ class Call(graph_4762: odb2.Graph, seq_4762: Int)

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[Call]
}

object NewCall { def apply(): NewCall = new NewCall }
class NewCall extends NewNode(7.toShort) with CallBase {
type RelatedStored = Call
Expand Down
Loading

0 comments on commit 26ddf50

Please sign in to comment.