nodeService

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGlobalVariableSteps

func AddGlobalVariableSteps(dataFlow []models.DataFlowStep, root *sitter.Node, content []byte, lineNumber uint32) []models.DataFlowStep

----------------------------------------------------------------------------- AddGlobalVariableSteps - Adds global variable declaration steps for all unique variables in the data flow steps. -----------------------------------------------------------------------------

Parameters:

  • dataFlow ([]models.DataFlowStep): The data flow steps to process.
  • root (*sitter.Node): The root node of the syntax tree.
  • content ([]byte): The content of the source code.
  • lineNumber (uint32): The line number to use for generic usage steps.

Returns:

  • ([]models.DataFlowStep): The updated data flow steps with global variable declaration steps.

-----------------------------------------------------------------------------

func ExtractFunctionNameFromCall

func ExtractFunctionNameFromCall(node *sitter.Node, content []byte) string

----------------------------------------------------------------------------- ExtractFunctionNameFromCall - Extracts the function name from a function call node. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The function call node.
  • content ([]byte): The content of the source code.

Returns:

  • (string): The name of the function being called.

-----------------------------------------------------------------------------

func FindCallExpression

func FindCallExpression(node *sitter.Node) *sitter.Node

----------------------------------------------------------------------------- FindCallExpression - Finds the call expression node in a given node for multiple languages. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node to search for a call expression.

Returns:

  • (*sitter.Node): The call expression node if found, otherwise nil.

-----------------------------------------------------------------------------

func FindFunctionBounds

func FindFunctionBounds(root *sitter.Node, node *sitter.Node, startLine uint32) (functionStart, functionEnd uint32)

----------------------------------------------------------------------------- FindFunctionBounds - Finds the start and end lines of a function containing the specified line. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • node (*sitter.Node): The node to check if it is a function declaration.
  • startLine (uint32): The line number to search for.

Returns:

  • (functionStart, functionEnd uint32): The start and end lines of the function.

-----------------------------------------------------------------------------

func FindFunctionByLine

func FindFunctionByLine(root *sitter.Node, line uint32, lang string) *sitter.Node

----------------------------------------------------------------------------- FindFunctionByLine - Finds the function node that contains the specified line. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • line (uint32): The line number to search for.
  • lang (string): The programming language of the source code.

Returns:

  • (*sitter.Node): The node representing the function if found, otherwise nil.

-----------------------------------------------------------------------------

func FindFunctionByName

func FindFunctionByName(root *sitter.Node, name string, content []byte) *sitter.Node

----------------------------------------------------------------------------- FindFunctionDeclaration - Finds the declaration of a function by its name in the syntax tree. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • functionName (string): The name of the function to find.
  • content ([]byte): The content of the source code.

Returns:

  • (*sitter.Node): The node representing the function declaration if found, otherwise nil.

-----------------------------------------------------------------------------

func FindFunctionCallSites

func FindFunctionCallSites(root *sitter.Node, functionName string, content []byte) []models.FunctionCallSite

----------------------------------------------------------------------------- FindFunctionCallSites - Searches all lines where a specific function is called. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • functionName (string): The name of the function to search for.
  • content ([]byte): The content of the source code.

Returns:

  • ([]models.FunctionCallSite): A slice of function call sites.

-----------------------------------------------------------------------------

func FindFunctionDeclaration

func FindFunctionDeclaration(root *sitter.Node, functionName string, content []byte) *sitter.Node

----------------------------------------------------------------------------- FindFunctionDeclaration - Finds the declaration of a function by its name in the syntax tree. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • functionName (string): The name of the function to find.
  • content ([]byte): The content of the source code.

Returns:

  • (*sitter.Node): The node representing the function declaration if found, otherwise nil.

-----------------------------------------------------------------------------

func FindGlobalVariableDeclaration

func FindGlobalVariableDeclaration(root *sitter.Node, variable string, content []byte) *sitter.Node

----------------------------------------------------------------------------- FindGlobalVariableDeclaration - Finds the declaration of a global variable in the syntax tree. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • variable (string): The name of the variable to search for.
  • content ([]byte): The content of the source code.

Returns:

  • (*sitter.Node): The node representing the global variable declaration if found, otherwise nil.

-----------------------------------------------------------------------------

func FindNodeAtLine

func FindNodeAtLine(node *sitter.Node, targetLine uint32) *sitter.Node

----------------------------------------------------------------------------- FindNodeAtLine - Finds the node at the specified line in the syntax tree. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The root node of the syntax tree.
  • targetLine (uint32): The line number to search for.

Returns:

  • (*sitter.Node): The node at the specified line if found, otherwise nil.

-----------------------------------------------------------------------------

func FindParentFunction

func FindParentFunction(node *sitter.Node, content []byte) string

----------------------------------------------------------------------------- FindParentFunction - Finds the name of the parent function for a given node. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node for which to find the parent function.
  • content ([]byte): The content of the source code.

Returns:

  • (string): The name of the parent function if found, otherwise an empty string.

-----------------------------------------------------------------------------

func GetArgumentVariable

func GetArgumentVariable(callNode *sitter.Node, parameterVariable string, functionNode *sitter.Node, content []byte) string

----------------------------------------------------------------------------- GetArgumentVariable - Finds the argument variable corresponding to a parameter variable in a function call. -----------------------------------------------------------------------------

Parameters:

  • callNode (*sitter.Node): The function call node.
  • parameterVariable (string): The parameter variable to search for.
  • functionNode (*sitter.Node): The function node containing the parameter.
  • content ([]byte): The content of the source code.

Returns:

  • (string): The argument variable corresponding to the parameter variable.

-----------------------------------------------------------------------------

func GetControlType

func GetControlType(nodeType string) string

----------------------------------------------------------------------------- GetControlType - Returns a descriptive string for control flow statements across multiple languages. -----------------------------------------------------------------------------

Parameters:

  • nodeType (string): The type of the node.

Returns:

  • (string): A descriptive string for the control flow statement.

-----------------------------------------------------------------------------

func GetParameterName

func GetParameterName(functionNode *sitter.Node, content []byte, originalVariable string, callSite *sitter.Node) string

----------------------------------------------------------------------------- GetParameterName - Finds the name of the parameter corresponding to a variable in a function call. -----------------------------------------------------------------------------

Parameters:

  • functionNode (*sitter.Node): The function node containing the parameter.
  • content ([]byte): The content of the source code.
  • originalVariable (string): The original variable name.
  • callSite (*sitter.Node): The function call node.

Returns:

  • (string): The name of the parameter corresponding to the variable.

-----------------------------------------------------------------------------

func IsAssignment

func IsAssignment(node *sitter.Node, content []byte, variable string) (bool, string)

----------------------------------------------------------------------------- IsAssignment - Checks if a variable is used in an assignment or declaration across multiple languages. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node to check.
  • content ([]byte): The content of the source code.
  • variable (string): The variable to check for.

Returns:

  • (bool, string): True if the variable is found in the assignment, and the value assigned to it.

-----------------------------------------------------------------------------

func IsClassFieldAssignment

func IsClassFieldAssignment(node *sitter.Node, content []byte, variable string) bool

----------------------------------------------------------------------------- IsClassFieldAssignment - Checks if a node represents an assignment to a class field. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node to check.
  • content ([]byte): The content of the source code.
  • variable (string): The variable to check for.

Returns:

  • (bool): True if the node represents an assignment to the class field, false otherwise.

-----------------------------------------------------------------------------

func IsFunctionCall

func IsFunctionCall(node *sitter.Node, content []byte, variable string) (bool, string)

----------------------------------------------------------------------------- IsFunctionCall - Checks if the node represents a function call involving the given variable. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node to check.
  • content ([]byte): The content of the source code.
  • variable (string): The variable to check for.

Returns:

  • (bool, string): True if the node represents a function call involving the variable, and the variable name if assigned.

-----------------------------------------------------------------------------

func IsFunctionDeclaration

func IsFunctionDeclaration(root, node *sitter.Node, content []byte) string

----------------------------------------------------------------------------- IsFunctionDeclaration - Determines if a node represents a function declaration. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • node (*sitter.Node): The node to check if it is a function declaration.
  • content ([]byte): The content of the source code.

Returns:

  • (string): The name of the function if the node is a function declaration, otherwise an empty string.

-----------------------------------------------------------------------------

func IsFunctionDeclared

func IsFunctionDeclared(root *sitter.Node, functionName string, content []byte) bool

----------------------------------------------------------------------------- IsFunctionDeclared - Checks if a function with the given name is declared in the syntax tree. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • functionName (string): The name of the function to search for.
  • content ([]byte): The content of the source code.

Returns:

  • (bool): True if the function is declared, false otherwise.

-----------------------------------------------------------------------------

func IsLiteral

func IsLiteral(node *sitter.Node) bool

----------------------------------------------------------------------------- IsLiteral - Checks if the node represents a literal value in the syntax tree. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node to check.

Returns:

  • (bool): True if the node represents a literal value, false otherwise.

-----------------------------------------------------------------------------

func IsValidVariableToTrack

func IsValidVariableToTrack(root *sitter.Node, variable string, content []byte) bool

----------------------------------------------------------------------------- IsValidVariableToTrack - Verifies if the variable name corresponds to a function declaration. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • variable (string): The variable name to check.
  • content ([]byte): The content of the source code.

Returns:

  • (bool): True if the variable name does not correspond to a function declaration, false otherwise.

-----------------------------------------------------------------------------

func IsVariableGlobal

func IsVariableGlobal(root *sitter.Node, variable string, content []byte) bool

----------------------------------------------------------------------------- IsVariableGlobal - Checks if a variable is global within the provided root node. -----------------------------------------------------------------------------

Parameters:

  • root (*sitter.Node): The root node of the syntax tree.
  • variable (string): The name of the variable to check.
  • content ([]byte): The content of the source code.

Returns:

  • (bool): True if the variable is global, false otherwise.

-----------------------------------------------------------------------------

func IsVariableInScope

func IsVariableInScope(varName string, functionNode *sitter.Node, content []byte) bool

----------------------------------------------------------------------------- IsVariableInScope - Checks if the given variable is in scope within the provided function node. -----------------------------------------------------------------------------

Parameters:

  • varName (string): The name of the variable to check.
  • functionNode (*sitter.Node): The function node to check within.
  • content ([]byte): The content of the source code.

Returns:

  • (bool): True if the variable is in scope, false otherwise.

-----------------------------------------------------------------------------

func IsVariableUsedInExpression

func IsVariableUsedInExpression(node *sitter.Node, variable string, content []byte) bool

----------------------------------------------------------------------------- IsVariableUsedInExpression - Checks if a variable is used in an expression within a node. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node to check.
  • variable (string): The variable to check for.
  • content ([]byte): The content of the source code.

Returns:

  • (bool): True if the variable is used in the expression, false otherwise.

-----------------------------------------------------------------------------

func SafeContent

func SafeContent(node *sitter.Node, content []byte) string

----------------------------------------------------------------------------- SafeContent - Securely extracts the content of a node from the content of the file. -----------------------------------------------------------------------------

Parameters:

  • node (*sitter.Node): The node from which to extract content.
  • content ([]byte): The content of the source code.

Returns:

  • (string): The extracted content as a string.

-----------------------------------------------------------------------------

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL