From ec21a9cd012b18b9bc76fa006be6937552661bb7 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Mon, 3 Mar 2025 13:10:32 +0100 Subject: [PATCH] add column number to location --- .../generated/GraphSchema.scala | 4 + .../generated/accessors/Accessors.scala | 4 + .../generated/nodes/Location.scala | 140 ++++++++++++------ .../traversals/TraversalLocationBase.scala | 64 ++++++++ .../schema/TagsAndLocation.scala | 3 +- 5 files changed, 168 insertions(+), 47 deletions(-) diff --git a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/GraphSchema.scala b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/GraphSchema.scala index 3e84fae05..bddc0b80d 100644 --- a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/GraphSchema.scala +++ b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/GraphSchema.scala @@ -668,6 +668,8 @@ object GraphSchema extends flatgraph.Schema { nodePropertyDescriptors(575) = FormalQtyType.QtyOne nodePropertyDescriptors(662) = FormalQtyType.StringType // LOCATION.CLASS_SHORT_NAME nodePropertyDescriptors(663) = FormalQtyType.QtyOne + nodePropertyDescriptors(1014) = FormalQtyType.IntType // LOCATION.COLUMN_NUMBER + nodePropertyDescriptors(1015) = FormalQtyType.QtyOption nodePropertyDescriptors(1894) = FormalQtyType.StringType // LOCATION.FILENAME nodePropertyDescriptors(1895) = FormalQtyType.QtyOne nodePropertyDescriptors(3126) = FormalQtyType.IntType // LOCATION.LINE_NUMBER @@ -1240,6 +1242,7 @@ object GraphSchema extends flatgraph.Schema { _newNodeInserters(4708) = nodes.NewLocal.InsertionHelpers.NewNodeInserter_Local_typeFullName _newNodeInserters(574) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_className _newNodeInserters(662) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_classShortName + _newNodeInserters(1014) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_columnNumber _newNodeInserters(1894) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_filename _newNodeInserters(3126) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_lineNumber _newNodeInserters(3302) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_methodFullName @@ -1618,6 +1621,7 @@ object GraphSchema extends flatgraph.Schema { Set( "CLASS_NAME", "CLASS_SHORT_NAME", + "COLUMN_NUMBER", "FILENAME", "LINE_NUMBER", "METHOD_FULL_NAME", diff --git a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/accessors/Accessors.scala b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/accessors/Accessors.scala index 5ab8b4d11..779276578 100644 --- a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/accessors/Accessors.scala +++ b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/accessors/Accessors.scala @@ -492,6 +492,10 @@ object Accessors { case stored: nodes.StoredNode => new AccessPropertyClassShortName(stored).classShortName case newNode: nodes.NewLocation => newNode.classShortName } + def columnNumber: Option[Int] = node match { + case stored: nodes.StoredNode => new AccessPropertyColumnNumber(stored).columnNumber + case newNode: nodes.NewLocation => newNode.columnNumber + } def filename: String = node match { case stored: nodes.StoredNode => new AccessPropertyFilename(stored).filename case newNode: nodes.NewLocation => newNode.filename diff --git a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/Location.scala b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/Location.scala index 2fcd0351c..9d5587c95 100644 --- a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/Location.scala +++ b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/Location.scala @@ -11,6 +11,7 @@ trait LocationEMT extends AnyRef with HasClassNameEMT with HasClassShortNameEMT + with HasColumnNumberEMT with HasFilenameEMT with HasLineNumberEMT with HasMethodFullNameEMT @@ -26,6 +27,7 @@ trait LocationBase extends AbstractNode with StaticType[LocationEMT] { val res = new java.util.HashMap[String, Any]() if (("": String) != this.className) res.put("CLASS_NAME", this.className) if (("": String) != this.classShortName) res.put("CLASS_SHORT_NAME", this.classShortName) + this.columnNumber.foreach { p => res.put("COLUMN_NUMBER", p) } if (("": String) != this.filename) res.put("FILENAME", this.filename) this.lineNumber.foreach { p => res.put("LINE_NUMBER", p) } if (("": String) != this.methodFullName) res.put("METHOD_FULL_NAME", this.methodFullName) @@ -46,6 +48,10 @@ object Location { val ClassShortName = "CLASS_SHORT_NAME" + /** This optional fields provides the column number of the program construct represented by the node. + */ + val ColumnNumber = "COLUMN_NUMBER" + /** The path of the source file this node was generated from, relative to the root path in the meta data node. This * field must be set but may be set to the value `` to indicate that no source file can be associated with * the node, e.g., because the node represents an entity known to exist because it is referenced, but for which the @@ -75,6 +81,10 @@ object Location { val ClassName = flatgraph.SinglePropertyKey[String](kind = 6, name = "CLASS_NAME", default = "") val ClassShortName = flatgraph.SinglePropertyKey[String](kind = 7, name = "CLASS_SHORT_NAME", default = "") + /** This optional fields provides the column number of the program construct represented by the node. + */ + val ColumnNumber = flatgraph.OptionalPropertyKey[Int](kind = 11, name = "COLUMN_NUMBER") + /** The path of the source file this node was generated from, relative to the root path in the meta data node. This * field must be set but may be set to the value `` to indicate that no source file can be associated with * the node, e.g., because the node represents an entity known to exist because it is referenced, but for which the @@ -116,36 +126,38 @@ class Location(graph_4762: flatgraph.Graph, seq_4762: Int) override def productElementName(n: Int): String = n match { - case 0 => "className" - case 1 => "classShortName" - case 2 => "filename" - case 3 => "lineNumber" - case 4 => "methodFullName" - case 5 => "methodShortName" - case 6 => "nodeLabel" - case 7 => "packageName" - case 8 => "symbol" - case 9 => "node" - case _ => "" + case 0 => "className" + case 1 => "classShortName" + case 2 => "columnNumber" + case 3 => "filename" + case 4 => "lineNumber" + case 5 => "methodFullName" + case 6 => "methodShortName" + case 7 => "nodeLabel" + case 8 => "packageName" + case 9 => "symbol" + case 10 => "node" + case _ => "" } override def productElement(n: Int): Any = n match { - case 0 => this.className - case 1 => this.classShortName - case 2 => this.filename - case 3 => this.lineNumber - case 4 => this.methodFullName - case 5 => this.methodShortName - case 6 => this.nodeLabel - case 7 => this.packageName - case 8 => this.symbol - case 9 => this.node - case _ => null + case 0 => this.className + case 1 => this.classShortName + case 2 => this.columnNumber + case 3 => this.filename + case 4 => this.lineNumber + case 5 => this.methodFullName + case 6 => this.methodShortName + case 7 => this.nodeLabel + case 8 => this.packageName + case 9 => this.symbol + case 10 => this.node + case _ => null } override def productPrefix = "Location" - override def productArity = 10 + override def productArity = 11 override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[Location] } @@ -206,6 +218,35 @@ object NewLocation { } } } + object NewNodeInserter_Location_columnNumber extends flatgraph.NewNodePropertyInsertionHelper { + override def insertNewNodeProperties( + newNodes: mutable.ArrayBuffer[flatgraph.DNode], + dst: AnyRef, + offsets: Array[Int] + ): Unit = { + if (newNodes.isEmpty) return + val dstCast = dst.asInstanceOf[Array[Int]] + val seq = newNodes.head.storedRef.get.seq() + var offset = offsets(seq) + var idx = 0 + while (idx < newNodes.length) { + val nn = newNodes(idx) + nn match { + case generated: NewLocation => + generated.columnNumber match { + case Some(item) => + dstCast(offset) = item + offset += 1 + case _ => + } + case _ => + } + assert(seq + idx == nn.storedRef.get.seq(), "internal consistency check") + idx += 1 + offsets(idx + seq) = offset + } + } + } object NewNodeInserter_Location_filename extends flatgraph.NewNodePropertyInsertionHelper { override def insertNewNodeProperties( newNodes: mutable.ArrayBuffer[flatgraph.DNode], @@ -433,6 +474,7 @@ class NewLocation extends NewNode(23.toShort) with LocationBase { var className: String = "": String var classShortName: String = "": String + var columnNumber: Option[Int] = None var filename: String = "": String var lineNumber: Option[Int] = None var methodFullName: String = "": String @@ -443,6 +485,8 @@ class NewLocation extends NewNode(23.toShort) with LocationBase { var symbol: String = "": String def className(value: String): this.type = { this.className = value; this } def classShortName(value: String): this.type = { this.classShortName = value; this } + def columnNumber(value: Int): this.type = { this.columnNumber = Option(value); this } + def columnNumber(value: Option[Int]): this.type = { this.columnNumber = value; this } def filename(value: String): this.type = { this.filename = value; this } def lineNumber(value: Int): this.type = { this.lineNumber = Option(value); this } def lineNumber(value: Option[Int]): this.type = { this.lineNumber = value; this } @@ -456,6 +500,7 @@ class NewLocation extends NewNode(23.toShort) with LocationBase { override def countAndVisitProperties(interface: flatgraph.BatchedUpdateInterface): Unit = { interface.countProperty(this, 6, 1) interface.countProperty(this, 7, 1) + interface.countProperty(this, 11, columnNumber.size) interface.countProperty(this, 21, 1) interface.countProperty(this, 35, lineNumber.size) interface.countProperty(this, 37, 1) @@ -471,6 +516,7 @@ class NewLocation extends NewNode(23.toShort) with LocationBase { val newInstance = new NewLocation newInstance.className = this.className newInstance.classShortName = this.classShortName + newInstance.columnNumber = this.columnNumber newInstance.filename = this.filename newInstance.lineNumber = this.lineNumber newInstance.methodFullName = this.methodFullName @@ -484,35 +530,37 @@ class NewLocation extends NewNode(23.toShort) with LocationBase { override def productElementName(n: Int): String = n match { - case 0 => "className" - case 1 => "classShortName" - case 2 => "filename" - case 3 => "lineNumber" - case 4 => "methodFullName" - case 5 => "methodShortName" - case 6 => "nodeLabel" - case 7 => "packageName" - case 8 => "symbol" - case 9 => "node" - case _ => "" + case 0 => "className" + case 1 => "classShortName" + case 2 => "columnNumber" + case 3 => "filename" + case 4 => "lineNumber" + case 5 => "methodFullName" + case 6 => "methodShortName" + case 7 => "nodeLabel" + case 8 => "packageName" + case 9 => "symbol" + case 10 => "node" + case _ => "" } override def productElement(n: Int): Any = n match { - case 0 => this.className - case 1 => this.classShortName - case 2 => this.filename - case 3 => this.lineNumber - case 4 => this.methodFullName - case 5 => this.methodShortName - case 6 => this.nodeLabel - case 7 => this.packageName - case 8 => this.symbol - case 9 => this.node - case _ => null + case 0 => this.className + case 1 => this.classShortName + case 2 => this.columnNumber + case 3 => this.filename + case 4 => this.lineNumber + case 5 => this.methodFullName + case 6 => this.methodShortName + case 7 => this.nodeLabel + case 8 => this.packageName + case 9 => this.symbol + case 10 => this.node + case _ => null } override def productPrefix = "NewLocation" - override def productArity = 10 + override def productArity = 11 override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[NewLocation] } diff --git a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/traversals/TraversalLocationBase.scala b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/traversals/TraversalLocationBase.scala index 241e659a7..ff13b2e7e 100644 --- a/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/traversals/TraversalLocationBase.scala +++ b/domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/traversals/TraversalLocationBase.scala @@ -141,6 +141,70 @@ final class TraversalLocationBase[NodeType <: nodes.LocationBase](val traversal: traversal.filter { item => matchers.find { _.reset(item.classShortName).matches }.isEmpty } } + /** Traverse to columnNumber property */ + def columnNumber: Iterator[Int] = + traversal.flatMap(_.columnNumber) + + /** Traverse to nodes where the columnNumber equals the given `value` + */ + def columnNumber(value: Int): Iterator[NodeType] = + traversal.filter { node => + val tmp = node.columnNumber; tmp.isDefined && tmp.get == value + } + + /** Traverse to nodes where the columnNumber equals at least one of the given `values` + */ + def columnNumber(values: Int*): Iterator[NodeType] = { + val vset = values.toSet + traversal.filter { node => + val tmp = node.columnNumber; tmp.isDefined && vset.contains(tmp.get) + } + } + + /** Traverse to nodes where the columnNumber is not equal to the given `value` + */ + def columnNumberNot(value: Int): Iterator[NodeType] = + traversal.filter { node => + val tmp = node.columnNumber; tmp.isEmpty || tmp.get != value + } + + /** Traverse to nodes where the columnNumber does not equal any one of the given `values` + */ + def columnNumberNot(values: Int*): Iterator[NodeType] = { + val vset = values.toSet + traversal.filter { node => + val tmp = node.columnNumber; tmp.isEmpty || !vset.contains(tmp.get) + } + } + + /** Traverse to nodes where the columnNumber is greater than the given `value` + */ + def columnNumberGt(value: Int): Iterator[NodeType] = + traversal.filter { node => + val tmp = node.columnNumber; tmp.isDefined && tmp.get > value + } + + /** Traverse to nodes where the columnNumber is greater than or equal the given `value` + */ + def columnNumberGte(value: Int): Iterator[NodeType] = + traversal.filter { node => + val tmp = node.columnNumber; tmp.isDefined && tmp.get >= value + } + + /** Traverse to nodes where the columnNumber is less than the given `value` + */ + def columnNumberLt(value: Int): Iterator[NodeType] = + traversal.filter { node => + val tmp = node.columnNumber; tmp.isDefined && tmp.get < value + } + + /** Traverse to nodes where the columnNumber is less than or equal the given `value` + */ + def columnNumberLte(value: Int): Iterator[NodeType] = + traversal.filter { node => + val tmp = node.columnNumber; tmp.isDefined && tmp.get <= value + } + /** Traverse to filename property */ def filename: Iterator[String] = traversal.map(_.filename) diff --git a/schema/src/main/scala/io/shiftleft/codepropertygraph/schema/TagsAndLocation.scala b/schema/src/main/scala/io/shiftleft/codepropertygraph/schema/TagsAndLocation.scala index 06b88be2c..01184e2f4 100644 --- a/schema/src/main/scala/io/shiftleft/codepropertygraph/schema/TagsAndLocation.scala +++ b/schema/src/main/scala/io/shiftleft/codepropertygraph/schema/TagsAndLocation.scala @@ -99,7 +99,8 @@ object TagsAndLocation extends SchemaBase { className, classShortName, nodeLabel, - filename + filename, + columnNumber ) val tagNodePair: NodeType = builder