未验证 提交 36e4b483 编写于 作者: P Phodal HUANG

refactor: refactor output

上级 5abd3e72
......@@ -11,6 +11,7 @@ import (
var imports []string
var currentPkg string
var currentClz string
var methods []JMethod
var methodCalls []JMethodCall
var currentMethodCall *JMethodCall
var currentType string
......@@ -25,7 +26,7 @@ func NewJavaCallListener() *JavaCallListener {
currentClz = ""
currentPkg = ""
currentMethodCall = nil
methodCalls = nil
methods = nil
return &JavaCallListener{}
}
......@@ -34,7 +35,7 @@ type JavaCallListener struct {
}
func (s *JavaCallListener) getNodeInfo() *JClassNode {
return &JClassNode{currentPkg, currentClz, currentType, methodCalls}
return &JClassNode{currentPkg, currentClz, currentType, methods, methodCalls}
}
func (s *JavaCallListener) EnterPackageDeclaration(ctx *PackageDeclarationContext) {
......@@ -57,9 +58,15 @@ func (s *JavaCallListener) EnterInterfaceDeclaration(ctx *InterfaceDeclarationCo
}
func (s *JavaCallListener) EnterInterfaceMethodDeclaration(ctx *InterfaceMethodDeclarationContext) {
methodName := ctx.IDENTIFIER().GetText()
currentMethodCall = &JMethodCall{currentPkg, currentClz, methodName}
methodCalls = append(methodCalls, *currentMethodCall)
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetTokenSource().GetCharPositionInLine()
stopLine := ctx.GetStop().GetLine()
stopLinePosition := ctx.GetStop().GetTokenSource().GetCharPositionInLine()
name := ctx.IDENTIFIER().GetText()
//XXX: find the start position of {, not public
method := &JMethod{name, startLine, startLinePosition, stopLine, stopLinePosition}
methods = append(methods, *method)
}
func (s *JavaCallListener) EnterFormalParameter(ctx *FormalParameterContext) {
......@@ -79,23 +86,30 @@ func (s *JavaCallListener) EnterLocalVariableDeclaration(ctx *LocalVariableDecla
}
func (s *JavaCallListener) EnterMethodDeclaration(ctx *MethodDeclarationContext) {
methodName := ctx.IDENTIFIER().GetText()
currentMethodCall = &JMethodCall{currentPkg, currentClz, methodName}
methodCalls = append(methodCalls, *currentMethodCall)
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetTokenSource().GetCharPositionInLine()
stopLine := ctx.GetStop().GetLine()
stopLinePosition := ctx.GetStop().GetTokenSource().GetCharPositionInLine()
name := ctx.IDENTIFIER().GetText()
//XXX: find the start position of {, not public
method := &JMethod{name, startLine, startLinePosition, stopLine, stopLinePosition}
methods = append(methods, *method)
}
func (s *JavaCallListener) EnterMethodCall(ctx *MethodCallContext) {
if currentMethodCall != nil {
var targetType = parseTargetType(ctx);
callee := ctx.GetChild(0).(antlr.ParseTree).GetText()
fullType := warpTargetFullType(targetType);
if fullType != "" {
currentMethodCall.AddMethodCall(fullType, callee);
} else {
}
var targetType = parseTargetType(ctx);
callee := ctx.GetChild(0).(antlr.ParseTree).GetText()
startLine := ctx.GetStart().GetLine()
startLinePosition := ctx.GetStart().GetTokenSource().GetCharPositionInLine()
stopLine := ctx.GetStop().GetLine()
stopLinePosition := ctx.GetStop().GetTokenSource().GetCharPositionInLine()
fullType := warpTargetFullType(targetType);
if fullType != "" {
jMethodCall := &JMethodCall{targetType, "", callee, startLine, startLinePosition, stopLine, stopLinePosition}
methodCalls = append(methodCalls, *jMethodCall)
} else {
}
}
......
......@@ -4,6 +4,7 @@ type JClassNode struct {
Package string
Class string
Type string
Methods []JMethod
MethodCalls []JMethodCall
}
......@@ -15,9 +16,9 @@ type JsonIdentifier struct {
}
func NewClassNode() *JClassNode {
return &JClassNode{"", "", "", nil}
return &JClassNode{"", "", "", nil, nil}
}
func NewJsonIdentifier() *JsonIdentifier {
return &JsonIdentifier{"", "", "", nil}
}
\ No newline at end of file
}
package models
type JMethodCall struct {
Pkg string
Dlz string
MethodName string
//tableOps map[string]string
}
func (call *JMethodCall) AddMethodCall (targetType string, method string) {
//fmt.Println(targetType, "->", method)
Pkg string
Dlz string
MethodName string
StartLine int
StartLinePosition int
StopLine int
StopLinePosition int
}
......@@ -3,9 +3,19 @@ package utils
import (
"fmt"
"io"
"io/ioutil"
"os"
)
func WriteFile(fileName string, payload string) {
_ = ioutil.WriteFile(fileName, []byte(payload), 0644)
}
func ReadFile(fileName string, payload string) []byte {
contents, _ := ioutil.ReadFile(fileName)
return contents
}
func CopyFile(src, dst string) (int64, error) {
sourceFileStat, err := os.Stat(src)
if err != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册