package jen

import (
	
	
	
	
)

// Statement represents a simple list of code items. When rendered the items
// are separated by spaces.
type Statement []Code

func newStatement() *Statement {
	return &Statement{}
}

// Clone makes a copy of the Statement, so further tokens can be appended
// without affecting the original.
func ( *Statement) () *Statement {
	return &Statement{}
}

func ( *Statement) ( Code) Code {
	 := -1
	for ,  := range * {
		if  ==  {
			 = 
			break
		}
	}
	if  > 0 {
		return (*)[-1]
	}
	return nil
}

func ( *Statement) ( *File) bool {
	if  == nil {
		return true
	}
	for ,  := range * {
		if !.isNull() {
			return false
		}
	}
	return true
}

func ( *Statement) ( *File,  io.Writer,  *Statement) error {
	 := true
	for ,  := range * {
		if  == nil || .isNull() {
			// Null() token produces no output but also
			// no separator. Empty() token products no
			// output but adds a separator.
			continue
		}
		if ! {
			if ,  := .Write([]byte(" "));  != nil {
				return 
			}
		}
		if  := .render(, , );  != nil {
			return 
		}
		 = false
	}
	return nil
}

// Render renders the Statement to the provided writer.
func ( *Statement) ( io.Writer) error {
	return .RenderWithFile(, NewFile(""))
}

// GoString renders the Statement for testing. Any error will cause a panic.
func ( *Statement) () string {
	 := bytes.Buffer{}
	if  := .Render(&);  != nil {
		panic()
	}
	return .String()
}

// RenderWithFile renders the Statement to the provided writer, using imports from the provided file.
func ( *Statement) ( io.Writer,  *File) error {
	 := &bytes.Buffer{}
	if  := .render(, , nil);  != nil {
		return 
	}
	,  := format.Source(.Bytes())
	if  != nil {
		return fmt.Errorf("Error %s while formatting source:\n%s", , .String())
	}
	if ,  := .Write();  != nil {
		return 
	}
	return nil
}