Skip to content

Commit 1f7305c

Browse files
authored
add column number to location (#1812)
1 parent 0c7f719 commit 1f7305c

File tree

5 files changed

+168
-47
lines changed

5 files changed

+168
-47
lines changed

Diff for: domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/GraphSchema.scala

+4
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ object GraphSchema extends flatgraph.Schema {
668668
nodePropertyDescriptors(575) = FormalQtyType.QtyOne
669669
nodePropertyDescriptors(662) = FormalQtyType.StringType // LOCATION.CLASS_SHORT_NAME
670670
nodePropertyDescriptors(663) = FormalQtyType.QtyOne
671+
nodePropertyDescriptors(1014) = FormalQtyType.IntType // LOCATION.COLUMN_NUMBER
672+
nodePropertyDescriptors(1015) = FormalQtyType.QtyOption
671673
nodePropertyDescriptors(1894) = FormalQtyType.StringType // LOCATION.FILENAME
672674
nodePropertyDescriptors(1895) = FormalQtyType.QtyOne
673675
nodePropertyDescriptors(3126) = FormalQtyType.IntType // LOCATION.LINE_NUMBER
@@ -1240,6 +1242,7 @@ object GraphSchema extends flatgraph.Schema {
12401242
_newNodeInserters(4708) = nodes.NewLocal.InsertionHelpers.NewNodeInserter_Local_typeFullName
12411243
_newNodeInserters(574) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_className
12421244
_newNodeInserters(662) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_classShortName
1245+
_newNodeInserters(1014) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_columnNumber
12431246
_newNodeInserters(1894) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_filename
12441247
_newNodeInserters(3126) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_lineNumber
12451248
_newNodeInserters(3302) = nodes.NewLocation.InsertionHelpers.NewNodeInserter_Location_methodFullName
@@ -1618,6 +1621,7 @@ object GraphSchema extends flatgraph.Schema {
16181621
Set(
16191622
"CLASS_NAME",
16201623
"CLASS_SHORT_NAME",
1624+
"COLUMN_NUMBER",
16211625
"FILENAME",
16221626
"LINE_NUMBER",
16231627
"METHOD_FULL_NAME",

Diff for: domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/accessors/Accessors.scala

+4
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ object Accessors {
492492
case stored: nodes.StoredNode => new AccessPropertyClassShortName(stored).classShortName
493493
case newNode: nodes.NewLocation => newNode.classShortName
494494
}
495+
def columnNumber: Option[Int] = node match {
496+
case stored: nodes.StoredNode => new AccessPropertyColumnNumber(stored).columnNumber
497+
case newNode: nodes.NewLocation => newNode.columnNumber
498+
}
495499
def filename: String = node match {
496500
case stored: nodes.StoredNode => new AccessPropertyFilename(stored).filename
497501
case newNode: nodes.NewLocation => newNode.filename

Diff for: domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/Location.scala

+94-46
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ trait LocationEMT
1111
extends AnyRef
1212
with HasClassNameEMT
1313
with HasClassShortNameEMT
14+
with HasColumnNumberEMT
1415
with HasFilenameEMT
1516
with HasLineNumberEMT
1617
with HasMethodFullNameEMT
@@ -26,6 +27,7 @@ trait LocationBase extends AbstractNode with StaticType[LocationEMT] {
2627
val res = new java.util.HashMap[String, Any]()
2728
if (("<empty>": String) != this.className) res.put("CLASS_NAME", this.className)
2829
if (("<empty>": String) != this.classShortName) res.put("CLASS_SHORT_NAME", this.classShortName)
30+
this.columnNumber.foreach { p => res.put("COLUMN_NUMBER", p) }
2931
if (("<empty>": String) != this.filename) res.put("FILENAME", this.filename)
3032
this.lineNumber.foreach { p => res.put("LINE_NUMBER", p) }
3133
if (("<empty>": String) != this.methodFullName) res.put("METHOD_FULL_NAME", this.methodFullName)
@@ -46,6 +48,10 @@ object Location {
4648

4749
val ClassShortName = "CLASS_SHORT_NAME"
4850

51+
/** This optional fields provides the column number of the program construct represented by the node.
52+
*/
53+
val ColumnNumber = "COLUMN_NUMBER"
54+
4955
/** The path of the source file this node was generated from, relative to the root path in the meta data node. This
5056
* field must be set but may be set to the value `<unknown>` to indicate that no source file can be associated with
5157
* 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 {
7581
val ClassName = flatgraph.SinglePropertyKey[String](kind = 6, name = "CLASS_NAME", default = "<empty>")
7682
val ClassShortName = flatgraph.SinglePropertyKey[String](kind = 7, name = "CLASS_SHORT_NAME", default = "<empty>")
7783

84+
/** This optional fields provides the column number of the program construct represented by the node.
85+
*/
86+
val ColumnNumber = flatgraph.OptionalPropertyKey[Int](kind = 11, name = "COLUMN_NUMBER")
87+
7888
/** The path of the source file this node was generated from, relative to the root path in the meta data node. This
7989
* field must be set but may be set to the value `<unknown>` to indicate that no source file can be associated with
8090
* 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)
116126

117127
override def productElementName(n: Int): String =
118128
n match {
119-
case 0 => "className"
120-
case 1 => "classShortName"
121-
case 2 => "filename"
122-
case 3 => "lineNumber"
123-
case 4 => "methodFullName"
124-
case 5 => "methodShortName"
125-
case 6 => "nodeLabel"
126-
case 7 => "packageName"
127-
case 8 => "symbol"
128-
case 9 => "node"
129-
case _ => ""
129+
case 0 => "className"
130+
case 1 => "classShortName"
131+
case 2 => "columnNumber"
132+
case 3 => "filename"
133+
case 4 => "lineNumber"
134+
case 5 => "methodFullName"
135+
case 6 => "methodShortName"
136+
case 7 => "nodeLabel"
137+
case 8 => "packageName"
138+
case 9 => "symbol"
139+
case 10 => "node"
140+
case _ => ""
130141
}
131142

132143
override def productElement(n: Int): Any =
133144
n match {
134-
case 0 => this.className
135-
case 1 => this.classShortName
136-
case 2 => this.filename
137-
case 3 => this.lineNumber
138-
case 4 => this.methodFullName
139-
case 5 => this.methodShortName
140-
case 6 => this.nodeLabel
141-
case 7 => this.packageName
142-
case 8 => this.symbol
143-
case 9 => this.node
144-
case _ => null
145+
case 0 => this.className
146+
case 1 => this.classShortName
147+
case 2 => this.columnNumber
148+
case 3 => this.filename
149+
case 4 => this.lineNumber
150+
case 5 => this.methodFullName
151+
case 6 => this.methodShortName
152+
case 7 => this.nodeLabel
153+
case 8 => this.packageName
154+
case 9 => this.symbol
155+
case 10 => this.node
156+
case _ => null
145157
}
146158

147159
override def productPrefix = "Location"
148-
override def productArity = 10
160+
override def productArity = 11
149161

150162
override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[Location]
151163
}
@@ -206,6 +218,35 @@ object NewLocation {
206218
}
207219
}
208220
}
221+
object NewNodeInserter_Location_columnNumber extends flatgraph.NewNodePropertyInsertionHelper {
222+
override def insertNewNodeProperties(
223+
newNodes: mutable.ArrayBuffer[flatgraph.DNode],
224+
dst: AnyRef,
225+
offsets: Array[Int]
226+
): Unit = {
227+
if (newNodes.isEmpty) return
228+
val dstCast = dst.asInstanceOf[Array[Int]]
229+
val seq = newNodes.head.storedRef.get.seq()
230+
var offset = offsets(seq)
231+
var idx = 0
232+
while (idx < newNodes.length) {
233+
val nn = newNodes(idx)
234+
nn match {
235+
case generated: NewLocation =>
236+
generated.columnNumber match {
237+
case Some(item) =>
238+
dstCast(offset) = item
239+
offset += 1
240+
case _ =>
241+
}
242+
case _ =>
243+
}
244+
assert(seq + idx == nn.storedRef.get.seq(), "internal consistency check")
245+
idx += 1
246+
offsets(idx + seq) = offset
247+
}
248+
}
249+
}
209250
object NewNodeInserter_Location_filename extends flatgraph.NewNodePropertyInsertionHelper {
210251
override def insertNewNodeProperties(
211252
newNodes: mutable.ArrayBuffer[flatgraph.DNode],
@@ -433,6 +474,7 @@ class NewLocation extends NewNode(23.toShort) with LocationBase {
433474

434475
var className: String = "<empty>": String
435476
var classShortName: String = "<empty>": String
477+
var columnNumber: Option[Int] = None
436478
var filename: String = "<empty>": String
437479
var lineNumber: Option[Int] = None
438480
var methodFullName: String = "<empty>": String
@@ -443,6 +485,8 @@ class NewLocation extends NewNode(23.toShort) with LocationBase {
443485
var symbol: String = "<empty>": String
444486
def className(value: String): this.type = { this.className = value; this }
445487
def classShortName(value: String): this.type = { this.classShortName = value; this }
488+
def columnNumber(value: Int): this.type = { this.columnNumber = Option(value); this }
489+
def columnNumber(value: Option[Int]): this.type = { this.columnNumber = value; this }
446490
def filename(value: String): this.type = { this.filename = value; this }
447491
def lineNumber(value: Int): this.type = { this.lineNumber = Option(value); this }
448492
def lineNumber(value: Option[Int]): this.type = { this.lineNumber = value; this }
@@ -456,6 +500,7 @@ class NewLocation extends NewNode(23.toShort) with LocationBase {
456500
override def countAndVisitProperties(interface: flatgraph.BatchedUpdateInterface): Unit = {
457501
interface.countProperty(this, 6, 1)
458502
interface.countProperty(this, 7, 1)
503+
interface.countProperty(this, 11, columnNumber.size)
459504
interface.countProperty(this, 21, 1)
460505
interface.countProperty(this, 35, lineNumber.size)
461506
interface.countProperty(this, 37, 1)
@@ -471,6 +516,7 @@ class NewLocation extends NewNode(23.toShort) with LocationBase {
471516
val newInstance = new NewLocation
472517
newInstance.className = this.className
473518
newInstance.classShortName = this.classShortName
519+
newInstance.columnNumber = this.columnNumber
474520
newInstance.filename = this.filename
475521
newInstance.lineNumber = this.lineNumber
476522
newInstance.methodFullName = this.methodFullName
@@ -484,35 +530,37 @@ class NewLocation extends NewNode(23.toShort) with LocationBase {
484530

485531
override def productElementName(n: Int): String =
486532
n match {
487-
case 0 => "className"
488-
case 1 => "classShortName"
489-
case 2 => "filename"
490-
case 3 => "lineNumber"
491-
case 4 => "methodFullName"
492-
case 5 => "methodShortName"
493-
case 6 => "nodeLabel"
494-
case 7 => "packageName"
495-
case 8 => "symbol"
496-
case 9 => "node"
497-
case _ => ""
533+
case 0 => "className"
534+
case 1 => "classShortName"
535+
case 2 => "columnNumber"
536+
case 3 => "filename"
537+
case 4 => "lineNumber"
538+
case 5 => "methodFullName"
539+
case 6 => "methodShortName"
540+
case 7 => "nodeLabel"
541+
case 8 => "packageName"
542+
case 9 => "symbol"
543+
case 10 => "node"
544+
case _ => ""
498545
}
499546

500547
override def productElement(n: Int): Any =
501548
n match {
502-
case 0 => this.className
503-
case 1 => this.classShortName
504-
case 2 => this.filename
505-
case 3 => this.lineNumber
506-
case 4 => this.methodFullName
507-
case 5 => this.methodShortName
508-
case 6 => this.nodeLabel
509-
case 7 => this.packageName
510-
case 8 => this.symbol
511-
case 9 => this.node
512-
case _ => null
549+
case 0 => this.className
550+
case 1 => this.classShortName
551+
case 2 => this.columnNumber
552+
case 3 => this.filename
553+
case 4 => this.lineNumber
554+
case 5 => this.methodFullName
555+
case 6 => this.methodShortName
556+
case 7 => this.nodeLabel
557+
case 8 => this.packageName
558+
case 9 => this.symbol
559+
case 10 => this.node
560+
case _ => null
513561
}
514562

515563
override def productPrefix = "NewLocation"
516-
override def productArity = 10
564+
override def productArity = 11
517565
override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[NewLocation]
518566
}

Diff for: domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/traversals/TraversalLocationBase.scala

+64
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,70 @@ final class TraversalLocationBase[NodeType <: nodes.LocationBase](val traversal:
141141
traversal.filter { item => matchers.find { _.reset(item.classShortName).matches }.isEmpty }
142142
}
143143

144+
/** Traverse to columnNumber property */
145+
def columnNumber: Iterator[Int] =
146+
traversal.flatMap(_.columnNumber)
147+
148+
/** Traverse to nodes where the columnNumber equals the given `value`
149+
*/
150+
def columnNumber(value: Int): Iterator[NodeType] =
151+
traversal.filter { node =>
152+
val tmp = node.columnNumber; tmp.isDefined && tmp.get == value
153+
}
154+
155+
/** Traverse to nodes where the columnNumber equals at least one of the given `values`
156+
*/
157+
def columnNumber(values: Int*): Iterator[NodeType] = {
158+
val vset = values.toSet
159+
traversal.filter { node =>
160+
val tmp = node.columnNumber; tmp.isDefined && vset.contains(tmp.get)
161+
}
162+
}
163+
164+
/** Traverse to nodes where the columnNumber is not equal to the given `value`
165+
*/
166+
def columnNumberNot(value: Int): Iterator[NodeType] =
167+
traversal.filter { node =>
168+
val tmp = node.columnNumber; tmp.isEmpty || tmp.get != value
169+
}
170+
171+
/** Traverse to nodes where the columnNumber does not equal any one of the given `values`
172+
*/
173+
def columnNumberNot(values: Int*): Iterator[NodeType] = {
174+
val vset = values.toSet
175+
traversal.filter { node =>
176+
val tmp = node.columnNumber; tmp.isEmpty || !vset.contains(tmp.get)
177+
}
178+
}
179+
180+
/** Traverse to nodes where the columnNumber is greater than the given `value`
181+
*/
182+
def columnNumberGt(value: Int): Iterator[NodeType] =
183+
traversal.filter { node =>
184+
val tmp = node.columnNumber; tmp.isDefined && tmp.get > value
185+
}
186+
187+
/** Traverse to nodes where the columnNumber is greater than or equal the given `value`
188+
*/
189+
def columnNumberGte(value: Int): Iterator[NodeType] =
190+
traversal.filter { node =>
191+
val tmp = node.columnNumber; tmp.isDefined && tmp.get >= value
192+
}
193+
194+
/** Traverse to nodes where the columnNumber is less than the given `value`
195+
*/
196+
def columnNumberLt(value: Int): Iterator[NodeType] =
197+
traversal.filter { node =>
198+
val tmp = node.columnNumber; tmp.isDefined && tmp.get < value
199+
}
200+
201+
/** Traverse to nodes where the columnNumber is less than or equal the given `value`
202+
*/
203+
def columnNumberLte(value: Int): Iterator[NodeType] =
204+
traversal.filter { node =>
205+
val tmp = node.columnNumber; tmp.isDefined && tmp.get <= value
206+
}
207+
144208
/** Traverse to filename property */
145209
def filename: Iterator[String] =
146210
traversal.map(_.filename)

Diff for: schema/src/main/scala/io/shiftleft/codepropertygraph/schema/TagsAndLocation.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ object TagsAndLocation extends SchemaBase {
9999
className,
100100
classShortName,
101101
nodeLabel,
102-
filename
102+
filename,
103+
columnNumber
103104
)
104105

105106
val tagNodePair: NodeType = builder

0 commit comments

Comments
 (0)