Skip to content

Commit 27c1476

Browse files
mpollmeiermaltek
andauthored
move walkUpAst and walkUpContains into companion object of CfgNodeMethods (#5589)
* move walkUpAst and walkUpContains into companion object of CfgNodeMethods * these don't work on the node of the value class, so it's rather confusing * their code was copied without changes in codescience, this way we can reuse it * privatise * fmt * fmt * Update semanticcpg/src/main/scala/io/shiftleft/semanticcpg/language/nodemethods/CfgNodeMethods.scala Co-authored-by: maltek <1694194+maltek@users.noreply.github.com> * fmt --------- Co-authored-by: maltek <1694194+maltek@users.noreply.github.com>
1 parent d995936 commit 27c1476

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

semanticcpg/src/main/scala/io/shiftleft/semanticcpg/language/nodemethods/CfgNodeMethods.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import io.shiftleft.semanticcpg.language.*
77
import scala.jdk.CollectionConverters.*
88

99
class CfgNodeMethods(val node: CfgNode) extends AnyVal with NodeExtension {
10+
import CfgNodeMethods.*
1011

1112
/** Successors in the CFG
1213
*/
@@ -118,10 +119,20 @@ class CfgNodeMethods(val node: CfgNode) extends AnyVal with NodeExtension {
118119
node.lineNumber.map(_.toLong.toHexString)
119120
}
120121

122+
}
123+
124+
object CfgNodeMethods {
125+
126+
/** Attention: this only works for some special CfgNodes that are guaranteed to always be direct children of a
127+
* method... that's why it's private!
128+
*/
121129
private def walkUpAst(node: CfgNode): Method =
122130
node.astParent.asInstanceOf[Method]
123131

124-
private def walkUpContains(node: StoredNode): Method =
132+
/** Attention: this only works for those `CfgNodes` that have `CONTAINS` edges (see `ContainsEdgePass`)... that's why
133+
* it's private!
134+
*/
135+
private def walkUpContains(node: StoredNode): Method = {
125136
node._containsIn.loneElement("trying to walk `containsIn` edge") match {
126137
case method: Method => method
127138
case typeDecl: TypeDecl =>
@@ -137,5 +148,6 @@ class CfgNodeMethods(val node: CfgNode) extends AnyVal with NodeExtension {
137148
null
138149
}
139150
}
151+
}
140152

141153
}

0 commit comments

Comments
 (0)