未验证 提交 15622935 编写于 作者: P Phodal Huang

refactor: enable api output

上级 2ed5dbf4
......@@ -55,3 +55,4 @@ vendor/
web/
bs.json
nodeInfos.json
apis.json
......@@ -14,12 +14,13 @@ import (
)
var parsedDeps []JClassNode
var allApis []RestApi
type JavaApiApp struct {
}
func (j *JavaApiApp) AnalysisPath(codeDir string, depPath string) []JClassNode {
func (j *JavaApiApp) AnalysisPath(codeDir string, depPath string) []RestApi {
parsedDeps = nil
file := ReadFile(depPath)
if file == nil {
......@@ -43,11 +44,13 @@ func (j *JavaApiApp) AnalysisPath(codeDir string, depPath string) []JClassNode {
antlr.NewParseTreeWalker().Walk(listener, context)
apis := listener.getApis()
fmt.Println(apis)
apis := listener.getClassApis()
allApis = append(allApis, apis...)
}
return parsedDeps
fmt.Println(allApis)
return allApis
}
func (j *JavaApiApp) JavaFiles(codeDir string) []string {
......
package api
import (
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/adapter/models"
. "github.com/phodal/coca/language/java"
......@@ -119,7 +118,7 @@ func filterMethodCall(blockContext antlr.Tree) {
statement := rangeStatement.GetChild(0).(*StatementContext)
if reflect.TypeOf(statement.GetChild(0)).String() == "*parser.ExpressionContext" {
express := statement.GetChild(0).(*ExpressionContext)
fmt.Println(reflect.TypeOf(express.GetChild(0)).String())
reflect.TypeOf(express.GetChild(0))
}
}
}
......@@ -153,7 +152,7 @@ func buildRestApi(ctx *MethodDeclarationContext) {
localVars[paramValue] = paramType
}
currentRestApi.Body = requestBodyClass
//currentRestApi.Body
hasEnterRestController = false
requestBodyClass = ""
RestApis = append(RestApis, currentRestApi)
......@@ -161,9 +160,8 @@ func buildRestApi(ctx *MethodDeclarationContext) {
func (s *JavaApiListener) appendClasses(classes []models.JClassNode) {
clz = classes
//fmt.Println(clz)
}
func (s *JavaApiListener) getApis() []RestApi {
func (s *JavaApiListener) getClassApis() []RestApi {
return RestApis
}
package cmd
import (
"encoding/json"
. "github.com/phodal/coca/adapter/api"
. "github.com/phodal/coca/utils"
"github.com/spf13/cobra"
)
......@@ -15,7 +17,10 @@ var apiCmd *cobra.Command = &cobra.Command{
if path != "" {
app := new(JavaApiApp)
app.AnalysisPath(path, dependence)
restApis := app.AnalysisPath(path, dependence)
cModel, _ := json.MarshalIndent(restApis, "", "\t")
WriteToFile("apis.json", string(cModel))
}
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册