Keep var refernce in resources

This commit is contained in:
Jian Qiu
2019-05-30 17:36:19 +08:00
parent fcc3082231
commit 7e12918f75
6 changed files with 303 additions and 34 deletions

View File

@@ -31,8 +31,9 @@ import (
// paired with a GenerationBehavior.
type Resource struct {
ifc.Kunstructured
options *types.GenArgs
refBy []resid.ResId
options *types.GenArgs
refBy []resid.ResId
refVarNames []string
}
func (r *Resource) KunstructEqual(o *Resource) bool {
@@ -59,6 +60,11 @@ func (r *Resource) DeepCopy() *Resource {
copy(refby, r.refBy)
rc.refBy = refby
}
if len(r.refVarNames) > 0 {
refVarNames := make([]string, len(r.refVarNames))
copy(refVarNames, r.refVarNames)
rc.refVarNames = refVarNames
}
return rc
}
@@ -98,6 +104,16 @@ func (r *Resource) AppendRefBy(id resid.ResId) {
r.refBy = append(r.refBy, id)
}
// GetRefVarNames returns vars that refer to current resource
func (r *Resource) GetRefVarNames() []string {
return r.refVarNames
}
// AppendRefVarName appends a name of a var into the refVar list
func (r *Resource) AppendRefVarName(variable types.Var) {
r.refVarNames = append(r.refVarNames, variable.Name)
}
// Merge performs merge with other resource.
func (r *Resource) Merge(other *Resource) {
r.Replace(other)