Skip to content

Commit

Permalink
remove method name extraction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shivasurya committed Feb 3, 2025
1 parent c3c47dc commit 4e43a59
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions sourcecode-parser/graph/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,68 +874,6 @@ func buildGraphFromAST(node *sitter.Node, sourceCode []byte, currentContext *Nod
buildGraphFromAST(child, sourceCode, currentContext, file, parentNode)
}
}

//nolint:all
func extractMethodName(node *sitter.Node, sourceCode []byte, filepath string) (string, string) {
var methodID string

// if the child node is method_declaration, extract method name, modifiers, parameters, and return type
var methodName string
var modifiers, parameters []string

if node.Type() == "method_declaration" {
// Iterate over all children of the method_declaration node
for i := 0; i < int(node.ChildCount()); i++ {
child := node.Child(i)
switch child.Type() {
case "modifiers", "marker_annotation", "annotation":
// This child is a modifier or annotation, add its content to modifiers
modifiers = append(modifiers, child.Content(sourceCode)) //nolint:all
case "identifier":
// This child is the method name
methodName = child.Content(sourceCode)
case "formal_parameters":
// This child represents formal parameters; iterate through its children
for j := 0; j < int(child.NamedChildCount()); j++ {
param := child.NamedChild(j)
parameters = append(parameters, param.Content(sourceCode))
}
}
}
}

// check if type is method_invocation
// if the child node is method_invocation, extract method name
if node.Type() == "method_invocation" {
for j := 0; j < int(node.ChildCount()); j++ {
child := node.Child(j)
if child.Type() == "identifier" {
if methodName == "" {
methodName = child.Content(sourceCode)
} else {
methodName = methodName + "." + child.Content(sourceCode)
}
}

argumentsNode := node.ChildByFieldName("argument_list")
// add data type of arguments list
if argumentsNode != nil {
for k := 0; k < int(argumentsNode.ChildCount()); k++ {
argument := argumentsNode.Child(k)
parameters = append(parameters, argument.Child(0).Content(sourceCode))
}
}

}
}
content := node.Content(sourceCode)
lineNumber := int(node.StartPoint().Row) + 1
columnNumber := int(node.StartPoint().Column) + 1
// convert to string and merge
content += " " + strconv.Itoa(lineNumber) + ":" + strconv.Itoa(columnNumber)
methodID = GenerateMethodID(methodName, parameters, filepath+"/"+content)
return methodName, methodID
}
func getFiles(directory string) ([]string, error) {
var files []string
err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
Expand Down

0 comments on commit 4e43a59

Please sign in to comment.