Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
acbdb668
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,发现更多精彩内容 >>
未验证
提交
acbdb668
编写于
1月 16, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: [ts] add first version data struct
上级
3e730b97
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
93 addition
and
27 deletion
+93
-27
pkg/domain/jmethod.go
pkg/domain/jmethod.go
+1
-12
pkg/domain/trial/code_function.go
pkg/domain/trial/code_function.go
+1
-0
trial/cocago/testdata/node_infos/hello_world.json
trial/cocago/testdata/node_infos/hello_world.json
+6
-0
trial/cocago/testdata/node_infos/nested_method.json
trial/cocago/testdata/node_infos/nested_method.json
+6
-0
trial/cocago/testdata/node_infos/normal_method.json
trial/cocago/testdata/node_infos/normal_method.json
+24
-0
trial/cocago/testdata/node_infos/struct_type_zero.json
trial/cocago/testdata/node_infos/struct_type_zero.json
+6
-0
trial/cocago/testdata/node_infos/struct_with_func_decl.json
trial/cocago/testdata/node_infos/struct_with_func_decl.json
+6
-0
trial/pkg/application/ts/ts_ident_app_test.go
trial/pkg/application/ts/ts_ident_app_test.go
+5
-4
trial/pkg/ast/ts/typescript_ident_converter.go
trial/pkg/ast/ts/typescript_ident_converter.go
+23
-7
trial/pkg/ast/ts/typescript_ident_listener.go
trial/pkg/ast/ts/typescript_ident_listener.go
+15
-4
未找到文件。
pkg/domain/jmethod.go
浏览文件 @
acbdb668
...
...
@@ -24,18 +24,7 @@ type JMethod struct {
}
func
NewJMethod
()
JMethod
{
return
JMethod
{
Name
:
""
,
Type
:
""
,
Annotations
:
nil
,
StartLine
:
0
,
StartLinePosition
:
0
,
StopLine
:
0
,
StopLinePosition
:
0
,
Parameters
:
nil
,
MethodCalls
:
nil
,
IsConstructor
:
false
,
}
return
JMethod
{}
}
type
JMethodInfo
struct
{
...
...
pkg/domain/trial/code_function.go
浏览文件 @
acbdb668
...
...
@@ -10,4 +10,5 @@ type CodeFunction struct {
Modifiers
[]
string
Creators
[]
CodeDataStruct
InnerFunctions
[]
CodeFunction
CodePosition
CodePosition
}
trial/cocago/testdata/node_infos/hello_world.json
浏览文件 @
acbdb668
...
...
@@ -19,6 +19,12 @@
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
[
...
...
trial/cocago/testdata/node_infos/nested_method.json
浏览文件 @
acbdb668
...
...
@@ -19,6 +19,12 @@
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
[
...
...
trial/cocago/testdata/node_infos/normal_method.json
浏览文件 @
acbdb668
...
...
@@ -26,6 +26,12 @@
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
null
,
...
...
@@ -63,6 +69,12 @@
},
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
null
,
...
...
@@ -117,6 +129,12 @@
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
null
,
...
...
@@ -154,6 +172,12 @@
},
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
null
,
...
...
trial/cocago/testdata/node_infos/struct_type_zero.json
浏览文件 @
acbdb668
...
...
@@ -25,6 +25,12 @@
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
null
,
...
...
trial/cocago/testdata/node_infos/struct_with_func_decl.json
浏览文件 @
acbdb668
...
...
@@ -58,6 +58,12 @@
"FunctionNodes"
:
[
{
"Annotations"
:
null
,
"CodePosition"
:
{
"StartLine"
:
0
,
"StartLinePosition"
:
0
,
"StopLine"
:
0
,
"StopLinePosition"
:
0
},
"Creators"
:
null
,
"InnerFunctions"
:
null
,
"MethodCalls"
:
[
...
...
trial/pkg/application/ts/ts_ident_app_test.go
浏览文件 @
acbdb668
...
...
@@ -78,7 +78,7 @@ func Test_ShouldGetClassFromModule(t *testing.T) {
for
_
,
node
:=
range
results
.
ClassNodes
{
fmt
.
Println
(
node
)
}
g
.
Expect
(
len
(
results
.
ClassNodes
))
.
To
(
Equal
(
2
))
g
.
Expect
(
len
(
results
.
ClassNodes
))
.
To
(
Equal
(
1
))
g
.
Expect
(
results
.
ClassNodes
[
0
]
.
Class
)
.
To
(
Equal
(
"Employee"
))
}
...
...
@@ -88,15 +88,16 @@ func Test_ShouldEnableGetClassMethod(t *testing.T) {
app
:=
new
(
TypeScriptApiApp
)
results
:=
app
.
Analysis
(
`
codefile
:=
app
.
Analysis
(
`
class Employee {
displayName():void {
console.log("hello, world");
}
}
`
,
""
)
.
ClassNodes
`
,
""
)
g
.
Expect
(
len
(
results
[
0
]
.
Methods
))
.
To
(
Equal
(
1
))
g
.
Expect
(
len
(
codefile
.
DataStructures
[
0
]
.
Functions
))
.
To
(
Equal
(
1
))
g
.
Expect
(
len
(
codefile
.
ClassNodes
[
0
]
.
Methods
))
.
To
(
Equal
(
1
))
}
func
Test_ShouldGetInterfaceImplements
(
t
*
testing
.
T
)
{
...
...
trial/pkg/ast/ts/typescript_ident_converter.go
浏览文件 @
acbdb668
...
...
@@ -4,12 +4,13 @@ import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/languages/ts"
"github.com/phodal/coca/pkg/domain"
"github.com/phodal/coca/pkg/domain/trial"
)
func
BuildArgExpressCall
(
memberDotExprCtx
*
parser
.
MemberDotExpressionContext
)
domain
.
JMethodCall
{
call
:=
domain
.
NewJMethodCall
()
memberChild
:=
memberDotExprCtx
.
GetChild
(
0
)
switch
x
:=
memberChild
.
(
type
){
switch
x
:=
memberChild
.
(
type
)
{
case
*
parser
.
IdentifierExpressionContext
:
call
.
Class
=
x
.
GetText
()
call
.
MethodName
=
memberDotExprCtx
.
IdentifierName
()
.
GetText
()
...
...
@@ -18,20 +19,27 @@ func BuildArgExpressCall(memberDotExprCtx *parser.MemberDotExpressionContext) do
return
call
}
func
BuildConstructorMethod
(
ctx
*
parser
.
ConstructorDeclarationContext
)
domain
.
JMethod
{
func
BuildConstructorMethod
(
ctx
*
parser
.
ConstructorDeclarationContext
)
(
domain
.
JMethod
,
*
trial
.
CodeFunction
)
{
method
:=
domain
.
NewJMethod
()
method
.
Name
=
"constructor"
function
:=
&
trial
.
CodeFunction
{
Name
:
"constructor"
,
}
method
.
AddPosition
(
ctx
.
GetChild
(
0
)
.
GetParent
()
.
(
*
antlr
.
BaseParserRuleContext
))
if
ctx
.
AccessibilityModifier
()
!=
nil
{
method
.
Modifiers
=
append
(
method
.
Modifiers
,
ctx
.
AccessibilityModifier
()
.
GetText
())
modifier
:=
ctx
.
AccessibilityModifier
()
.
GetText
()
method
.
Modifiers
=
append
(
method
.
Modifiers
,
modifier
)
function
.
Modifiers
=
append
(
function
.
Modifiers
,
modifier
)
}
return
method
return
method
,
function
}
func
BuildMemberMethod
(
ctx
*
parser
.
PropertyMemberDeclarationContext
)
domain
.
JMethod
{
func
BuildMemberMethod
(
ctx
*
parser
.
PropertyMemberDeclarationContext
)
(
domain
.
JMethod
,
*
trial
.
CodeFunction
)
{
method
:=
domain
.
NewJMethod
()
method
.
Name
=
ctx
.
PropertyName
()
.
GetText
()
...
...
@@ -40,7 +48,15 @@ func BuildMemberMethod(ctx *parser.PropertyMemberDeclarationContext) domain.JMet
method
.
StopLine
=
ctx
.
GetStop
()
.
GetLine
()
method
.
StopLinePosition
=
ctx
.
GetStop
()
.
GetColumn
()
return
method
function
:=
&
trial
.
CodeFunction
{
Name
:
ctx
.
PropertyName
()
.
GetText
(),
}
function
.
CodePosition
.
StartLine
=
ctx
.
GetStart
()
.
GetLine
()
function
.
CodePosition
.
StartLinePosition
=
ctx
.
GetStart
()
.
GetColumn
()
function
.
CodePosition
.
StopLine
=
ctx
.
GetStop
()
.
GetLine
()
function
.
CodePosition
.
StopLinePosition
=
ctx
.
GetStop
()
.
GetColumn
()
return
method
,
function
}
func
BuildImplements
(
typeList
parser
.
IClassOrInterfaceTypeListContext
)
[]
string
{
...
...
@@ -64,7 +80,7 @@ func BuildMethodParameter(context *parser.ParameterListContext) []domain.JParame
parameters
=
append
(
parameters
,
buildRequireParameterList
(
listContext
)
...
)
if
context
.
RestParameter
()
!=
nil
{
if
context
.
RestParameter
()
!=
nil
{
restParamCtx
:=
context
.
RestParameter
()
.
(
*
parser
.
RestParameterContext
)
parameters
=
append
(
parameters
,
buildRestParameters
(
restParamCtx
))
}
...
...
trial/pkg/ast/ts/typescript_ident_listener.go
浏览文件 @
acbdb668
...
...
@@ -167,17 +167,23 @@ func (s *TypeScriptIdentListener) EnterClassDeclaration(ctx *parser.ClassDeclara
heritageContext
:=
ctx
.
ClassHeritage
()
.
(
*
parser
.
ClassHeritageContext
)
if
heritageContext
.
ImplementsClause
()
!=
nil
{
typeList
:=
heritageContext
.
ImplementsClause
()
.
(
*
parser
.
ImplementsClauseContext
)
.
ClassOrInterfaceTypeList
()
currentNode
.
Implements
=
append
(
currentNode
.
Implements
,
BuildImplements
(
typeList
)
...
)
currentDataStruct
.
Implements
=
append
(
currentNode
.
Implements
,
BuildImplements
(
typeList
)
...
)
}
if
heritageContext
.
ClassExtendsClause
()
!=
nil
{
referenceContext
:=
heritageContext
.
ClassExtendsClause
()
.
(
*
parser
.
ClassExtendsClauseContext
)
.
TypeReference
()
.
(
*
parser
.
TypeReferenceContext
)
currentNode
.
Extend
=
referenceContext
.
TypeName
()
.
GetText
()
currentDataStruct
.
Extend
=
referenceContext
.
TypeName
()
.
GetText
()
}
classTailContext
:=
ctx
.
ClassTail
()
.
(
*
parser
.
ClassTailContext
)
handleClassBodyElements
(
classTailContext
)
classNodeQueue
=
append
(
classNodeQueue
,
*
currentNode
)
dataStructQueue
=
append
(
dataStructQueue
,
*
currentDataStruct
)
}
func
handleClassBodyElements
(
classTailContext
*
parser
.
ClassTailContext
)
{
...
...
@@ -185,14 +191,17 @@ func handleClassBodyElements(classTailContext *parser.ClassTailContext) {
elementChild
:=
classElement
.
GetChild
(
0
)
switch
x
:=
elementChild
.
(
type
)
{
case
*
parser
.
ConstructorDeclarationContext
:
currentNode
.
Methods
=
append
(
currentNode
.
Methods
,
BuildConstructorMethod
(
x
))
constructorMethod
,
codeFunction
:=
BuildConstructorMethod
(
x
)
currentNode
.
Methods
=
append
(
currentNode
.
Methods
,
constructorMethod
)
currentDataStruct
.
Functions
=
append
(
currentDataStruct
.
Functions
,
*
codeFunction
)
case
*
parser
.
PropertyMemberDeclarationContext
:
HandlePropertyMember
(
x
,
currentNode
)
HandlePropertyMember
(
x
,
currentNode
,
currentDataStruct
)
}
}
}
func
HandlePropertyMember
(
propertyMemberCtx
*
parser
.
PropertyMemberDeclarationContext
,
node
*
domain
.
JClassNode
)
{
func
HandlePropertyMember
(
propertyMemberCtx
*
parser
.
PropertyMemberDeclarationContext
,
node
*
domain
.
JClassNode
,
dataStruct
*
trial
.
CodeDataStruct
)
{
callSignatureSizePos
:=
3
if
propertyMemberCtx
.
PropertyName
()
!=
nil
{
field
:=
domain
.
JField
{}
...
...
@@ -208,8 +217,10 @@ func HandlePropertyMember(propertyMemberCtx *parser.PropertyMemberDeclarationCon
callSignCtxPos
:=
2
switch
propertyMemberCtx
.
GetChild
(
callSignCtxPos
)
.
(
type
)
{
case
*
parser
.
CallSignatureContext
:
node
.
Methods
=
append
(
currentNode
.
Methods
,
BuildMemberMethod
(
propertyMemberCtx
))
memberMethod
,
memberFunction
:=
BuildMemberMethod
(
propertyMemberCtx
)
node
.
Methods
=
append
(
currentNode
.
Methods
,
memberMethod
)
dataStruct
.
Functions
=
append
(
dataStruct
.
Functions
,
*
memberFunction
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录