kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/indexer/testdata/override.go (about)

     1  // Package override tests that override edges are correcty generated between
     2  // methods of concrete types and the interfaces they satisfy.
     3  package override
     4  
     5  import (
     6  	_ "fmt"
     7  	"strings"
     8  )
     9  
    10  // - @Thinger defines/binding Thinger
    11  // - Thinger.node/kind interface
    12  type Thinger interface {
    13  	//- @Thing defines/binding AbstractThing
    14  	//- Thing.node/kind function
    15  	//- Thing childof Thinger
    16  	//- AbstractThing typed AbstractThingType
    17  	Thing()
    18  }
    19  
    20  // - @Stuffer defines/binding Stuffer
    21  // - Stuffer.node/kind interface
    22  // - Stuffer extends Thinger
    23  type Stuffer interface {
    24  	Thinger
    25  
    26  	//- @Stuff defines/binding AbstractStuff
    27  	//- Stuff.node/kind function
    28  	//- Stuff childof Stuffer
    29  	//- AbstractStuff typed AbstractStuffType
    30  	Stuff()
    31  }
    32  
    33  // - @foo defines/binding Foo
    34  // - Foo.node/kind record
    35  // - Foo satisfies Thinger
    36  // - Foo satisfies Stuffer
    37  type foo struct{}
    38  
    39  // - @Thing defines/binding ConcreteThing
    40  // - ConcreteThing.node/kind function
    41  // - ConcreteThing childof Foo
    42  // - ConcreteThing overrides AbstractThing
    43  // - ConcreteThing typed ConcreteThingType
    44  // - ConcreteThingType satisfies AbstractThingType
    45  // - !{ ConcreteThing overrides FoilThing }
    46  func (foo) Thing() {}
    47  
    48  // - @Stuff defines/binding ConcreteStuff
    49  // - ConcreteStuff.node/kind function
    50  // - ConcreteStuff childof Foo
    51  // - ConcreteStuff overrides AbstractStuff
    52  // - ConcreteStuff typed ConcreteStuffType
    53  // - ConcreteStuffType satisfies AbstractStuffType
    54  func (foo) Stuff() {}
    55  
    56  // - @bar defines/binding Bar
    57  // - Bar.node/kind record
    58  // - Bar satisfies Thinger
    59  // - Bar satisfies vname("type Stringer",_,_,"fmt","go")
    60  // - !{ Bar satisfies Stuffer }
    61  type bar struct{}
    62  
    63  // - @Thing defines/binding OtherConcreteThing
    64  // - OtherConcreteThing.node/kind function
    65  // - OtherConcreteThing childof Bar
    66  // - OtherConcreteThing overrides AbstractThing
    67  // - !{ OtherConcreteThing overrides FoilThing }
    68  func (*bar) Thing() {}
    69  
    70  // - @String defines/binding String
    71  // - String.node/kind function
    72  // - String childof Bar
    73  // - String overrides vname("method Stringer.String",_,_,"fmt","go")
    74  func (*bar) String() string { return "" }
    75  
    76  // Foil has a method with the same name as Thinger, but is not a compatible
    77  // type signature. We use this to verify that we don't try to emit override
    78  // edges unless the assignability check passes.
    79  //
    80  // - @Foil defines/binding Foil
    81  // - Foil.node/kind interface
    82  type Foil interface {
    83  	//- @Thing defines/binding FoilThing
    84  	//- FoilThing.node/kind function
    85  	//- FoilThing childof Foil
    86  	Thing(bool)
    87  }
    88  
    89  // - @Grower defines/binding Grower
    90  // - Grower.node/kind interface
    91  // - StringBuilder satisfies Grower
    92  type Grower interface {
    93  	//- @Grow defines/binding Grow
    94  	//- Grow.node/kind function
    95  	Grow(int)
    96  
    97  	//- StringBuilderGrow overrides Grow
    98  }
    99  
   100  // - @Builder ref StringBuilder
   101  var _ Grower = &strings.Builder{}
   102  
   103  // - @Grow ref StringBuilderGrow
   104  func init() { (&strings.Builder{}).Grow(10) }