Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iocli gen问题 #53

Closed
T-Manson opened this issue Jun 21, 2022 · 4 comments · Fixed by #157
Closed

iocli gen问题 #53

T-Manson opened this issue Jun 21, 2022 · 4 comments · Fixed by #157
Labels
bug Something isn't working good first issue Good for newcomers P1

Comments

@T-Manson
Copy link

type Test interface {
T(a int) (int64, []*int, error)
}

// +ioc:autowire=true
// +ioc:autowire:type=singleton
type TestImpl1 struct {
}

func (t *TestImpl1) T(a int) (int64, []*int, error) {
return 0, nil, nil
}

// +ioc:autowire=true
// +ioc:autowire:type=singleton
type TestImpl2 struct {
}

func (t *TestImpl2) T(a int) (int64, []*int, error) {
return 0, nil, nil
}

// +ioc:autowire=true
// +ioc:autowire:type=singleton
type TestImpl3 struct {
}

func (t *TestImpl3) T(
a int,
) (int64, []*int, error) {
return 0, nil, nil
}

使用 iocli gen后的zz_generated.ioc.go文件,如下:

//go:build !ignore_autogenerated
// +build !ignore_autogenerated

// Code generated by iocli, run 'iocli gen' to re-generate

package main

import (
autowire "github.com/alibaba/ioc-golang/autowire"
normal "github.com/alibaba/ioc-golang/autowire/normal"
singleton "github.com/alibaba/ioc-golang/autowire/singleton"
util "github.com/alibaba/ioc-golang/autowire/util"
)

func init() {
normal.RegisterStructDescriptor(&autowire.StructDescriptor{
Factory: func() interface{} {
return &testImpl1_{}
},
})
singleton.RegisterStructDescriptor(&autowire.StructDescriptor{
Factory: func() interface{} {
return &TestImpl1{}
},
})
normal.RegisterStructDescriptor(&autowire.StructDescriptor{
Factory: func() interface{} {
return &testImpl2_{}
},
})
singleton.RegisterStructDescriptor(&autowire.StructDescriptor{
Factory: func() interface{} {
return &TestImpl2{}
},
})
normal.RegisterStructDescriptor(&autowire.StructDescriptor{
Factory: func() interface{} {
return &testImpl3_{}
},
})
singleton.RegisterStructDescriptor(&autowire.StructDescriptor{
Factory: func() interface{} {
return &TestImpl3{}
},
})
}

type testImpl1_ struct {
T_ func(a int) (int64, []*int, error)
}

func (t *testImpl1_) T(a int) (int64, []*int, error) {
return t.T_(a)
}

type testImpl2_ struct {
T_ func(a int) (int64, []*int, error)
}

func (t *testImpl2_) T(a int) (int64, []*int, error) {
return t.T_(a)
}

type testImpl3_ struct {
}

type TestImpl1IOCInterface interface {
T(a int) (int64, []*int, error)
}

type TestImpl2IOCInterface interface {
T(a int) (int64, []*int, error)
}

type TestImpl3IOCInterface interface {
}

func GetTestImpl1() (*TestImpl1, error) {
i, err := singleton.GetImpl(util.GetSDIDByStructPtr(new(TestImpl1)), nil)
if err != nil {
return nil, err
}
impl := i.(*TestImpl1)
return impl, nil
}

func GetTestImpl1IOCInterface() (TestImpl1IOCInterface, error) {
i, err := singleton.GetImplWithProxy(util.GetSDIDByStructPtr(new(TestImpl1)), nil)
if err != nil {
return nil, err
}
impl := i.(TestImpl1IOCInterface)
return impl, nil
}

func GetTestImpl2() (*TestImpl2, error) {
i, err := singleton.GetImpl(util.GetSDIDByStructPtr(new(TestImpl2)), nil)
if err != nil {
return nil, err
}
impl := i.(*TestImpl2)
return impl, nil
}

func GetTestImpl2IOCInterface() (TestImpl2IOCInterface, error) {
i, err := singleton.GetImplWithProxy(util.GetSDIDByStructPtr(new(TestImpl2)), nil)
if err != nil {
return nil, err
}
impl := i.(TestImpl2IOCInterface)
return impl, nil
}

func GetTestImpl3() (*TestImpl3, error) {
i, err := singleton.GetImpl(util.GetSDIDByStructPtr(new(TestImpl3)), nil)
if err != nil {
return nil, err
}
impl := i.(*TestImpl3)
return impl, nil
}

func GetTestImpl3IOCInterface() (TestImpl3IOCInterface, error) {
i, err := singleton.GetImplWithProxy(util.GetSDIDByStructPtr(new(TestImpl3)), nil)
if err != nil {
return nil, err
}
impl := i.(TestImpl3IOCInterface)
return impl, nil
}

问题:
TestImpl3未正确生成对应函数签名,结果为空结构体。

@LaurenceLiZhixin LaurenceLiZhixin self-assigned this Jun 21, 2022
@LaurenceLiZhixin LaurenceLiZhixin added the bug Something isn't working label Jun 21, 2022
@LaurenceLiZhixin
Copy link
Collaborator

LaurenceLiZhixin commented Jun 21, 2022

@T-Manson 方法名需要写成一行才能识别到,这是个问题,后面会修

@T-Manson
Copy link
Author

@T-Manson 方法名需要写成一行才能识别到,这是个enhancement,后面会修

👌

@LaurenceLiZhixin LaurenceLiZhixin added the good first issue Good for newcomers label Jun 23, 2022
@LaurenceLiZhixin LaurenceLiZhixin removed their assignment Jul 2, 2022
@LaurenceLiZhixin
Copy link
Collaborator

@photowey How is going on with ast analysis of iocli ? I want to refactor codes and structure of iocli recently, and I'm worry about conflicts with your contribution.

@LaurenceLiZhixin
Copy link
Collaborator

解析占据多行的函数,如果覆盖全部写法,需要引入语法分析,这个能力可能要暂时被搁置了。目前只支持单行方法名解析,合法的方法签名所在行例如:

valid line is like
func (s *ServiceStruct) GetString(name string, param *substruct.Param) string {
func (s *ServiceStruct) GetString(param *substruct.Param) string {
func (s *ServiceStruct) GetString(name, param *substruct.Param) (string, error) {
func (s *ServiceStruct) GetString() string {
func (s *ServiceStruct) GetString()  {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers P1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants