Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
7185b9c6
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 搜索 >>
未验证
提交
7185b9c6
编写于
1月 02, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: make inner class to inner class node
上级
e3594aeb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
8 deletion
+42
-8
_fixtures/abug/InnerClass.java
_fixtures/abug/InnerClass.java
+5
-0
core/context/analysis/java_full_app_test.go
core/context/analysis/java_full_app_test.go
+3
-0
core/domain/jclass_node.go
core/domain/jclass_node.go
+2
-1
core/infrastructure/ast/full/java_full_listener.go
core/infrastructure/ast/full/java_full_listener.go
+32
-7
未找到文件。
_fixtures/abug/InnerClass.java
浏览文件 @
7185b9c6
package
com.phodal.coca.abug
;
public
class
Outer
{
public
class
Outer
{
final
int
z
=
10
;
final
int
z
=
10
;
class
Inner
extends
HasStatic
{
class
Inner
extends
HasStatic
{
static
final
int
x
=
3
;
static
final
int
x
=
3
;
static
int
y
=
4
;
static
int
y
=
4
;
public
static
void
pr
()
{
}
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
core/context/analysis/java_full_app_test.go
浏览文件 @
7185b9c6
...
@@ -77,6 +77,7 @@ func TestInterface(t *testing.T) {
...
@@ -77,6 +77,7 @@ func TestInterface(t *testing.T) {
callNodes
:=
getCallNodes
(
codePath
)
callNodes
:=
getCallNodes
(
codePath
)
methodMap
:=
make
(
map
[
string
]
domain
.
JMethod
)
methodMap
:=
make
(
map
[
string
]
domain
.
JMethod
)
for
_
,
c
:=
range
callNodes
[
0
]
.
Methods
{
for
_
,
c
:=
range
callNodes
[
0
]
.
Methods
{
methodMap
[
c
.
Name
]
=
c
methodMap
[
c
.
Name
]
=
c
}
}
...
@@ -238,5 +239,7 @@ func Test_InnerClass(t *testing.T) {
...
@@ -238,5 +239,7 @@ func Test_InnerClass(t *testing.T) {
callNodes
:=
getCallNodes
(
codePath
)
callNodes
:=
getCallNodes
(
codePath
)
g
.
Expect
(
len
(
callNodes
))
.
To
(
Equal
(
1
))
g
.
Expect
(
callNodes
[
0
]
.
Class
)
.
To
(
Equal
(
"Outer"
))
g
.
Expect
(
callNodes
[
0
]
.
Class
)
.
To
(
Equal
(
"Outer"
))
g
.
Expect
(
callNodes
[
0
]
.
InnerClass
[
0
]
.
Class
)
.
To
(
Equal
(
"Inner"
))
}
}
core/domain/jclass_node.go
浏览文件 @
7185b9c6
...
@@ -13,6 +13,7 @@ type JClassNode struct {
...
@@ -13,6 +13,7 @@ type JClassNode struct {
Extend
string
Extend
string
Implements
[]
string
Implements
[]
string
Annotations
[]
Annotation
Annotations
[]
Annotation
InnerClass
[]
JClassNode
}
}
type
JAppField
struct
{
type
JAppField
struct
{
...
@@ -21,7 +22,7 @@ type JAppField struct {
...
@@ -21,7 +22,7 @@ type JAppField struct {
}
}
func
NewClassNode
()
*
JClassNode
{
func
NewClassNode
()
*
JClassNode
{
return
&
JClassNode
{
""
,
""
,
""
,
""
,
nil
,
nil
,
nil
,
""
,
nil
,
nil
}
return
&
JClassNode
{
""
,
""
,
""
,
""
,
nil
,
nil
,
nil
,
""
,
nil
,
nil
,
nil
}
}
}
func
(
j
*
JClassNode
)
IsUtilClass
()
bool
{
func
(
j
*
JClassNode
)
IsUtilClass
()
bool
{
...
...
core/infrastructure/ast/full/java_full_listener.go
浏览文件 @
7185b9c6
...
@@ -88,7 +88,6 @@ func (s *JavaFullListener) ExitInterfaceBody(ctx *parser.InterfaceBodyContext) {
...
@@ -88,7 +88,6 @@ func (s *JavaFullListener) ExitInterfaceBody(ctx *parser.InterfaceBodyContext) {
func
(
s
*
JavaFullListener
)
exitBody
()
{
func
(
s
*
JavaFullListener
)
exitBody
()
{
if
currentNode
.
Class
!=
""
{
if
currentNode
.
Class
!=
""
{
currentNode
.
Fields
=
fields
currentNode
.
Fields
=
fields
currentNode
.
Type
=
currentType
currentNode
.
Path
=
fileName
currentNode
.
Path
=
fileName
currentNode
.
SetMethodFromMap
(
methodMap
)
currentNode
.
SetMethodFromMap
(
methodMap
)
}
}
...
@@ -98,11 +97,29 @@ func (s *JavaFullListener) exitBody() {
...
@@ -98,11 +97,29 @@ func (s *JavaFullListener) exitBody() {
return
return
}
}
if
currentNode
.
Class
!=
""
{
if
currentNode
.
Class
==
""
{
currentNode
=
domain
.
NewClassNode
()
initClass
()
return
}
if
currentNode
.
Type
==
"InnerClass"
&&
len
(
classNodeQueue
)
>=
1
{
classNodeQueue
[
0
]
.
InnerClass
=
append
(
currentNode
.
InnerClass
,
*
currentNode
)
}
else
{
classNodes
=
append
(
classNodes
,
*
currentNode
)
classNodes
=
append
(
classNodes
,
*
currentNode
)
}
}
currentNode
=
domain
.
NewClassNode
()
if
len
(
classNodeQueue
)
>=
1
{
if
len
(
classNodeQueue
)
==
1
{
currentNode
=
&
classNodeQueue
[
0
]
}
else
{
classNodeQueue
=
classNodeQueue
[
0
:
len
(
classNodeQueue
)
-
1
]
currentNode
=
&
classNodeQueue
[
len
(
classNodeQueue
)
-
1
]
}
}
else
{
currentNode
=
domain
.
NewClassNode
()
}
initClass
()
initClass
()
}
}
...
@@ -119,12 +136,14 @@ func (s *JavaFullListener) EnterImportDeclaration(ctx *parser.ImportDeclarationC
...
@@ -119,12 +136,14 @@ func (s *JavaFullListener) EnterImportDeclaration(ctx *parser.ImportDeclarationC
func
(
s
*
JavaFullListener
)
EnterClassDeclaration
(
ctx
*
parser
.
ClassDeclarationContext
)
{
func
(
s
*
JavaFullListener
)
EnterClassDeclaration
(
ctx
*
parser
.
ClassDeclarationContext
)
{
// TODO: support inner class
// TODO: support inner class
if
currentNode
.
Class
!=
""
{
if
currentNode
.
Class
!=
""
{
return
classNodeQueue
=
append
(
classNodeQueue
,
*
currentNode
)
currentType
=
"InnerClass"
}
else
{
currentType
=
"Class"
}
}
hasEnterClass
=
true
hasEnterClass
=
true
currentClzExtend
=
""
currentClzExtend
=
""
currentType
=
"Class"
if
ctx
.
IDENTIFIER
()
!=
nil
{
if
ctx
.
IDENTIFIER
()
!=
nil
{
currentClz
=
ctx
.
IDENTIFIER
()
.
GetText
()
currentClz
=
ctx
.
IDENTIFIER
()
.
GetText
()
currentNode
.
Class
=
currentClz
currentNode
.
Class
=
currentClz
...
@@ -143,6 +162,7 @@ func (s *JavaFullListener) EnterClassDeclaration(ctx *parser.ClassDeclarationCon
...
@@ -143,6 +162,7 @@ func (s *JavaFullListener) EnterClassDeclaration(ctx *parser.ClassDeclarationCon
}
}
}
}
currentNode
.
Type
=
currentType
// TODO: 支持依赖注入
// TODO: 支持依赖注入
}
}
...
@@ -157,6 +177,8 @@ func (s *JavaFullListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclar
...
@@ -157,6 +177,8 @@ func (s *JavaFullListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclar
buildExtend
(
typ
.
GetText
())
buildExtend
(
typ
.
GetText
())
}
}
}
}
currentNode
.
Type
=
currentType
}
}
func
(
s
*
JavaFullListener
)
EnterInterfaceBodyDeclaration
(
ctx
*
parser
.
InterfaceBodyDeclarationContext
)
{
func
(
s
*
JavaFullListener
)
EnterInterfaceBodyDeclaration
(
ctx
*
parser
.
InterfaceBodyDeclarationContext
)
{
...
@@ -399,7 +421,6 @@ func (s *JavaFullListener) EnterCreator(ctx *parser.CreatorContext) {
...
@@ -399,7 +421,6 @@ func (s *JavaFullListener) EnterCreator(ctx *parser.CreatorContext) {
createdName
:=
identifier
.
GetText
()
createdName
:=
identifier
.
GetText
()
localVars
[
variableName
]
=
createdName
localVars
[
variableName
]
=
createdName
classNodeQueue
=
append
(
classNodeQueue
,
*
currentNode
)
buildCreatedCall
(
createdName
,
ctx
)
buildCreatedCall
(
createdName
,
ctx
)
if
currentMethod
.
Name
==
""
{
if
currentMethod
.
Name
==
""
{
...
@@ -414,6 +435,8 @@ func (s *JavaFullListener) EnterCreator(ctx *parser.CreatorContext) {
...
@@ -414,6 +435,8 @@ func (s *JavaFullListener) EnterCreator(ctx *parser.CreatorContext) {
return
return
}
}
//classNodeQueue = append(classNodeQueue, *currentNode)
currentType
=
"CreatorClass"
currentType
=
"CreatorClass"
text
:=
ctx
.
CreatedName
()
.
GetText
()
text
:=
ctx
.
CreatedName
()
.
GetText
()
creatorNode
:=
&
domain
.
JClassNode
{
creatorNode
:=
&
domain
.
JClassNode
{
...
@@ -441,7 +464,9 @@ func (s *JavaFullListener) ExitCreator(ctx *parser.CreatorContext) {
...
@@ -441,7 +464,9 @@ func (s *JavaFullListener) ExitCreator(ctx *parser.CreatorContext) {
methodMap
[
getMethodMapName
(
currentMethod
)]
=
method
methodMap
[
getMethodMapName
(
currentMethod
)]
=
method
}
}
currentType
=
""
if
currentType
==
"CreatorClass"
{
currentType
=
""
}
currentCreatorNode
=
*
domain
.
NewClassNode
()
currentCreatorNode
=
*
domain
.
NewClassNode
()
if
classNodeQueue
==
nil
||
len
(
classNodeQueue
)
<
1
{
if
classNodeQueue
==
nil
||
len
(
classNodeQueue
)
<
1
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录