Skip to content

fixed unique id issue for generating unique id #146

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

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions sourcecode-parser/graph/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,14 @@ func extractMethodName(node *sitter.Node, sourceCode []byte, filepath string) (s

}
}
methodID = GenerateMethodID(methodName, parameters, filepath)
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
8 changes: 4 additions & 4 deletions sourcecode-parser/graph/construct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func TestBuildGraphFromAST(t *testing.T) {
}
}
`,
expectedNodes: 4,
expectedNodes: 5,
expectedEdges: 2,
expectedTypes: []string{"class_declaration", "method_declaration", "method_invocation"},
unexpectedTypes: []string{"variable_declaration"},
Expand Down Expand Up @@ -852,19 +852,19 @@ func TestExtractMethodName(t *testing.T) {
name: "Simple method",
sourceCode: "public void simpleMethod() {}",
expectedName: "simpleMethod",
expectedIDPart: "f5bef43ffe2408f266cdb6a6649ec63ae0e3e00d0f8b9269c057626c2ed750e7",
expectedIDPart: "e4bf121a07daa7b5fc0821f04fe31f22689361aaa7604264034bf231640c0b94",
},
{
name: "Method with parameters",
sourceCode: "private int complexMethod(String a, int b) {}",
expectedName: "complexMethod",
expectedIDPart: "7aafd0e3d06b68d9795e019ed7131eeda9f3ae692125b537a4e69486205ef6a0",
expectedIDPart: "8fa7666614f2db09a92d83f0ec126328a0c0fc93ac0919ffce2be2ce65e5fed5",
},
{
name: "Generic method",
sourceCode: "public <T> List<T> genericMethod(T item) {}",
expectedName: "genericMethod",
expectedIDPart: "5bcc19f46ab5547ade3962fc401d19b71d17c2c16ee9ff1a0bdfa7fd9b788131",
expectedIDPart: "4072dc9bf8d115f9c73a0ff3ff2205ef2866845921ac3dd218530ffe85966d96",
},
}

Expand Down
Loading