type (
// The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.
Spec interface {
+ Node;
specNode();
};
)
+// Pos() implementations for spec nodes.
+//
+func (s *ImportSpec) Pos() token.Position {
+ if s.Name != nil {
+ return s.Name.Pos();
+ }
+ return s.Path[0].Pos();
+}
+
+func (s *ValueSpec) Pos() token.Position {
+ return s.Names[0].Pos();
+}
+func (s *TypeSpec) Pos() token.Position {
+ return s.Name.Pos();
+}
+
+
// specNode() ensures that only spec nodes can be
// assigned to a Spec.
//
if len(list) == 1 {
sep = blank;
}
+ var ml bool;
for i, f := range list {
- var ml bool;
+ if i > 0 {
+ p.linebreak(f.Pos().Line, 1, 2, ignore, ml);
+ }
+ ml = false;
extraTabs := 0;
p.leadComment(f.Doc);
if len(f.Names) > 0 {
}
p.lineComment(f.Comment);
}
- if i+1 < len(list) {
- p.linebreak(list[i+1].Pos().Line, 1, 2, ignore, ml);
- } else if isIncomplete {
- p.print(formfeed);
- }
}
if isIncomplete {
+ if len(list) > 0 {
+ p.print(formfeed);
+ }
// TODO(gri): this needs to be styled like normal comments
p.print("// contains unexported fields");
}
} else { // interface
+ var ml bool;
for i, f := range list {
- var ml bool;
+ if i > 0 {
+ p.linebreak(f.Pos().Line, 1, 2, ignore, ml);
+ }
+ ml = false;
p.leadComment(f.Doc);
if ftyp, isFtyp := f.Type.(*ast.FuncType); isFtyp {
// method
}
p.print(token.SEMICOLON);
p.lineComment(f.Comment);
- if i+1 < len(list) {
- p.linebreak(list[i+1].Pos().Line, 1, 2, ignore, ml);
- } else if isIncomplete {
- p.print(formfeed);
- }
}
if isIncomplete {
+ if len(list) > 0 {
+ p.print(formfeed);
+ }
// TODO(gri): this needs to be styled like normal comments
p.print("// contains unexported methods");
}
var ml bool;
for i, s := range d.Specs {
if i > 0 {
- if ml {
- p.print(formfeed);
- } else {
- p.print(newline);
- }
+ p.linebreak(s.Pos().Line, 1, 2, ignore, ml);
}
ml = false;
p.spec(s, len(d.Specs), inGroup, &ml);