Debian Codegraph @

internal/refactor/refactor.go

raw symbols SCIP
1 // Copyright 2025 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 // Package refactor provides operators to compute common textual edits
6 // for refactoring tools.
7 //
8 // This package should not use features of the analysis API other than [Edit].
9 package refactorscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/refactor`/
10
11 import (
12 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
13 "go/tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/"
14 "go/typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/"
15 )
16
17 // FreshName returns the name of an identifier that is undefined
18 // at the specified position, based on the preferred name.
19 //
20 // export/use freshName in go/analysis/passes/modernize/modernize.go if you want
21 // to generate a fresh name only when necessary (i.e., there is both an existing
22 // declaration and some free reference to the name within a narrower scope)
23 func FreshNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/refactor`/FreshName().(scope *typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Scopescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Scope#, pos tokenscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/.Posscip-go gomod github.com/golang/go/src go1.25.0 `go/token`/Pos#, preferred string) string {
24 newName := preferred
25 for i := 0; ; i++ {
26 if _, obj := scope.LookupParentscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Scope#LookupParent().(newName, pos); obj == nil {
27 break // fresh
28 }
29 newName = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s%d", preferred, i)
30 }
31 return newName
32 }