Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76aace8

Browse files
committed
internal/analysisinternal: rationalize
This CL moves declarations as described below,and updates comments. No logic was changed exceptin merging the DocComment functions, and inusing safetoken from TypeErrorEndPos within gopls.internal/astutil (pure syntax)+ func Comments+ func DocComment (merging various unexported copies)+ func EnclosingFile+ func Format+ func IsChildOfinternal/typesinternal (typed syntax)+ func EnclosingScope+ func Imports+ func IsFunctionNamed+ func IsMethodNamed+ func IsPointerToNamed+ func IsTypeNamed- func IsZeroExpr (moved to fillreturns)internal/analysisinternal (use of analysis framework)- func AddImport- func Comments- func DeleteDecl- func DeleteSpec- func DeleteStmt- func DeleteVar- func EnclosingFile- func EnclosingScope- func Format- func FreshName- func Imports- func IsChildOf- func IsFunctionNamed- func IsMethodNamed- func IsPointerToNamed- func IsTypeNamed- func TypeErrorEndPos (moved to gopls/internal/cache)internal/refactor: (computing text edits from typed syntax)+ func AddImport+ func DeleteDecl+ func DeleteSpec+ func DeleteStmt+ func DeleteVar+ func FreshNameChange-Id: I9fad550ee55efbeb217627570e3a2e9abfee2178Reviewed-on:https://go-review.googlesource.com/c/tools/+/710295Reviewed-by: Robert Findley <rfindley@google.com>LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent8cf2d63 commit76aace8

File tree

70 files changed

+1048
-962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1048
-962
lines changed

‎go/analysis/passes/assign/assign.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"golang.org/x/tools/go/analysis/passes/inspect"
2020
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
2121
"golang.org/x/tools/go/ast/inspector"
22-
"golang.org/x/tools/internal/analysisinternal"
22+
"golang.org/x/tools/internal/astutil"
2323
)
2424

2525
//go:embed doc.go
@@ -66,8 +66,8 @@ func run(pass *analysis.Pass) (any, error) {
6666
!isMapIndex(pass.TypesInfo,lhs)&&
6767
reflect.TypeOf(lhs)==reflect.TypeOf(rhs) {// short-circuit the heavy-weight gofmt check
6868

69-
le=analysisinternal.Format(pass.Fset,lhs)
70-
re:=analysisinternal.Format(pass.Fset,rhs)
69+
le=astutil.Format(pass.Fset,lhs)
70+
re:=astutil.Format(pass.Fset,rhs)
7171
ifle==re {
7272
isSelfAssign=true
7373
}

‎go/analysis/passes/atomic/atomic.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import (
1414
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
1515
"golang.org/x/tools/go/ast/inspector"
1616
"golang.org/x/tools/go/types/typeutil"
17-
"golang.org/x/tools/internal/analysisinternal"
17+
"golang.org/x/tools/internal/astutil"
18+
"golang.org/x/tools/internal/typesinternal"
1819
)
1920

2021
//go:embed doc.go
@@ -30,7 +31,7 @@ var Analyzer = &analysis.Analyzer{
3031
}
3132

3233
funcrun(pass*analysis.Pass) (any,error) {
33-
if!analysisinternal.Imports(pass.Pkg,"sync/atomic") {
34+
if!typesinternal.Imports(pass.Pkg,"sync/atomic") {
3435
returnnil,nil// doesn't directly import sync/atomic
3536
}
3637

@@ -54,7 +55,7 @@ func run(pass *analysis.Pass) (any, error) {
5455
continue
5556
}
5657
obj:=typeutil.Callee(pass.TypesInfo,call)
57-
ifanalysisinternal.IsFunctionNamed(obj,"sync/atomic","AddInt32","AddInt64","AddUint32","AddUint64","AddUintptr") {
58+
iftypesinternal.IsFunctionNamed(obj,"sync/atomic","AddInt32","AddInt64","AddUint32","AddUint64","AddUintptr") {
5859
checkAtomicAddAssignment(pass,n.Lhs[i],call)
5960
}
6061
}
@@ -72,7 +73,7 @@ func checkAtomicAddAssignment(pass *analysis.Pass, left ast.Expr, call *ast.Call
7273
arg:=call.Args[0]
7374
broken:=false
7475

75-
gofmt:=func(e ast.Expr)string {returnanalysisinternal.Format(pass.Fset,e) }
76+
gofmt:=func(e ast.Expr)string {returnastutil.Format(pass.Fset,e) }
7677

7778
ifuarg,ok:=arg.(*ast.UnaryExpr);ok&&uarg.Op==token.AND {
7879
broken=gofmt(left)==gofmt(uarg.X)

‎go/analysis/passes/atomicalign/atomicalign.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"golang.org/x/tools/go/analysis/passes/inspect"
1919
"golang.org/x/tools/go/ast/inspector"
2020
"golang.org/x/tools/go/types/typeutil"
21-
"golang.org/x/tools/internal/analysisinternal"
21+
"golang.org/x/tools/internal/typesinternal"
2222
)
2323

2424
constDoc="check for non-64-bits-aligned arguments to sync/atomic functions"
@@ -35,7 +35,7 @@ func run(pass *analysis.Pass) (any, error) {
3535
if8*pass.TypesSizes.Sizeof(types.Typ[types.Uintptr])==64 {
3636
returnnil,nil// 64-bit platform
3737
}
38-
if!analysisinternal.Imports(pass.Pkg,"sync/atomic") {
38+
if!typesinternal.Imports(pass.Pkg,"sync/atomic") {
3939
returnnil,nil// doesn't directly import sync/atomic
4040
}
4141

@@ -54,7 +54,7 @@ func run(pass *analysis.Pass) (any, error) {
5454
inspect.Preorder(nodeFilter,func(node ast.Node) {
5555
call:=node.(*ast.CallExpr)
5656
obj:=typeutil.Callee(pass.TypesInfo,call)
57-
ifanalysisinternal.IsFunctionNamed(obj,"sync/atomic",funcNames...) {
57+
iftypesinternal.IsFunctionNamed(obj,"sync/atomic",funcNames...) {
5858
// For all the listed functions, the expression to check is always the first function argument.
5959
check64BitAlignment(pass,obj.Name(),call.Args[0])
6060
}

‎go/analysis/passes/bools/bools.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"golang.org/x/tools/go/analysis/passes/inspect"
1616
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
1717
"golang.org/x/tools/go/ast/inspector"
18-
"golang.org/x/tools/internal/analysisinternal"
18+
"golang.org/x/tools/internal/astutil"
1919
)
2020

2121
constDoc="check for common mistakes involving boolean operators"
@@ -104,7 +104,7 @@ func (op boolOp) commutativeSets(info *types.Info, e *ast.BinaryExpr, seen map[*
104104
func (opboolOp)checkRedundant(pass*analysis.Pass,exprs []ast.Expr) {
105105
seen:=make(map[string]bool)
106106
for_,e:=rangeexprs {
107-
efmt:=analysisinternal.Format(pass.Fset,e)
107+
efmt:=astutil.Format(pass.Fset,e)
108108
ifseen[efmt] {
109109
pass.ReportRangef(e,"redundant %s: %s %s %s",op.name,efmt,op.tok,efmt)
110110
}else {
@@ -150,8 +150,8 @@ func (op boolOp) checkSuspect(pass *analysis.Pass, exprs []ast.Expr) {
150150
}
151151

152152
// e is of the form 'x != c' or 'x == c'.
153-
xfmt:=analysisinternal.Format(pass.Fset,x)
154-
efmt:=analysisinternal.Format(pass.Fset,e)
153+
xfmt:=astutil.Format(pass.Fset,x)
154+
efmt:=astutil.Format(pass.Fset,e)
155155
ifprev,found:=seen[xfmt];found {
156156
// checkRedundant handles the case in which efmt == prev.
157157
ifefmt!=prev {

‎go/analysis/passes/cgocall/cgocall.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"strconv"
1919

2020
"golang.org/x/tools/go/analysis"
21-
"golang.org/x/tools/internal/analysisinternal"
21+
"golang.org/x/tools/internal/typesinternal"
2222
)
2323

2424
constdebug=false
@@ -41,7 +41,7 @@ var Analyzer = &analysis.Analyzer{
4141
}
4242

4343
funcrun(pass*analysis.Pass) (any,error) {
44-
if!analysisinternal.Imports(pass.Pkg,"runtime/cgo") {
44+
if!typesinternal.Imports(pass.Pkg,"runtime/cgo") {
4545
returnnil,nil// doesn't use cgo
4646
}
4747

‎go/analysis/passes/copylock/copylock.go‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
"golang.org/x/tools/go/analysis"
1717
"golang.org/x/tools/go/analysis/passes/inspect"
1818
"golang.org/x/tools/go/ast/inspector"
19-
"golang.org/x/tools/internal/analysisinternal"
19+
"golang.org/x/tools/internal/astutil"
2020
"golang.org/x/tools/internal/typeparams"
21+
"golang.org/x/tools/internal/typesinternal"
2122
"golang.org/x/tools/internal/versions"
2223
)
2324

@@ -86,7 +87,7 @@ func checkCopyLocksAssign(pass *analysis.Pass, assign *ast.AssignStmt, goversion
8687
lhs:=assign.Lhs
8788
fori,x:=rangeassign.Rhs {
8889
ifpath:=lockPathRhs(pass,x);path!=nil {
89-
pass.ReportRangef(x,"assignment copies lock value to %v: %v",analysisinternal.Format(pass.Fset,assign.Lhs[i]),path)
90+
pass.ReportRangef(x,"assignment copies lock value to %v: %v",astutil.Format(pass.Fset,assign.Lhs[i]),path)
9091
lhs=nil// An lhs has been reported. We prefer the assignment warning and do not report twice.
9192
}
9293
}
@@ -100,7 +101,7 @@ func checkCopyLocksAssign(pass *analysis.Pass, assign *ast.AssignStmt, goversion
100101
ifid,ok:=l.(*ast.Ident);ok&&id.Name!="_" {
101102
ifobj:=pass.TypesInfo.Defs[id];obj!=nil&&obj.Type()!=nil {
102103
ifpath:=lockPath(pass.Pkg,obj.Type(),nil);path!=nil {
103-
pass.ReportRangef(l,"for loop iteration copies lock value to %v: %v",analysisinternal.Format(pass.Fset,l),path)
104+
pass.ReportRangef(l,"for loop iteration copies lock value to %v: %v",astutil.Format(pass.Fset,l),path)
104105
}
105106
}
106107
}
@@ -132,7 +133,7 @@ func checkCopyLocksCompositeLit(pass *analysis.Pass, cl *ast.CompositeLit) {
132133
x=node.Value
133134
}
134135
ifpath:=lockPathRhs(pass,x);path!=nil {
135-
pass.ReportRangef(x,"literal copies lock value from %v: %v",analysisinternal.Format(pass.Fset,x),path)
136+
pass.ReportRangef(x,"literal copies lock value from %v: %v",astutil.Format(pass.Fset,x),path)
136137
}
137138
}
138139
}
@@ -166,7 +167,7 @@ func checkCopyLocksCallExpr(pass *analysis.Pass, ce *ast.CallExpr) {
166167
}
167168
for_,x:=rangece.Args {
168169
ifpath:=lockPathRhs(pass,x);path!=nil {
169-
pass.ReportRangef(x,"call of %s copies lock value: %v",analysisinternal.Format(pass.Fset,ce.Fun),path)
170+
pass.ReportRangef(x,"call of %s copies lock value: %v",astutil.Format(pass.Fset,ce.Fun),path)
170171
}
171172
}
172173
}
@@ -233,7 +234,7 @@ func checkCopyLocksRangeVar(pass *analysis.Pass, rtok token.Token, e ast.Expr) {
233234
return
234235
}
235236
ifpath:=lockPath(pass.Pkg,typ,nil);path!=nil {
236-
pass.Reportf(e.Pos(),"range var %s copies lock: %v",analysisinternal.Format(pass.Fset,e),path)
237+
pass.Reportf(e.Pos(),"range var %s copies lock: %v",astutil.Format(pass.Fset,e),path)
237238
}
238239
}
239240

@@ -353,7 +354,7 @@ func lockPath(tpkg *types.Package, typ types.Type, seen map[types.Type]bool) typ
353354
// In go1.10, sync.noCopy did not implement Locker.
354355
// (The Unlock method was added only in CL 121876.)
355356
// TODO(adonovan): remove workaround when we drop go1.10.
356-
ifanalysisinternal.IsTypeNamed(typ,"sync","noCopy") {
357+
iftypesinternal.IsTypeNamed(typ,"sync","noCopy") {
357358
return []string{typ.String()}
358359
}
359360

‎go/analysis/passes/deepequalerrors/deepequalerrors.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"golang.org/x/tools/go/analysis/passes/inspect"
1515
"golang.org/x/tools/go/ast/inspector"
1616
"golang.org/x/tools/go/types/typeutil"
17-
"golang.org/x/tools/internal/analysisinternal"
17+
"golang.org/x/tools/internal/typesinternal"
1818
)
1919

2020
constDoc=`check for calls of reflect.DeepEqual on error values
@@ -35,7 +35,7 @@ var Analyzer = &analysis.Analyzer{
3535
}
3636

3737
funcrun(pass*analysis.Pass) (any,error) {
38-
if!analysisinternal.Imports(pass.Pkg,"reflect") {
38+
if!typesinternal.Imports(pass.Pkg,"reflect") {
3939
returnnil,nil// doesn't directly import reflect
4040
}
4141

@@ -47,7 +47,7 @@ func run(pass *analysis.Pass) (any, error) {
4747
inspect.Preorder(nodeFilter,func(n ast.Node) {
4848
call:=n.(*ast.CallExpr)
4949
obj:=typeutil.Callee(pass.TypesInfo,call)
50-
ifanalysisinternal.IsFunctionNamed(obj,"reflect","DeepEqual")&&hasError(pass,call.Args[0])&&hasError(pass,call.Args[1]) {
50+
iftypesinternal.IsFunctionNamed(obj,"reflect","DeepEqual")&&hasError(pass,call.Args[0])&&hasError(pass,call.Args[1]) {
5151
pass.ReportRangef(call,"avoid using reflect.DeepEqual with errors")
5252
}
5353
})

‎go/analysis/passes/defers/defers.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
1414
"golang.org/x/tools/go/ast/inspector"
1515
"golang.org/x/tools/go/types/typeutil"
16-
"golang.org/x/tools/internal/analysisinternal"
16+
"golang.org/x/tools/internal/typesinternal"
1717
)
1818

1919
//go:embed doc.go
@@ -29,14 +29,14 @@ var Analyzer = &analysis.Analyzer{
2929
}
3030

3131
funcrun(pass*analysis.Pass) (any,error) {
32-
if!analysisinternal.Imports(pass.Pkg,"time") {
32+
if!typesinternal.Imports(pass.Pkg,"time") {
3333
returnnil,nil
3434
}
3535

3636
checkDeferCall:=func(node ast.Node)bool {
3737
switchv:=node.(type) {
3838
case*ast.CallExpr:
39-
ifanalysisinternal.IsFunctionNamed(typeutil.Callee(pass.TypesInfo,v),"time","Since") {
39+
iftypesinternal.IsFunctionNamed(typeutil.Callee(pass.TypesInfo,v),"time","Since") {
4040
pass.Reportf(v.Pos(),"call to time.Since is not deferred")
4141
}
4242
case*ast.FuncLit:

‎go/analysis/passes/httpmux/httpmux.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"golang.org/x/tools/go/analysis/passes/inspect"
1818
"golang.org/x/tools/go/ast/inspector"
1919
"golang.org/x/tools/go/types/typeutil"
20-
"golang.org/x/tools/internal/analysisinternal"
2120
"golang.org/x/tools/internal/typesinternal"
2221
)
2322

@@ -46,7 +45,7 @@ func run(pass *analysis.Pass) (any, error) {
4645
returnnil,nil
4746
}
4847
}
49-
if!analysisinternal.Imports(pass.Pkg,"net/http") {
48+
if!typesinternal.Imports(pass.Pkg,"net/http") {
5049
returnnil,nil
5150
}
5251
// Look for calls to ServeMux.Handle or ServeMux.HandleFunc.
@@ -79,15 +78,15 @@ func isServeMuxRegisterCall(pass *analysis.Pass, call *ast.CallExpr) bool {
7978
iffn==nil {
8079
returnfalse
8180
}
82-
ifanalysisinternal.IsFunctionNamed(fn,"net/http","Handle","HandleFunc") {
81+
iftypesinternal.IsFunctionNamed(fn,"net/http","Handle","HandleFunc") {
8382
returntrue
8483
}
8584
if!isMethodNamed(fn,"net/http","Handle","HandleFunc") {
8685
returnfalse
8786
}
8887
recv:=fn.Type().(*types.Signature).Recv()// isMethodNamed() -> non-nil
8988
isPtr,named:=typesinternal.ReceiverNamed(recv)
90-
returnisPtr&&analysisinternal.IsTypeNamed(named,"net/http","ServeMux")
89+
returnisPtr&&typesinternal.IsTypeNamed(named,"net/http","ServeMux")
9190
}
9291

9392
// isMethodNamed reports when a function f is a method,

‎go/analysis/passes/httpresponse/httpresponse.go‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"golang.org/x/tools/go/analysis"
1414
"golang.org/x/tools/go/analysis/passes/inspect"
1515
"golang.org/x/tools/go/ast/inspector"
16-
"golang.org/x/tools/internal/analysisinternal"
1716
"golang.org/x/tools/internal/typesinternal"
1817
)
1918

@@ -46,7 +45,7 @@ func run(pass *analysis.Pass) (any, error) {
4645

4746
// Fast path: if the package doesn't import net/http,
4847
// skip the traversal.
49-
if!analysisinternal.Imports(pass.Pkg,"net/http") {
48+
if!typesinternal.Imports(pass.Pkg,"net/http") {
5049
returnnil,nil
5150
}
5251

@@ -118,7 +117,7 @@ func isHTTPFuncOrMethodOnClient(info *types.Info, expr *ast.CallExpr) bool {
118117
returnfalse// the function called does not return two values.
119118
}
120119
isPtr,named:=typesinternal.ReceiverNamed(res.At(0))
121-
if!isPtr||named==nil||!analysisinternal.IsTypeNamed(named,"net/http","Response") {
120+
if!isPtr||named==nil||!typesinternal.IsTypeNamed(named,"net/http","Response") {
122121
returnfalse// the first return type is not *http.Response.
123122
}
124123

@@ -133,11 +132,11 @@ func isHTTPFuncOrMethodOnClient(info *types.Info, expr *ast.CallExpr) bool {
133132
returnok&&id.Name=="http"// function in net/http package.
134133
}
135134

136-
ifanalysisinternal.IsTypeNamed(typ,"net/http","Client") {
135+
iftypesinternal.IsTypeNamed(typ,"net/http","Client") {
137136
returntrue// method on http.Client.
138137
}
139138
ptr,ok:=types.Unalias(typ).(*types.Pointer)
140-
returnok&&analysisinternal.IsTypeNamed(ptr.Elem(),"net/http","Client")// method on *http.Client.
139+
returnok&&typesinternal.IsTypeNamed(ptr.Elem(),"net/http","Client")// method on *http.Client.
141140
}
142141

143142
// restOfBlock, given a traversal stack, finds the innermost containing

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp