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

Commitd32fb50

Browse files
committed
internal/analysisinternal: export EnclosingFile
...and use it throughout modernize.Change-Id: I8d9b94ed474750e00c94cc963745340cd7fb2348Reviewed-on:https://go-review.googlesource.com/c/tools/+/708956LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>Reviewed-by: Robert Findley <rfindley@google.com>
1 parent03ab8a0 commitd32fb50

File tree

11 files changed

+16
-20
lines changed

11 files changed

+16
-20
lines changed

‎go/analysis/passes/modernize/errorsastype.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func errorsastype(pass *analysis.Pass) (any, error) {
9494
continue
9595
}
9696

97-
file:=enclosingFile(curDeclStmt)
97+
file:=analysisinternal.EnclosingFile(curDeclStmt)
9898
if!fileUses(info,file,"go1.26") {
9999
continue// errors.AsType is too new
100100
}

‎go/analysis/passes/modernize/fmtappendf.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func fmtappendf(pass *analysis.Pass) (any, error) {
4949
conv:=curCall.Parent().Node().(*ast.CallExpr)
5050
tv:=pass.TypesInfo.Types[conv.Fun]
5151
iftv.IsType()&&types.Identical(tv.Type,byteSliceType)&&
52-
fileUses(pass.TypesInfo,enclosingFile(curCall),"go1.19") {
52+
fileUses(pass.TypesInfo,analysisinternal.EnclosingFile(curCall),"go1.19") {
5353
// Have: []byte(fmt.SprintX(...))
5454

5555
// Find "Sprint" identifier.

‎go/analysis/passes/modernize/modernize.go‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ func fileUses(info *types.Info, file *ast.File, version string) bool {
118118
return!versions.Before(info.FileVersions[file],version)
119119
}
120120

121-
// enclosingFile returns the syntax tree for the file enclosing c.
122-
funcenclosingFile(c inspector.Cursor)*ast.File {
123-
c,_=moreiters.First(c.Enclosing((*ast.File)(nil)))
124-
returnc.Node().(*ast.File)
125-
}
126-
127121
// within reports whether the current pass is analyzing one of the
128122
// specified standard packages or their dependencies.
129123
funcwithin(pass*analysis.Pass,pkgs...string)bool {

‎go/analysis/passes/modernize/newexpr.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func run(pass *analysis.Pass) (any, error) {
5858
pass.ExportObjectFact(fn,&newLike{})
5959

6060
// Check file version.
61-
file:=enclosingFile(curFuncDecl)
61+
file:=analysisinternal.EnclosingFile(curFuncDecl)
6262
if!fileUses(info,file,"go1.26") {
6363
continue// new(expr) not available in this file
6464
}
@@ -138,7 +138,7 @@ func run(pass *analysis.Pass) (any, error) {
138138
pass.ImportObjectFact(fn,&fact) {
139139

140140
// Check file version.
141-
file:=enclosingFile(curCall)
141+
file:=analysisinternal.EnclosingFile(curCall)
142142
if!fileUses(info,file,"go1.26") {
143143
continue// new(expr) not available in this file
144144
}

‎go/analysis/passes/modernize/reflect.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func reflecttypefor(pass *analysis.Pass) (any, error) {
8787
continue
8888
}
8989

90-
file:=enclosingFile(curCall)
90+
file:=analysisinternal.EnclosingFile(curCall)
9191
ifversions.Before(info.FileVersions[file],"go1.22") {
9292
continue// TypeFor requires go1.22
9393
}

‎go/analysis/passes/modernize/sortslice.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func slicessort(pass *analysis.Pass) (any, error) {
8484
is[*ast.Ident](index.Index)&&
8585
info.Uses[index.Index.(*ast.Ident)]==v
8686
}
87-
file:=enclosingFile(curCall)
87+
file:=analysisinternal.EnclosingFile(curCall)
8888
ifisIndex(compare.X,i)&&isIndex(compare.Y,j)&&
8989
fileUses(info,file,"go1.21") {
9090
// Have: sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })

‎go/analysis/passes/modernize/stditerators.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func stditerators(pass *analysis.Pass) (any, error) {
314314
// may be somewhat expensive.)
315315
ifv,ok:=methodGoVersion(row.pkgpath,row.typename,row.itermethod);!ok {
316316
panic("no version found")
317-
}elseiffile:=enclosingFile(curLenCall);!fileUses(info,file,v.String()) {
317+
}elseiffile:=analysisinternal.EnclosingFile(curLenCall);!fileUses(info,file,v.String()) {
318318
continue nextCall
319319
}
320320

‎go/analysis/passes/modernize/stringsbuilder.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ nextcand:
101101

102102
// Add strings import.
103103
_,prefix,importEdits:=analysisinternal.AddImport(
104-
pass.TypesInfo,enclosingFile(def),"strings","strings","Builder",v.Pos())
104+
pass.TypesInfo,analysisinternal.EnclosingFile(def),"strings","strings","Builder",v.Pos())
105105
edits=append(edits,importEdits...)
106106

107107
ifisEmptyString(pass.TypesInfo,assign.Rhs[0]) {
@@ -140,7 +140,7 @@ nextcand:
140140

141141
// Add strings import.
142142
_,prefix,importEdits:=analysisinternal.AddImport(
143-
pass.TypesInfo,enclosingFile(def),"strings","strings","Builder",v.Pos())
143+
pass.TypesInfo,analysisinternal.EnclosingFile(def),"strings","strings","Builder",v.Pos())
144144
edits=append(edits,importEdits...)
145145

146146
spec:=def.Parent().Node().(*ast.ValueSpec)

‎go/analysis/passes/modernize/testingcontext.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ calls:
135135
testObj=isTestFn(info,n)
136136
}
137137
}
138-
iftestObj!=nil&&fileUses(info,enclosingFile(cur),"go1.24") {
138+
iftestObj!=nil&&fileUses(info,analysisinternal.EnclosingFile(cur),"go1.24") {
139139
// Have a test function. Check that we can resolve the relevant
140140
// testing.{T,B,F} at the current position.
141141
if_,obj:=lhs[0].Parent().LookupParent(testObj.Name(),lhs[0].Pos());obj==testObj {

‎go/analysis/passes/modernize/waitgroup.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func waitgroup(pass *analysis.Pass) (any, error) {
126126
panic("can't find Cursor for 'done' statement")
127127
}
128128

129-
file:=enclosingFile(curAddCall)
129+
file:=analysisinternal.EnclosingFile(curAddCall)
130130
if!fileUses(info,file,"go1.25") {
131131
continue
132132
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp