Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
b0360e46
Commit
b0360e46
authored
Jan 20, 2012
by
Scott Lawrence
Committed by
Russ Cox
Jan 20, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/ast: respect ImportSpec.EndPos
Fixes #2566. R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/5541068
parent
88010973
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
7 deletions
+37
-7
src/cmd/gofix/import_test.go
src/cmd/gofix/import_test.go
+36
-1
src/pkg/go/ast/import.go
src/pkg/go/ast/import.go
+1
-6
No files found.
src/cmd/gofix/import_test.go
View file @
b0360e46
...
...
@@ -351,7 +351,7 @@ var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18
`
,
},
{
Name
:
"import.
3
"
,
Name
:
"import.
17
"
,
Fn
:
addImportFn
(
"x/y/z"
,
"x/a/c"
),
In
:
`package main
...
...
@@ -382,6 +382,26 @@ import (
"d/f"
)
`
,
},
{
Name
:
"import.18"
,
Fn
:
addDelImportFn
(
"e"
,
"o"
),
In
:
`package main
import (
"f"
"o"
"z"
)
`
,
Out
:
`package main
import (
"e"
"f"
"z"
)
`
,
},
}
...
...
@@ -409,6 +429,21 @@ func deleteImportFn(path string) func(*ast.File) bool {
}
}
func
addDelImportFn
(
p1
string
,
p2
string
)
func
(
*
ast
.
File
)
bool
{
return
func
(
f
*
ast
.
File
)
bool
{
fixed
:=
false
if
!
imports
(
f
,
p1
)
{
addImport
(
f
,
p1
)
fixed
=
true
}
if
imports
(
f
,
p2
)
{
deleteImport
(
f
,
p2
)
fixed
=
true
}
return
fixed
}
}
func
rewriteImportFn
(
oldnew
...
string
)
func
(
*
ast
.
File
)
bool
{
return
func
(
f
*
ast
.
File
)
bool
{
fixed
:=
false
...
...
src/pkg/go/ast/import.go
View file @
b0360e46
...
...
@@ -67,12 +67,7 @@ func sortSpecs(fset *token.FileSet, f *File, specs []Spec) {
// Record positions for specs.
pos
:=
make
([]
posSpan
,
len
(
specs
))
for
i
,
s
:=
range
specs
{
// Cannot use s.End(), because it looks at len(s.Path.Value),
// and that string might have gotten longer or shorter.
// Instead, use s.Pos()+1, which is guaranteed to be > s.Pos()
// and still before the original end of the string, since any
// string literal must be at least 2 characters ("" or ``).
pos
[
i
]
=
posSpan
{
s
.
Pos
(),
s
.
Pos
()
+
1
}
pos
[
i
]
=
posSpan
{
s
.
Pos
(),
s
.
End
()}
}
// Identify comments in this range.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment