Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
d92ea4bc
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 搜索 >>
未验证
提交
d92ea4bc
编写于
10月 29, 2019
作者:
P
Phodal HUANG
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: exploe apis
上级
c60fcd39
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
6 deletion
+69
-6
refactor/base/JavaRefactorApp.go
refactor/base/JavaRefactorApp.go
+9
-5
refactor/base/JavaRefactorListener.go
refactor/base/JavaRefactorListener.go
+25
-1
refactor/base/models/JFullIdentifier.go
refactor/base/models/JFullIdentifier.go
+35
-0
未找到文件。
refactor/base/JavaRefactorApp.go
浏览文件 @
d92ea4bc
...
...
@@ -12,7 +12,6 @@ import (
)
type
JavaRefactorApp
struct
{
}
func
(
j
*
JavaRefactorApp
)
AnalysisPath
(
codeDir
string
)
{
...
...
@@ -26,18 +25,23 @@ func (j *JavaRefactorApp) AnalysisPath(codeDir string) {
parser
:=
(
*
JavaRefactorApp
)(
nil
)
.
processFile
(
file
)
context
:=
parser
.
CompilationUnit
()
interfaceIdent
:=
NewJFullIdentifier
()
node
:=
NewJFullIdentifier
()
listener
:=
new
(
JavaRefactorListener
)
listener
.
InitNode
(
interfaceIdent
)
listener
.
InitNode
(
node
)
antlr
.
NewParseTreeWalker
()
.
Walk
(
listener
,
context
)
if
interfaceIdent
.
Name
!=
""
{
fmt
.
Println
(
interfaceIdent
.
Type
,
interfaceIdent
.
Pkg
,
interfaceIdent
.
Name
,
interfaceIdent
.
GetMethods
())
if
node
.
Name
!=
""
{
handleNode
(
node
)
}
}
}
func
handleNode
(
identifier
*
JFullIdentifier
)
{
fmt
.
Println
(
node
.
Pkg
+
"."
+
node
.
Name
,
node
.
GetImports
(),
node
.
GetMethods
(),
node
.
GetFields
())
}
func
(
j
*
JavaRefactorApp
)
javaFiles
(
codeDir
string
)
[]
string
{
files
:=
make
([]
string
,
0
)
_
=
filepath
.
Walk
(
codeDir
,
func
(
path
string
,
fi
os
.
FileInfo
,
err
error
)
error
{
...
...
refactor/base/JavaRefactorListener.go
浏览文件 @
d92ea4bc
...
...
@@ -3,6 +3,7 @@ package base
import
(
.
"../../language/java"
.
"./models"
"github.com/antlr/antlr4/runtime/Go/antlr"
)
var
node
*
JFullIdentifier
;
...
...
@@ -15,6 +16,16 @@ func (s *JavaRefactorListener) EnterPackageDeclaration(ctx *PackageDeclarationCo
node
.
Pkg
=
ctx
.
QualifiedName
()
.
GetText
()
}
func
(
s
*
JavaRefactorListener
)
EnterImportDeclaration
(
ctx
*
ImportDeclarationContext
)
{
importText
:=
ctx
.
QualifiedName
()
.
GetText
()
startLine
:=
ctx
.
GetStart
()
.
GetLine
()
stopLine
:=
ctx
.
GetStop
()
.
GetLine
()
jImport
:=
&
JImport
{
importText
,
startLine
,
stopLine
}
node
.
AddImport
(
*
jImport
)
}
func
(
s
*
JavaRefactorListener
)
EnterClassDeclaration
(
ctx
*
ClassDeclarationContext
)
{
node
.
Type
=
"Class"
node
.
Name
=
ctx
.
IDENTIFIER
()
.
GetText
()
...
...
@@ -42,6 +53,20 @@ func (s *JavaRefactorListener) EnterMethodDeclaration(ctx *MethodDeclarationCont
node
.
AddMethod
(
*
method
)
}
func
(
s
*
JavaRefactorListener
)
EnterFieldDeclaration
(
ctx
*
FieldDeclarationContext
)
{
declarators
:=
ctx
.
VariableDeclarators
()
variableName
:=
declarators
.
GetParent
()
.
GetChild
(
0
)
.
(
antlr
.
ParseTree
)
.
GetText
()
startLine
:=
ctx
.
GetStart
()
.
GetLine
()
stopLine
:=
ctx
.
GetStop
()
.
GetLine
()
text
:=
ctx
.
TypeType
()
.
GetText
()
if
variableName
!=
""
&&
text
!=
""
{
field
:=
&
JField
{
variableName
,
node
.
Pkg
,
startLine
,
stopLine
}
node
.
AddField
(
*
field
)
}
}
func
(
s
*
JavaRefactorListener
)
EnterInterfaceDeclaration
(
ctx
*
InterfaceDeclarationContext
)
{
node
.
Type
=
"Interface"
node
.
Name
=
ctx
.
IDENTIFIER
()
.
GetText
()
...
...
@@ -50,4 +75,3 @@ func (s *JavaRefactorListener) EnterInterfaceDeclaration(ctx *InterfaceDeclarati
func
(
s
*
JavaRefactorListener
)
InitNode
(
identifier
*
JFullIdentifier
)
{
node
=
identifier
}
refactor/base/models/JFullIdentifier.go
浏览文件 @
d92ea4bc
...
...
@@ -8,7 +8,24 @@ type JFullMethod struct {
StopLinePosition
int
}
type
JField
struct
{
Name
string
Source
string
StartLine
int
StopLine
int
//StartLinePosition int
//StopLinePosition int
}
type
JImport
struct
{
Name
string
StartLine
int
StopLine
int
}
var
methods
[]
JFullMethod
var
fields
=
make
(
map
[
string
]
JField
)
var
imports
=
make
(
map
[
string
]
JImport
)
type
JFullIdentifier
struct
{
Pkg
string
...
...
@@ -19,6 +36,8 @@ type JFullIdentifier struct {
func
NewJFullIdentifier
()
*
JFullIdentifier
{
identifier
:=
&
JFullIdentifier
{
""
,
""
,
""
}
methods
=
nil
fields
=
make
(
map
[
string
]
JField
)
imports
=
make
(
map
[
string
]
JImport
)
return
identifier
}
...
...
@@ -29,3 +48,19 @@ func (identifier *JFullIdentifier) AddMethod(method JFullMethod) {
func
(
identifier
*
JFullIdentifier
)
GetMethods
()
[]
JFullMethod
{
return
methods
}
func
(
identifier
*
JFullIdentifier
)
AddField
(
field
JField
)
{
fields
[
field
.
Name
]
=
field
}
func
(
identifier
*
JFullIdentifier
)
GetFields
()
map
[
string
]
JField
{
return
fields
}
func
(
identifier
*
JFullIdentifier
)
AddImport
(
jImport
JImport
)
{
imports
[
jImport
.
Name
]
=
jImport
}
func
(
identifier
*
JFullIdentifier
)
GetImports
()
map
[
string
]
JImport
{
return
imports
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录