Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
add inline comment to non-embedded option and import
Browse files Browse the repository at this point in the history
Change-Id: I4cec0665e606eba6868319097716701502346ce5
  • Loading branch information
emicklei committed Feb 7, 2017
1 parent 1a88e9f commit 69c9f5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 3 additions & 3 deletions aligned.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type aligned struct {

var (
alignedEquals = leftAligned(" = ")
alignedShortEquals = notAligned("=")
alignedShortEquals = leftAligned("=")
alignedSpace = leftAligned(" ")
alignedComma = leftAligned(", ")
alignedEmpty = notAligned("")
alignedSemicolon = notAligned(";")
alignedEmpty = leftAligned("")
alignedSemicolon = leftAligned(";")
)

func leftAligned(src string) aligned { return aligned{src, true, true} }
Expand Down
11 changes: 10 additions & 1 deletion import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import "fmt"
type Import struct {
Filename string
Kind string // weak, public, <empty>
Comment *Comment
}

// Accept dispatches the call to the visitor.
func (i *Import) Accept(v Visitor) {
v.VisitImport(i)
}

// inlineComment is part of commentInliner.
func (i *Import) inlineComment(c *Comment) {
i.Comment = c
}

// columns returns printable source tokens
func (i *Import) columns() (cols []aligned) {
cols = append(cols, leftAligned("import "))
Expand All @@ -21,7 +27,10 @@ func (i *Import) columns() (cols []aligned) {
} else {
cols = append(cols, alignedEmpty)
}
cols = append(cols, alignedEmpty, notAligned(fmt.Sprintf("%q", i.Filename)))
cols = append(cols, alignedSpace, notAligned(fmt.Sprintf("%q", i.Filename)), alignedSemicolon)
if i.Comment != nil {
cols = append(cols, notAligned(" //"), notAligned(i.Comment.Message))
}
return
}

Expand Down
12 changes: 12 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ type Option struct {
Name string
Constant Literal
IsEmbedded bool
Comment *Comment
}

// inlineComment is part of commentInliner.
func (o *Option) inlineComment(c *Comment) {
o.Comment = c
}

// Accept dispatches the call to the visitor.
Expand All @@ -26,6 +32,12 @@ func (o *Option) columns() (cols []aligned) {
if o.IsEmbedded {
cols = append(cols, leftAligned("]"))
}
if !o.IsEmbedded {
cols = append(cols, alignedSemicolon)
if o.Comment != nil {
cols = append(cols, notAligned(" //"), notAligned(o.Comment.Message))
}
}
return
}

Expand Down

0 comments on commit 69c9f5f

Please sign in to comment.