/
origin_path.go
56 lines (44 loc) · 1.31 KB
/
origin_path.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"
)
// PathOrigin represents a resolved reference origin
// targeting an attribute or a block in a separate path
type PathOrigin struct {
// Range represents a range of a local traversal or an attribute
Range hcl.Range
// TargetAddr describes the address of the targeted attribute or block
TargetAddr lang.Address
// TargetPath represents what Path does the origin target
TargetPath lang.Path
// Constraints represent any constraints to use when filtering
// the targets within the destination Path
Constraints OriginConstraints
}
func (po PathOrigin) Copy() Origin {
return PathOrigin{
Range: po.Range,
TargetAddr: po.TargetAddr.Copy(),
TargetPath: po.TargetPath,
Constraints: po.Constraints.Copy(),
}
}
func (PathOrigin) isOriginImpl() originSigil {
return originSigil{}
}
func (po PathOrigin) OriginRange() hcl.Range {
return po.Range
}
func (po PathOrigin) OriginConstraints() OriginConstraints {
return po.Constraints
}
func (po PathOrigin) AppendConstraints(oc OriginConstraints) MatchableOrigin {
po.Constraints = append(po.Constraints, oc...)
return po
}
func (po PathOrigin) Address() lang.Address {
return po.TargetAddr
}