merge DocComment and PlainComment
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
11
comment/comments.go
Normal 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...)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user