github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/knowledge/signatures.go (about)

     1  package knowledge
     2  
     3  import (
     4  	"go/token"
     5  	"go/types"
     6  )
     7  
     8  var Signatures = map[string]*types.Signature{
     9  	"(io.Seeker).Seek": types.NewSignatureType(nil, nil, nil,
    10  		types.NewTuple(
    11  			types.NewParam(token.NoPos, nil, "", types.Typ[types.Int64]),
    12  			types.NewParam(token.NoPos, nil, "", types.Typ[types.Int]),
    13  		),
    14  		types.NewTuple(
    15  			types.NewParam(token.NoPos, nil, "", types.Typ[types.Int64]),
    16  			types.NewParam(token.NoPos, nil, "", types.Universe.Lookup("error").Type()),
    17  		),
    18  		false,
    19  	),
    20  
    21  	"(io.Writer).Write": types.NewSignatureType(nil, nil, nil,
    22  		types.NewTuple(
    23  			types.NewParam(token.NoPos, nil, "", types.NewSlice(types.Typ[types.Byte])),
    24  		),
    25  		types.NewTuple(
    26  			types.NewParam(token.NoPos, nil, "", types.Typ[types.Int]),
    27  			types.NewParam(token.NoPos, nil, "", types.Universe.Lookup("error").Type()),
    28  		),
    29  		false,
    30  	),
    31  
    32  	"(io.StringWriter).WriteString": types.NewSignatureType(nil, nil, nil,
    33  		types.NewTuple(
    34  			types.NewParam(token.NoPos, nil, "", types.Typ[types.String]),
    35  		),
    36  		types.NewTuple(
    37  			types.NewParam(token.NoPos, nil, "", types.Typ[types.Int]),
    38  			types.NewParam(token.NoPos, nil, "", types.Universe.Lookup("error").Type()),
    39  		),
    40  		false,
    41  	),
    42  
    43  	"(encoding.TextMarshaler).MarshalText": types.NewSignatureType(nil, nil, nil,
    44  		types.NewTuple(),
    45  		types.NewTuple(
    46  			types.NewParam(token.NoPos, nil, "", types.NewSlice(types.Typ[types.Byte])),
    47  			types.NewParam(token.NoPos, nil, "", types.Universe.Lookup("error").Type()),
    48  		),
    49  		false,
    50  	),
    51  
    52  	"(encoding/json.Marshaler).MarshalJSON": types.NewSignatureType(nil, nil, nil,
    53  		types.NewTuple(),
    54  		types.NewTuple(
    55  			types.NewParam(token.NoPos, nil, "", types.NewSlice(types.Typ[types.Byte])),
    56  			types.NewParam(token.NoPos, nil, "", types.Universe.Lookup("error").Type()),
    57  		),
    58  		false,
    59  	),
    60  
    61  	"(fmt.Stringer).String": types.NewSignatureType(nil, nil, nil,
    62  		types.NewTuple(),
    63  		types.NewTuple(
    64  			types.NewParam(token.NoPos, nil, "", types.Typ[types.String]),
    65  		),
    66  		false,
    67  	),
    68  }
    69  
    70  var Interfaces = map[string]*types.Interface{
    71  	"fmt.Stringer": types.NewInterfaceType(
    72  		[]*types.Func{
    73  			types.NewFunc(token.NoPos, nil, "String", Signatures["(fmt.Stringer).String"]),
    74  		},
    75  		nil,
    76  	).Complete(),
    77  
    78  	"error": types.Universe.Lookup("error").Type().Underlying().(*types.Interface),
    79  
    80  	"io.Writer": types.NewInterfaceType(
    81  		[]*types.Func{
    82  			types.NewFunc(token.NoPos, nil, "Write", Signatures["(io.Writer).Write"]),
    83  		},
    84  		nil,
    85  	).Complete(),
    86  
    87  	"io.StringWriter": types.NewInterfaceType(
    88  		[]*types.Func{
    89  			types.NewFunc(token.NoPos, nil, "WriteString", Signatures["(io.StringWriter).WriteString"]),
    90  		},
    91  		nil,
    92  	).Complete(),
    93  
    94  	"encoding.TextMarshaler": types.NewInterfaceType(
    95  		[]*types.Func{
    96  			types.NewFunc(token.NoPos, nil, "MarshalText", Signatures["(encoding.TextMarshaler).MarshalText"]),
    97  		},
    98  		nil,
    99  	).Complete(),
   100  
   101  	"encoding/json.Marshaler": types.NewInterfaceType(
   102  		[]*types.Func{
   103  			types.NewFunc(token.NoPos, nil, "MarshalJSON", Signatures["(encoding/json.Marshaler).MarshalJSON"]),
   104  		},
   105  		nil,
   106  	).Complete(),
   107  }