merge DocComment and PlainComment

This commit is contained in:
z7zmey
2018-04-15 15:55:33 +03:00
parent e65ace8984
commit c2f938e55c
13 changed files with 62 additions and 92 deletions

View File

@@ -1,16 +1,17 @@
package comment
import "github.com/z7zmey/php-parser/node"
// Comment represents comment lines in the code
type Comment interface {
String() string
// Comment aggrigates information about comment /**
type Comment struct {
value string
}
// Comments a collection of comment groups assigned to nodes
type Comments map[node.Node][]Comment
// AddComments add comment group to the collection
func (c Comments) AddComments(node node.Node, comments []Comment) {
c[node] = append(c[node], comments...)
// NewComment - Comment constructor
func NewComment(value string) *Comment {
return &Comment{
value,
}
}
func (c *Comment) String() string {
return c.value
}

View File

@@ -10,9 +10,9 @@ import (
func TestComments(t *testing.T) {
n := node.NewIdentifier("test")
commentGroup := []comment.Comment{
comment.NewDocComment("/** hello world */"),
comment.NewPlainComment("// hello world"),
commentGroup := []*comment.Comment{
comment.NewComment("/** hello world */"),
comment.NewComment("// hello world"),
}
comments := comment.Comments{}

11
comment/comments.go Normal file
View File

@@ -0,0 +1,11 @@
package comment
import "github.com/z7zmey/php-parser/node"
// Comments a collection of comment groups assigned to nodes
type Comments map[node.Node][]*Comment
// AddComments add comment group to the collection
func (c Comments) AddComments(node node.Node, comments []*Comment) {
c[node] = append(c[node], comments...)
}

View File

@@ -1,17 +0,0 @@
package comment
// DocComment represents comments that start /**
type DocComment struct {
value string
}
// NewDocComment - DocComment constructor
func NewDocComment(value string) *DocComment {
return &DocComment{
value,
}
}
func (c *DocComment) String() string {
return c.value
}

View File

@@ -1,17 +0,0 @@
package comment
// PlainComment represents comments that dont start /**
type PlainComment struct {
value string
}
// NewPlainComment - PlainComment constructor
func NewPlainComment(value string) *PlainComment {
return &PlainComment{
value,
}
}
func (c *PlainComment) String() string {
return c.value
}