Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
example-java-project/
main
sourcecode-parser/sourcecode-parser
.idea/
3 changes: 2 additions & 1 deletion sourcecode-parser/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func readFile(path string) ([]byte, error) {
return content, nil
}

func Initialize(directory string) {
func Initialize(directory string) *CodeGraph {
// Initialize the parser
parser := sitter.NewParser()
defer parser.Close()
Expand Down Expand Up @@ -271,4 +271,5 @@ func Initialize(directory string) {
// go StartServer(codeGraph)

// select {}
return codeGraph
}
10 changes: 8 additions & 2 deletions sourcecode-parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
func main() {
// accept command line param optional path to source code
sourceDirectory := "."
graph := NewCodeGraph()
if len(os.Args) > 1 {
sourceDirectory = os.Args[1]
Initialize(sourceDirectory)
graph = Initialize(sourceDirectory)
}
var input string
fmt.Print("Path-Finder Query Console: \n>")
Expand All @@ -34,6 +35,11 @@ func main() {
fmt.Println(err)
}
} else {
fmt.Println(query)
entities := QueryEntities(graph, query)
fmt.Println("------Query Results------")
for _, entity := range entities {
fmt.Println(entity.CodeSnippet)
}
fmt.Println("-------------------")
}
}
20 changes: 0 additions & 20 deletions sourcecode-parser/query_test.go

This file was deleted.

14 changes: 14 additions & 0 deletions sourcecode-parser/source_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"fmt"
"queryparser"
)

type SourceSinkPath struct {
Expand Down Expand Up @@ -68,3 +69,16 @@ func AnalyzeSourceSinkPatterns(graph *CodeGraph, sourceMethodName, sinkMethodNam
// Return true if sourceNode is connected to sinkNode as a result of the DFS
return Result{IsConnected: isConnected, SourceMethod: sourceNode.CodeSnippet, SinkMethod: sinkNode.CodeSnippet, SourceLine: sourceNode.LineNumber, SinkLine: sinkNode.LineNumber}
}

func QueryEntities(graph *CodeGraph, query *queryparser.Query) []*GraphNode {
result := make([]*GraphNode, 0)
if query.Entity == "method" {
for _, node := range graph.Nodes {
// create array of nodes that match the query
if node.Type == "method_declaration" && node.Name == query.Conditions[0].Value {
result = append(result, node)
}
}
}
return result
}