Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Method declaration has_access routine #28

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions sourcecode-parser/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,30 @@ func buildGraphFromAST(node *sitter.Node, sourceCode []byte, graph *CodeGraph, c
case "method_invocation":
methodName, methodID := extractMethodName(node, sourceCode) // Implement this
invokedNode, exists := graph.Nodes[methodID]
arguments := []string{}
// get argument list from arguments node iterate for child node
for i := 0; i < int(node.ChildCount()); i++ {
if node.Child(i).Type() == "argument_list" {
argumentsNode := node.Child(i)
for j := 0; j < int(argumentsNode.ChildCount()); j++ {
argument := argumentsNode.Child(j)
if argument.Type() == "identifier" {
arguments = append(arguments, argument.Content(sourceCode))
}
}
}
}

if !exists || (exists && invokedNode.ID != methodID) {
// Create a placeholder node for external or inbuilt method
invokedNode = &GraphNode{
ID: methodID,
Type: "method_invocation",
Name: methodName,
IsExternal: true,
CodeSnippet: node.Content(sourceCode),
LineNumber: node.StartPoint().Row + 1, // Lines start from 0 in the AST
ID: methodID,
Type: "method_invocation",
Name: methodName,
IsExternal: true,
CodeSnippet: node.Content(sourceCode),
LineNumber: node.StartPoint().Row + 1, // Lines start from 0 in the AST
MethodArgumentsValue: arguments,
}
graph.AddNode(invokedNode)
}
Expand Down Expand Up @@ -285,6 +300,23 @@ func buildGraphFromAST(node *sitter.Node, sourceCode []byte, graph *CodeGraph, c
child := node.Child(i)
buildGraphFromAST(child, sourceCode, graph, currentContext, file)
}

// iterate through method declaration from graph node
for _, node := range graph.Nodes {
if node.Type == "method_declaration" {
// iterate through method method_invocation from graph node
for _, invokedNode := range graph.Nodes {
if invokedNode.Type == "method_invocation" {
if invokedNode.Name == node.Name {
// check argument list count is same
if len(invokedNode.MethodArgumentsValue) == len(node.MethodArgumentsType) {
node.hasAccess = true
}
}
}
}
}
}
}

// write a function to generate unique method id from method name, class name, and package name, parameters, and return type.
Expand Down
Loading