Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
ecb51d2d
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,发现更多精彩内容 >>
未验证
提交
ecb51d2d
编写于
1月 16, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: [ts] make method num correct for interfacE
上级
5c7bb90b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
85 addition
and
32 deletion
+85
-32
pkg/domain/trial/code_data_struct.go
pkg/domain/trial/code_data_struct.go
+19
-11
pkg/domain/trial/code_function.go
pkg/domain/trial/code_function.go
+6
-0
trial/cocago/cocago_parser.go
trial/cocago/cocago_parser.go
+5
-5
trial/pkg/application/ts/ts_ident_app_test.go
trial/pkg/application/ts/ts_ident_app_test.go
+1
-1
trial/pkg/ast/pyast/python_ident_listener.go
trial/pkg/ast/pyast/python_ident_listener.go
+4
-4
trial/pkg/ast/ts/typescript_ident_converter.go
trial/pkg/ast/ts/typescript_ident_converter.go
+10
-2
trial/pkg/ast/ts/typescript_ident_listener.go
trial/pkg/ast/ts/typescript_ident_listener.go
+40
-9
未找到文件。
pkg/domain/trial/code_data_struct.go
浏览文件 @
ecb51d2d
package
trial
type
CodeDataStruct
struct
{
Name
string
Type
string
ID
string
MemberIds
[]
string
Extend
string
Implements
[]
string
Annotations
interface
{}
Properties
[]
CodeProperty
Functions
[]
CodeFunction
FunctionCalls
[]
CodeCall
Extension
interface
{}
Name
string
Type
string
ID
string
MemberIds
[]
string
Extend
string
Implements
[]
string
Annotations
interface
{}
InOutProperties
[]
CodeProperty
Functions
[]
CodeFunction
FunctionCalls
[]
CodeCall
// for field call
Extension
interface
{}
Fields
[]
CodeField
}
type
CodeField
struct
{
CodeProperty
TypeValue
string
}
type
JavaExtension
struct
{
...
...
pkg/domain/trial/code_function.go
浏览文件 @
ecb51d2d
...
...
@@ -12,3 +12,9 @@ type CodeFunction struct {
InnerFunctions
[]
CodeFunction
CodePosition
CodePosition
}
func
(
c
*
CodeFunction
)
BuildSingleReturnType
(
typeType
string
)
*
CodeProperty
{
return
&
CodeProperty
{
TypeType
:
typeType
,
}
}
trial/cocago/cocago_parser.go
浏览文件 @
ecb51d2d
...
...
@@ -118,10 +118,10 @@ func AddInterface(x *ast.InterfaceType, ident string, codeFile *trial.CodeFile)
properties
:=
BuildFieldToProperty
(
x
.
Methods
.
List
)
dataStruct
:=
trial
.
CodeDataStruct
{
Name
:
ident
,
ID
:
""
,
MemberIds
:
nil
,
Properties
:
properties
,
Name
:
ident
,
ID
:
""
,
MemberIds
:
nil
,
InOut
Properties
:
properties
,
}
member
:=
trial
.
CodeMember
{
...
...
@@ -270,7 +270,7 @@ func AddStructType(currentStruct trial.CodeDataStruct, x *ast.StructType, curren
for
_
,
field
:=
range
x
.
Fields
.
List
{
property
:=
BuildPropertyField
(
getFieldName
(
field
),
field
)
member
.
FileID
=
currentFile
.
FullName
currentStruct
.
Properties
=
append
(
currentStruct
.
Properties
,
*
property
)
currentStruct
.
InOutProperties
=
append
(
currentStruct
.
InOut
Properties
,
*
property
)
}
currentFile
.
Members
=
append
(
currentFile
.
Members
,
&
member
)
currentFile
.
DataStructures
=
append
(
currentFile
.
DataStructures
,
currentStruct
)
...
...
trial/pkg/application/ts/ts_ident_app_test.go
浏览文件 @
ecb51d2d
...
...
@@ -140,7 +140,7 @@ export interface IPerson {
g
.
Expect
(
len
(
results
[
0
]
.
Methods
))
.
To
(
Equal
(
2
))
//fmt.Println(codeFile.DataStructures)
//
g.Expect(len(codeFile.DataStructures[0].Functions)).To(Equal(2))
g
.
Expect
(
len
(
codeFile
.
DataStructures
[
0
]
.
Functions
))
.
To
(
Equal
(
2
))
g
.
Expect
(
firstMethod
.
Name
)
.
To
(
Equal
(
"getSalary"
))
g
.
Expect
(
secondMethod
.
Name
)
.
To
(
Equal
(
"getManagerName"
))
...
...
trial/pkg/ast/pyast/python_ident_listener.go
浏览文件 @
ecb51d2d
...
...
@@ -76,10 +76,10 @@ func (s *PythonIdentListener) EnterFrom_stmt(ctx *parser.From_stmtContext) {
func
(
s
*
PythonIdentListener
)
EnterClassdef
(
ctx
*
parser
.
ClassdefContext
)
{
hasEnterMember
=
true
dataStruct
:=
&
trial
.
CodeDataStruct
{
Name
:
ctx
.
Name
()
.
GetText
(),
ID
:
""
,
MemberIds
:
nil
,
Properties
:
nil
,
Name
:
ctx
.
Name
()
.
GetText
(),
ID
:
""
,
MemberIds
:
nil
,
InOut
Properties
:
nil
,
}
ctxIndex
:=
ast_util
.
GetNodeIndex
(
ctx
)
...
...
trial/pkg/ast/ts/typescript_ident_converter.go
浏览文件 @
ecb51d2d
...
...
@@ -72,9 +72,11 @@ func BuildImplements(typeList parser.IClassOrInterfaceTypeListContext) []string
return
implements
}
func
BuildMethodParameter
(
context
*
parser
.
ParameterListContext
)
[]
domain
.
JParameter
{
func
BuildMethodParameter
(
context
*
parser
.
ParameterListContext
)
([]
domain
.
JParameter
,
[]
trial
.
CodeProperty
)
{
childNode
:=
context
.
GetChild
(
0
)
var
parameters
[]
domain
.
JParameter
=
nil
var
codeParameters
[]
trial
.
CodeProperty
=
nil
switch
x
:=
childNode
.
(
type
)
{
case
*
parser
.
RequiredParameterListContext
:
listContext
:=
x
...
...
@@ -91,9 +93,15 @@ func BuildMethodParameter(context *parser.ParameterListContext) []domain.JParame
Name
:
"any"
,
Type
:
predefinedTypeContext
.
GetText
(),
})
parameter
:=
trial
.
CodeProperty
{
TypeName
:
"any"
,
TypeType
:
predefinedTypeContext
.
GetText
(),
}
codeParameters
=
append
(
codeParameters
,
parameter
)
}
return
parameters
return
parameters
,
codeParameters
}
func
buildRestParameters
(
ctx
*
parser
.
RestParameterContext
)
domain
.
JParameter
{
...
...
trial/pkg/ast/ts/typescript_ident_listener.go
浏览文件 @
ecb51d2d
...
...
@@ -104,28 +104,34 @@ func (s *TypeScriptIdentListener) EnterInterfaceDeclaration(ctx *parser.Interfac
objectTypeCtx
:=
ctx
.
ObjectType
()
.
(
*
parser
.
ObjectTypeContext
)
if
objectTypeCtx
.
TypeBody
()
!=
nil
{
typeMemberListCtx
:=
objectTypeCtx
.
TypeBody
()
.
(
*
parser
.
TypeBodyContext
)
.
TypeMemberList
()
.
(
*
parser
.
TypeMemberListContext
)
BuildInterfaceTypeBody
(
typeMemberListCtx
,
s
.
currentNode
)
BuildInterfaceTypeBody
(
typeMemberListCtx
,
s
.
currentNode
,
s
.
currentDataStruct
)
}
}
func
BuildInterfaceTypeBody
(
ctx
*
parser
.
TypeMemberListContext
,
classNode
*
domain
.
JClassNode
)
{
func
BuildInterfaceTypeBody
(
ctx
*
parser
.
TypeMemberListContext
,
classNode
*
domain
.
JClassNode
,
dataStruct
*
trial
.
CodeDataStruct
)
{
for
_
,
typeMember
:=
range
ctx
.
AllTypeMember
()
{
typeMemberCtx
:=
typeMember
.
(
*
parser
.
TypeMemberContext
)
memberChild
:=
typeMemberCtx
.
GetChild
(
0
)
switch
x
:=
memberChild
.
(
type
)
{
case
*
parser
.
PropertySignatureContext
:
BuildInterfacePropertySignature
(
x
,
classNode
)
BuildInterfacePropertySignature
(
x
,
classNode
,
dataStruct
)
case
*
parser
.
MethodSignatureContext
:
method
:=
domain
.
NewJMethod
()
method
.
Name
=
x
.
PropertyName
()
.
GetText
()
FillMethodFromCallSignature
(
x
.
CallSignature
()
.
(
*
parser
.
CallSignatureContext
),
&
method
)
function
:=
trial
.
CodeFunction
{
Name
:
x
.
PropertyName
()
.
GetText
(),
}
FillMethodFromCallSignature
(
x
.
CallSignature
()
.
(
*
parser
.
CallSignatureContext
),
&
method
,
&
function
)
dataStruct
.
Functions
=
append
(
dataStruct
.
Functions
,
function
)
classNode
.
Methods
=
append
(
classNode
.
Methods
,
method
)
}
}
}
func
BuildInterfacePropertySignature
(
signatureCtx
*
parser
.
PropertySignatureContext
,
classNode
*
domain
.
JClassNode
)
{
func
BuildInterfacePropertySignature
(
signatureCtx
*
parser
.
PropertySignatureContext
,
classNode
*
domain
.
JClassNode
,
dataStruct
*
trial
.
CodeDataStruct
)
{
typeType
:=
BuildTypeAnnotation
(
signatureCtx
.
TypeAnnotation
()
.
(
*
parser
.
TypeAnnotationContext
))
typeValue
:=
signatureCtx
.
PropertyName
()
.
(
*
parser
.
PropertyNameContext
)
.
GetText
()
...
...
@@ -141,13 +147,34 @@ func BuildInterfacePropertySignature(signatureCtx *parser.PropertySignatureConte
method
.
Type
=
signatureCtx
.
Type_
()
.
GetText
()
classNode
.
Methods
=
append
(
classNode
.
Methods
,
method
)
function
:=
&
trial
.
CodeFunction
{
Name
:
typeValue
,
}
param
:=
trial
.
CodeProperty
{
Name
:
"any"
,
TypeType
:
typeType
,
}
returnType
:=
trial
.
CodeProperty
{
TypeType
:
signatureCtx
.
Type_
()
.
GetText
(),
}
function
.
Parameters
=
append
(
function
.
Parameters
,
param
)
function
.
ReturnTypes
=
append
(
function
.
ReturnTypes
,
returnType
)
dataStruct
.
Functions
=
append
(
dataStruct
.
Functions
,
*
function
)
}
else
{
field
:=
&
domain
.
JField
{
Type
:
typeType
,
Value
:
typeValue
,
}
codeField
:=
&
trial
.
CodeField
{}
codeField
.
TypeType
=
typeType
codeField
.
TypeValue
=
typeValue
classNode
.
Fields
=
append
(
classNode
.
Fields
,
*
field
)
dataStruct
.
Fields
=
append
(
dataStruct
.
Fields
,
*
codeField
)
}
}
...
...
@@ -257,7 +284,7 @@ func (s *TypeScriptIdentListener) EnterFunctionDeclaration(ctx *parser.FunctionD
ast_util
.
AddPosition
(
&
method
,
ctx
.
GetChild
(
0
)
.
GetParent
()
.
(
*
antlr
.
BaseParserRuleContext
))
callSignatureContext
:=
ctx
.
CallSignature
()
.
(
*
parser
.
CallSignatureContext
)
FillMethodFromCallSignature
(
callSignatureContext
,
&
method
)
FillMethodFromCallSignature
(
callSignatureContext
,
&
method
,
nil
)
function
:=
&
trial
.
CodeFunction
{
Name
:
ctx
.
Identifier
()
.
GetText
(),
...
...
@@ -274,15 +301,19 @@ func (s *TypeScriptIdentListener) EnterFunctionDeclaration(ctx *parser.FunctionD
s
.
currentDataStruct
.
Functions
=
append
(
s
.
currentDataStruct
.
Functions
,
*
function
)
}
func
FillMethodFromCallSignature
(
callSignatureContext
*
parser
.
CallSignatureContext
,
method
*
domain
.
JMethod
)
{
func
FillMethodFromCallSignature
(
callSignatureContext
*
parser
.
CallSignatureContext
,
method
*
domain
.
JMethod
,
function
*
trial
.
CodeFunction
)
{
if
callSignatureContext
.
ParameterList
()
!=
nil
{
parameterListContext
:=
callSignatureContext
.
ParameterList
()
.
(
*
parser
.
ParameterListContext
)
methodParameters
:=
BuildMethodParameter
(
parameterListContext
)
methodParameters
,
_
:=
BuildMethodParameter
(
parameterListContext
)
method
.
Parameters
=
append
(
method
.
Parameters
,
methodParameters
...
)
}
if
callSignatureContext
.
TypeAnnotation
()
!=
nil
{
annotationContext
:=
callSignatureContext
.
TypeAnnotation
()
.
(
*
parser
.
TypeAnnotationContext
)
method
.
Type
=
BuildTypeAnnotation
(
annotationContext
)
typeAnnotation
:=
BuildTypeAnnotation
(
annotationContext
)
method
.
Type
=
typeAnnotation
function
.
ReturnTypes
=
append
(
function
.
ReturnTypes
,
*
function
.
BuildSingleReturnType
(
typeAnnotation
))
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录