Replace OptionalPath.valid flag by checking the path itself.
Test: m nothing Change-Id: Iaf7655e4676d2beeb7c7ac3bcba11a7dad4a01a3
This commit is contained in:
@@ -263,27 +263,23 @@ func ResPathWithName(ctx ModuleOutPathContext, p Path, name string) ModuleResPat
|
|||||||
|
|
||||||
// OptionalPath is a container that may or may not contain a valid Path.
|
// OptionalPath is a container that may or may not contain a valid Path.
|
||||||
type OptionalPath struct {
|
type OptionalPath struct {
|
||||||
valid bool
|
path Path // nil if invalid.
|
||||||
path Path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionalPathForPath returns an OptionalPath containing the path.
|
// OptionalPathForPath returns an OptionalPath containing the path.
|
||||||
func OptionalPathForPath(path Path) OptionalPath {
|
func OptionalPathForPath(path Path) OptionalPath {
|
||||||
if path == nil {
|
return OptionalPath{path: path}
|
||||||
return OptionalPath{}
|
|
||||||
}
|
|
||||||
return OptionalPath{valid: true, path: path}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid returns whether there is a valid path
|
// Valid returns whether there is a valid path
|
||||||
func (p OptionalPath) Valid() bool {
|
func (p OptionalPath) Valid() bool {
|
||||||
return p.valid
|
return p.path != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path returns the Path embedded in this OptionalPath. You must be sure that
|
// Path returns the Path embedded in this OptionalPath. You must be sure that
|
||||||
// there is a valid path, since this method will panic if there is not.
|
// there is a valid path, since this method will panic if there is not.
|
||||||
func (p OptionalPath) Path() Path {
|
func (p OptionalPath) Path() Path {
|
||||||
if !p.valid {
|
if p.path == nil {
|
||||||
panic("Requesting an invalid path")
|
panic("Requesting an invalid path")
|
||||||
}
|
}
|
||||||
return p.path
|
return p.path
|
||||||
@@ -294,7 +290,7 @@ func (p OptionalPath) Path() Path {
|
|||||||
// It returns nil if this is not valid, or a single length slice containing the Path embedded in
|
// It returns nil if this is not valid, or a single length slice containing the Path embedded in
|
||||||
// this OptionalPath.
|
// this OptionalPath.
|
||||||
func (p OptionalPath) AsPaths() Paths {
|
func (p OptionalPath) AsPaths() Paths {
|
||||||
if !p.valid {
|
if p.path == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return Paths{p.path}
|
return Paths{p.path}
|
||||||
@@ -303,7 +299,7 @@ func (p OptionalPath) AsPaths() Paths {
|
|||||||
// RelativeToTop returns an OptionalPath with the path that was embedded having been replaced by the
|
// RelativeToTop returns an OptionalPath with the path that was embedded having been replaced by the
|
||||||
// result of calling Path.RelativeToTop on it.
|
// result of calling Path.RelativeToTop on it.
|
||||||
func (p OptionalPath) RelativeToTop() OptionalPath {
|
func (p OptionalPath) RelativeToTop() OptionalPath {
|
||||||
if !p.valid {
|
if p.path == nil {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
p.path = p.path.RelativeToTop()
|
p.path = p.path.RelativeToTop()
|
||||||
@@ -312,7 +308,7 @@ func (p OptionalPath) RelativeToTop() OptionalPath {
|
|||||||
|
|
||||||
// String returns the string version of the Path, or "" if it isn't valid.
|
// String returns the string version of the Path, or "" if it isn't valid.
|
||||||
func (p OptionalPath) String() string {
|
func (p OptionalPath) String() string {
|
||||||
if p.valid {
|
if p.path != nil {
|
||||||
return p.path.String()
|
return p.path.String()
|
||||||
} else {
|
} else {
|
||||||
return ""
|
return ""
|
||||||
|
Reference in New Issue
Block a user