-
-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge experimental / refactor #146
Changes from 1 commit
9b08174
8df48f9
cacf21f
bf78d02
50bbc53
5160048
65b18da
026fe4c
f4b705a
6943f9e
3caf7c3
9c959ca
5a11336
27b2fd9
67dc432
d4311c9
02901b9
e3b6fd9
97cde35
cfa4327
af25ac1
25d74c6
e925d3c
4c49716
d452dcb
867d300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package gas | ||
|
||
import ( | ||
"go/ast" | ||
"go/types" | ||
"strings" | ||
) | ||
|
||
type ImportTracker struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type ImportTracker should have comment or be unexported |
||
Imported map[string]string | ||
Aliased map[string]string | ||
InitOnly map[string]bool | ||
} | ||
|
||
func NewImportTracker() *ImportTracker { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported function NewImportTracker should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported function NewImportTracker should have comment or be unexported |
||
return &ImportTracker{ | ||
make(map[string]string), | ||
make(map[string]string), | ||
make(map[string]bool), | ||
} | ||
} | ||
|
||
func (t *ImportTracker) TrackPackages(pkgs ...*types.Package) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method ImportTracker.TrackPackages should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method ImportTracker.TrackPackages should have comment or be unexported |
||
for _, pkg := range pkgs { | ||
for _, imp := range pkg.Imports() { | ||
t.Imported[imp.Path()] = imp.Name() | ||
} | ||
} | ||
} | ||
|
||
func (t *ImportTracker) TrackImport(n ast.Node) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method ImportTracker.TrackImport should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method ImportTracker.TrackImport should have comment or be unexported |
||
if imported, ok := n.(*ast.ImportSpec); ok { | ||
path := strings.Trim(imported.Path.Value, `"`) | ||
if imported.Name != nil { | ||
if imported.Name.Name == "_" { | ||
// Initialization only import | ||
t.InitOnly[path] = true | ||
} else { | ||
// Aliased import | ||
t.Aliased[path] = imported.Name.Name | ||
} | ||
} | ||
|
||
// unsafe is not included in Package.Imports() | ||
if path == "unsafe" { | ||
t.Imported[path] = path | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type ImportTracker should have comment or be unexported