Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
2ed5dbf4
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
2ed5dbf4
编写于
11月 11, 2019
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add scan api api
上级
440cf2d6
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
48 addition
and
28 deletion
+48
-28
adapter/api/JavaApiApp.go
adapter/api/JavaApiApp.go
+14
-8
adapter/api/JavaApiListener.go
adapter/api/JavaApiListener.go
+1
-0
adapter/call/JavaCallListener.go
adapter/call/JavaCallListener.go
+0
-3
adapter/sql/SqlIdentifierApp.go
adapter/sql/SqlIdentifierApp.go
+0
-1
cmd/analysis.go
cmd/analysis.go
+4
-7
cmd/api.go
cmd/api.go
+28
-0
cmd/root.go
cmd/root.go
+1
-4
cmd/sql.go
cmd/sql.go
+0
-5
未找到文件。
adapter/api/JavaApiApp.go
浏览文件 @
2ed5dbf4
package
api
import
(
"encoding/json"
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"os"
...
...
@@ -9,16 +10,24 @@ import (
.
"github.com/phodal/coca/adapter/models"
.
"github.com/phodal/coca/language/java"
.
"github.com/phodal/coca/utils"
)
var
nodeInfo
s
[]
JClassNode
var
parsedDep
s
[]
JClassNode
type
JavaApiApp
struct
{
}
func
(
j
*
JavaApiApp
)
AnalysisPath
(
codeDir
string
,
classes
[]
JClassNode
)
[]
JClassNode
{
nodeInfos
=
nil
func
(
j
*
JavaApiApp
)
AnalysisPath
(
codeDir
string
,
depPath
string
)
[]
JClassNode
{
parsedDeps
=
nil
file
:=
ReadFile
(
depPath
)
if
file
==
nil
{
return
nil
}
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
files
:=
(
*
JavaApiApp
)(
nil
)
.
JavaFiles
(
codeDir
)
for
index
:=
range
files
{
file
:=
files
[
index
]
...
...
@@ -30,18 +39,15 @@ func (j *JavaApiApp) AnalysisPath(codeDir string, classes []JClassNode) []JClass
context
:=
parser
.
CompilationUnit
()
listener
:=
NewJavaApiListener
()
listener
.
appendClasses
(
classe
s
)
listener
.
appendClasses
(
parsedDep
s
)
antlr
.
NewParseTreeWalker
()
.
Walk
(
listener
,
context
)
apis
:=
listener
.
getApis
()
fmt
.
Println
(
apis
)
//nodeInfo = listener.getNodeInfo()
//nodeInfo.Path = file
//nodeInfos = append(nodeInfos, *nodeInfo)
}
return
nodeInfo
s
return
parsedDep
s
}
func
(
j
*
JavaApiApp
)
JavaFiles
(
codeDir
string
)
[]
string
{
...
...
adapter/api/JavaApiListener.go
浏览文件 @
2ed5dbf4
...
...
@@ -161,6 +161,7 @@ func buildRestApi(ctx *MethodDeclarationContext) {
func
(
s
*
JavaApiListener
)
appendClasses
(
classes
[]
models
.
JClassNode
)
{
clz
=
classes
//fmt.Println(clz)
}
func
(
s
*
JavaApiListener
)
getApis
()
[]
RestApi
{
...
...
adapter/call/JavaCallListener.go
浏览文件 @
2ed5dbf4
package
call
import
(
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
.
"github.com/phodal/coca/adapter/models"
.
"github.com/phodal/coca/language/java"
...
...
@@ -93,8 +92,6 @@ func (s *JavaCallListener) EnterLocalVariableDeclaration(ctx *LocalVariableDecla
typ
:=
ctx
.
GetChild
(
0
)
.
(
antlr
.
ParseTree
)
.
GetText
()
variableName
:=
ctx
.
GetChild
(
1
)
.
GetChild
(
0
)
.
GetChild
(
0
)
.
(
antlr
.
ParseTree
)
.
GetText
()
localVars
[
variableName
]
=
typ
fmt
.
Println
(
typ
,
variableName
)
}
func
(
s
*
JavaCallListener
)
EnterMethodDeclaration
(
ctx
*
MethodDeclarationContext
)
{
...
...
adapter/sql/SqlIdentifierApp.go
浏览文件 @
2ed5dbf4
...
...
@@ -24,7 +24,6 @@ func (j *SqlIdentifierApp) AnalysisPath(codeDir string) {
parsedXml
:=
ParseXml
(
xmlFile
)
for
_
,
attr
:=
range
parsedXml
.
Attrs
{
if
strings
.
Contains
(
attr
.
Name
.
Local
,
"namespace"
)
{
fmt
.
Println
(
attr
.
Value
)
}
...
...
cmd/analysis.go
浏览文件 @
2ed5dbf4
...
...
@@ -4,13 +4,12 @@ import (
"encoding/json"
"github.com/spf13/cobra"
.
"github.com/phodal/coca/adapter/api"
.
"github.com/phodal/coca/adapter/call"
.
"github.com/phodal/coca/adapter/identifier"
.
"github.com/phodal/coca/utils"
)
var
coll
Cmd
*
cobra
.
Command
=
&
cobra
.
Command
{
var
analysis
Cmd
*
cobra
.
Command
=
&
cobra
.
Command
{
Use
:
"analysis"
,
Short
:
"analysis package"
,
Long
:
``
,
...
...
@@ -31,15 +30,13 @@ var collCmd *cobra.Command = &cobra.Command{
callNodes
:=
callApp
.
AnalysisPath
(
importPath
,
classes
)
cModel
,
_
:=
json
.
MarshalIndent
(
callNodes
,
""
,
"
\t
"
)
apiApp
:=
new
(
JavaApiApp
)
apiApp
.
AnalysisPath
(
importPath
,
callNodes
)
WriteToFile
(
"deps.json"
,
string
(
cModel
))
}
},
}
func
init
()
{
rootCmd
.
PersistentFlags
()
.
StringP
(
"path"
,
"p"
,
"Code Path"
,
"example -p src/main"
)
rootCmd
.
AddCommand
(
analysisCmd
)
analysisCmd
.
PersistentFlags
()
.
StringP
(
"path"
,
"p"
,
"Code Path"
,
"example -p src/main"
)
}
cmd/api.go
0 → 100644
浏览文件 @
2ed5dbf4
package
cmd
import
(
.
"github.com/phodal/coca/adapter/api"
"github.com/spf13/cobra"
)
var
apiCmd
*
cobra
.
Command
=
&
cobra
.
Command
{
Use
:
"api"
,
Short
:
"scan api"
,
Long
:
``
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
path
:=
cmd
.
Flag
(
"path"
)
.
Value
.
String
()
dependence
:=
cmd
.
Flag
(
"dependence"
)
.
Value
.
String
()
if
path
!=
""
{
app
:=
new
(
JavaApiApp
)
app
.
AnalysisPath
(
path
,
dependence
)
}
},
}
func
init
()
{
rootCmd
.
AddCommand
(
apiCmd
)
rootCmd
.
PersistentFlags
()
.
StringP
(
"path"
,
"p"
,
""
,
"path"
)
rootCmd
.
PersistentFlags
()
.
StringP
(
"dependence"
,
"d"
,
""
,
"get dependence file"
)
}
cmd/root.go
浏览文件 @
2ed5dbf4
package
cmd
import
(
"fmt"
"github.com/spf13/cobra"
)
...
...
@@ -16,14 +15,12 @@ var (
}
)
// Execute executes the root command.
func
Execute
()
error
{
fmt
.
Println
(
rootCmd
.
Flag
(
"config"
)
.
Value
.
String
())
return
rootCmd
.
Execute
()
}
func
init
()
{
rootCmd
.
AddCommand
(
coll
Cmd
)
rootCmd
.
AddCommand
(
analysis
Cmd
)
rootCmd
.
PersistentFlags
()
.
StringVar
(
&
cfgFile
,
"config"
,
""
,
"config file (default is $HOME/.cobra.yaml)"
)
}
...
...
cmd/sql.go
浏览文件 @
2ed5dbf4
...
...
@@ -18,8 +18,3 @@ var sqlCmd *cobra.Command = &cobra.Command{
},
}
func
init
()
{
rootCmd
.
AddCommand
(
sqlCmd
)
sqlCmd
.
PersistentFlags
()
.
StringP
(
"path"
,
"p"
,
""
,
"path"
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录