golang.org/x/tools/gopls@v0.15.3/internal/golang/origin_119.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build go1.19
     6  // +build go1.19
     7  
     8  package golang
     9  
    10  import "go/types"
    11  
    12  // containsOrigin reports whether the provided object set contains an object
    13  // with the same origin as the provided obj (which may be a synthetic object
    14  // created during instantiation).
    15  func containsOrigin(objSet map[types.Object]bool, obj types.Object) bool {
    16  	objOrigin := origin(obj)
    17  	for target := range objSet {
    18  		if origin(target) == objOrigin {
    19  			return true
    20  		}
    21  	}
    22  	return false
    23  }
    24  
    25  func origin(obj types.Object) types.Object {
    26  	switch obj := obj.(type) {
    27  	case *types.Var:
    28  		return obj.Origin()
    29  	case *types.Func:
    30  		return obj.Origin()
    31  	}
    32  	return obj
    33  }