-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Create Sources from ClosureBindings over MethodRefs (#2343)
The nodes and edges of `ClosureBinding` and `CAPTURE` hold the information containing which parent identifiers are associated with which child identifiers in children scopes. * Added `DeclarationTraversal` to centralize the ability to use `CAPTURE` and `CLOSURE_BINDING` properties * Leverage these properties instead of naively traversing child methods
- Loading branch information
1 parent
5797650
commit 65f36d3
Showing
3 changed files
with
41 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...iftleft/semanticcpg/language/types/expressions/generalizations/DeclarationTraversal.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.shiftleft.semanticcpg.language.types.expressions.generalizations | ||
|
||
import io.shiftleft.codepropertygraph.generated.nodes.{ClosureBinding, Declaration, MethodRef} | ||
import overflowdb.traversal.{Traversal, help, jIteratortoTraversal} | ||
|
||
/** A declaration, such as a local or parameter. | ||
*/ | ||
@help.Traversal(elementType = classOf[Declaration]) | ||
class DeclarationTraversal[NodeType <: Declaration](val traversal: Traversal[NodeType]) extends AnyVal { | ||
|
||
/** The closure binding node referenced by this declaration | ||
*/ | ||
def closureBinding: Traversal[ClosureBinding] = traversal.flatMap(_._refIn).collectAll[ClosureBinding] | ||
|
||
/** Methods that capture this declaration | ||
*/ | ||
def capturedByMethodRef: Traversal[MethodRef] = closureBinding.flatMap(_._captureIn).collectAll[MethodRef] | ||
|
||
/** Types that capture this declaration | ||
*/ | ||
def capturedByTypeRef: Traversal[MethodRef] = closureBinding.flatMap(_._captureIn).collectAll[MethodRef] | ||
|
||
} |