package jen

import (
	
	
	
)

// Comment adds a comment. If the provided string contains a newline, the
// comment is formatted in multiline style. If the comment string starts
// with "//" or "/*", the automatic formatting is disabled and the string is
// rendered directly.
func ( string) *Statement {
	return newStatement().Comment()
}

// Comment adds a comment. If the provided string contains a newline, the
// comment is formatted in multiline style. If the comment string starts
// with "//" or "/*", the automatic formatting is disabled and the string is
// rendered directly.
func ( *Group) ( string) *Statement {
	 := Comment()
	.items = append(.items, )
	return 
}

// Comment adds a comment. If the provided string contains a newline, the
// comment is formatted in multiline style. If the comment string starts
// with "//" or "/*", the automatic formatting is disabled and the string is
// rendered directly.
func ( *Statement) ( string) *Statement {
	 := comment{
		comment: ,
	}
	* = append(*, )
	return 
}

// Commentf adds a comment, using a format string and a list of parameters. If
// the provided string contains a newline, the comment is formatted in
// multiline style. If the comment string starts with "//" or "/*", the
// automatic formatting is disabled and the string is rendered directly.
func ( string,  ...interface{}) *Statement {
	return newStatement().Commentf(, ...)
}

// Commentf adds a comment, using a format string and a list of parameters. If
// the provided string contains a newline, the comment is formatted in
// multiline style. If the comment string starts with "//" or "/*", the
// automatic formatting is disabled and the string is rendered directly.
func ( *Group) ( string,  ...interface{}) *Statement {
	 := Commentf(, ...)
	.items = append(.items, )
	return 
}

// Commentf adds a comment, using a format string and a list of parameters. If
// the provided string contains a newline, the comment is formatted in
// multiline style. If the comment string starts with "//" or "/*", the
// automatic formatting is disabled and the string is rendered directly.
func ( *Statement) ( string,  ...interface{}) *Statement {
	 := comment{
		comment: fmt.Sprintf(, ...),
	}
	* = append(*, )
	return 
}

type comment struct {
	comment string
}

func ( comment) ( *File) bool {
	return false
}

func ( comment) ( *File,  io.Writer,  *Statement) error {
	if strings.HasPrefix(.comment, "//") || strings.HasPrefix(.comment, "/*") {
		// automatic formatting disabled.
		if ,  := .Write([]byte(.comment));  != nil {
			return 
		}
		return nil
	}
	if strings.Contains(.comment, "\n") {
		if ,  := .Write([]byte("/*\n"));  != nil {
			return 
		}
	} else {
		if ,  := .Write([]byte("// "));  != nil {
			return 
		}
	}
	if ,  := .Write([]byte(.comment));  != nil {
		return 
	}
	if strings.Contains(.comment, "\n") {
		if !strings.HasSuffix(.comment, "\n") {
			if ,  := .Write([]byte("\n"));  != nil {
				return 
			}
		}
		if ,  := .Write([]byte("*/"));  != nil {
			return 
		}
	}
	return nil
}