/
origin_local.go
56 lines (45 loc) · 1.37 KB
/
origin_local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package reference
import (
"github.com/hashicorp/hcl-lang/lang"
"github.com/hashicorp/hcl/v2"
)
// LocalOrigin represents a resolved reference origin (traversal)
// targeting a *local* attribute or a block within the same path
type LocalOrigin struct {
// Addr describes the resolved address of the reference
Addr lang.Address
// Range represents the range of the traversal
Range hcl.Range
// Constraints represents any traversal expression constraints
// for the attribute where the origin was found.
//
// Further matching against decoded reference targets is needed
// for >1 constraints, which is done later at runtime as
// targets and origins can be decoded at different times.
Constraints OriginConstraints
}
func (lo LocalOrigin) Copy() Origin {
return LocalOrigin{
Addr: lo.Addr.Copy(),
Range: lo.Range,
Constraints: lo.Constraints.Copy(),
}
}
func (LocalOrigin) isOriginImpl() originSigil {
return originSigil{}
}
func (lo LocalOrigin) OriginRange() hcl.Range {
return lo.Range
}
func (lo LocalOrigin) OriginConstraints() OriginConstraints {
return lo.Constraints
}
func (lo LocalOrigin) AppendConstraints(oc OriginConstraints) MatchableOrigin {
lo.Constraints = append(lo.Constraints, oc...)
return lo
}
func (lo LocalOrigin) Address() lang.Address {
return lo.Addr
}