Skip to content
Permalink
Browse files

generated: deprecate package in favor of moved copy

This package has been moved to a new home. Its new import path
is dmitri.shuralyov.com/go/generated. Deprecate this old copy
in favor of the new one.

Replace the implementation with a forwarding stub.

Updates golang/go#28089
  • Loading branch information...
dmitshur committed Jul 4, 2019
1 parent 6713ea5 commit 7189cc372560f641a5c041d2b199d9b0a41293c4
@@ -11,13 +11,15 @@
// primitives and allocating less. That can be explored later. A lot of the time
// is spent on reading the entire file without being able to stop early,
// since the specification allows the comment to appear anywhere in the file.
//
// Deprecated: This package has moved to dmitri.shuralyov.com/go/generated.
// Use that package instead.
package generated

import (
"bufio"
"bytes"
"io"
"os"

"dmitri.shuralyov.com/go/generated"
)

// Parse parses the source code of a single Go source file
@@ -36,45 +38,11 @@ import (
//
// The text may appear anywhere in the file.
func Parse(src io.Reader) (hasGeneratedComment bool, err error) {
br := bufio.NewReader(src)
for {
s, err := br.ReadBytes('\n')
if err == io.EOF {
return containsComment(s), nil
} else if err != nil {
return false, err
}
if len(s) >= 2 && s[len(s)-2] == '\r' {
s = s[:len(s)-2] // Trim "\r\n".
} else {
s = s[:len(s)-1] // Trim "\n".
}
if containsComment(s) {
return true, nil
}
}
}

// containsComment reports whether a line of Go source code s (without newline character)
// contains the generated comment.
func containsComment(s []byte) bool {
return len(s) >= len(prefix)+len(suffix) &&
bytes.HasPrefix(s, prefix) &&
bytes.HasSuffix(s, suffix)
return generated.Parse(src)
}

var (
prefix = []byte("// Code generated ")
suffix = []byte(" DO NOT EDIT.")
)

// ParseFile opens the file specified by filename and uses Parse to parse it.
// If the source couldn't be read, the error indicates the specific failure.
func ParseFile(filename string) (hasGeneratedComment bool, err error) {
f, err := os.Open(filename)
if err != nil {
return false, err
}
defer f.Close()
return Parse(f)
return generated.ParseFile(filename)
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 7189cc3

Please sign in to comment.
You can’t perform that action at this time.