未验证 提交 26b83b3b 编写于 作者: P Phodal HUANG

refactor: refactor json for export

上级 e09f9d93
package call
import (
"encoding/json"
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"os"
......@@ -9,15 +8,20 @@ import (
"strings"
. "../../language/java"
. "../models"
)
var nodeInfos []JClassNode
type JavaCallApp struct {
}
func (j *JavaCallApp) AnalysisPath(codeDir string) {
func (j *JavaCallApp) AnalysisPath(codeDir string) []JClassNode {
nodeInfos = nil
files := (*JavaCallApp)(nil).javaFiles(codeDir)
for index := range files {
nodeInfo := NewClassNode()
file := files[index]
displayName := filepath.Base(file)
......@@ -30,10 +34,11 @@ func (j *JavaCallApp) AnalysisPath(codeDir string) {
antlr.NewParseTreeWalker().Walk(listener, context)
nodeInfo := listener.getNodeInfo()
bytes, _ := json.Marshal(nodeInfo)
fmt.Println(string(bytes))
nodeInfo = listener.getNodeInfo()
nodeInfos = append(nodeInfos, *nodeInfo)
}
return nodeInfos
}
func (j *JavaCallApp) javaFiles(codeDir string) []string {
......
......@@ -2,7 +2,7 @@ package call
import (
. "../../language/java"
. "./models"
. "../models"
"github.com/antlr/antlr4/runtime/Go/antlr"
"reflect"
"strings"
......
package identifier
import (
"encoding/json"
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"os"
......@@ -9,23 +8,20 @@ import (
"strings"
. "../../language/java"
. "./models"
. "../models"
)
type JsonIdentifier struct {
Package string
Name string
Type string
Methods []JMethod
}
var nodeInfos []JsonIdentifier = nil
type JavaIdentifierApp struct {
}
func (j *JavaIdentifierApp) AnalysisPath(codeDir string) {
func (j *JavaIdentifierApp) AnalysisPath(codeDir string) []JsonIdentifier {
nodeInfos = nil
files := (*JavaIdentifierApp)(nil).javaFiles(codeDir)
for index := range files {
file := files[index]
node := NewJsonIdentifier()
displayName := filepath.Base(file)
fmt.Println("Start parse java call: " + displayName)
......@@ -40,11 +36,13 @@ func (j *JavaIdentifierApp) AnalysisPath(codeDir string) {
antlr.NewParseTreeWalker().Walk(listener, context)
if clzInfo.Name != "" {
identifier := &JsonIdentifier{clzInfo.Pkg, clzInfo.Name, clzInfo.Type, clzInfo.GetMethods()}
bytes, _ := json.Marshal(identifier)
fmt.Println(string(bytes))
node = &JsonIdentifier{clzInfo.Pkg, clzInfo.Name, clzInfo.Type, clzInfo.GetMethods()}
nodeInfos = append(nodeInfos, *node)
}
}
return nodeInfos
}
func (j *JavaIdentifierApp) javaFiles(codeDir string) []string {
......
......@@ -2,7 +2,7 @@ package identifier
import (
. "../../language/java"
. "./models"
. "../models"
)
var node *JIdentifier;
......
......@@ -6,3 +6,18 @@ type JClassNode struct {
Type string
MethodCalls []JMethodCall
}
type JsonIdentifier struct {
Package string
Name string
Type string
Methods []JMethod
}
func NewClassNode() *JClassNode {
return &JClassNode{"", "", "", nil}
}
func NewJsonIdentifier() *JsonIdentifier {
return &JsonIdentifier{"", "", "", nil}
}
\ No newline at end of file
package cmd
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
......@@ -17,10 +19,16 @@ var collCmd *cobra.Command = &cobra.Command{
if importPath != "" {
callApp := new(JavaCallApp)
callApp.AnalysisPath(importPath)
callNodes := callApp.AnalysisPath(importPath)
cModel, _ := json.Marshal(callNodes)
identifierApp := new(JavaIdentifierApp)
identifierApp.AnalysisPath(importPath)
identNodes := identifierApp.AnalysisPath(importPath)
iNodes, _ := json.Marshal(identNodes)
fmt.Println(string(cModel))
fmt.Println(string(iNodes))
}
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册