14
15
16
17
18
19
20
24
26
27
28
29
30
31
32
33
34
38 cont = cont && self.dvValueLazyField(visitor, Fields::fullRegion, [
this]() {
39 return sourceLocationToQCborValue(fullRegion);
42 && self.dvItemField(
std::move(visitor), Fields::regions, [
this, &self]() ->
DomItem {
44 auto map = Map::fromFileRegionMap(pathFromOwner, regions);
57 Path relative = basePath;
59 for (
const auto &p : std::as_const(relative)) {
60 res = res->insertOrReturnChildAt(p);
72 res = res->subItems().value(rest
.head());
78bool visitTree(
const Tree &base, function_ref<
bool(
const Path &,
const Tree &)> visitor,
82 Path pNow = basePath.withPath(base->path());
83 if (!visitor(pNow, base)) {
86 for (
const auto &childNode : base->subItems()) {
87 if (!visitTree(childNode, visitor, pNow))
97 for (
auto *it = base.get(); it; it = it->parent().get()) {
98 result.prepend(it->path().toString());
104
105
106
110 DomItem fLoc = item.field(Fields::fileLocationsTree);
116 fLoc = o.field(Fields::fileLocationsTree);
121 fLoc = o.field(Fields::fileLocationsTree);
124 if (Node::Ptr fLocPtr = fLoc.ownerAs<Node>())
125 return find(fLocPtr, p);
132 if (loc != SourceLocation()) {
135 SourceLocation &l = p->info().fullRegion;
136 if (loc.begin() < l.begin() || loc.end() > l.end()) {
138 p->info().regions[MainRegion] = l;
151void addRegion(
const Tree &fLoc, FileLocationRegion region, SourceLocation loc)
154 fLoc->info().regions[region] = loc;
155 updateFullLocation(fLoc, loc);
161 const auto ®ions = fLoc->info().regions;
162 if (
auto it = regions.constFind(region); it != regions.constEnd() && it->isValid()) {
166 if (region == MainRegion)
167 return fLoc->info().fullRegion;
169 return SourceLocation{};
173
174
175
176
177
178
179
180
181
182
183
184
185
189 return std::shared_ptr<Node>(
new Node(parent, p));
195 if (
const Ptr p = parent()) {
196 cont = cont && self.dvItemField(visitor, Fields::parent, [&self, &p]() {
197 return self.copy(p, self.m_ownerPath.dropTail(2), p.get());
201 && self.dvValueLazyField(visitor, Fields::path, [
this]() {
return path().toString(); });
202 cont = cont && self.dvItemField(visitor, Fields::subItems, [
this, &self]() {
203 return self.subMapItem(Map(
204 Path::fromField(Fields::subItems),
205 [
this](
const DomItem &map,
const QString &key) {
206 Path p = Path::fromString(key);
207 return map.copy(m_subItems.value(p), map.canonicalPath().withKey(key));
209 [
this](
const DomItem &) {
211 for (
const auto &p : m_subItems.keys())
212 res.insert(p.toString());
215 QLatin1String(
"Node")));
217 cont = cont && self.dvItemField(
std::move(visitor), Fields::infoItem, [&self,
this]() {
218 return self.wrapField(Fields::infoItem, m_info);
225 if (Node::Ptr subEl = m_subItems.value(path)) {
228 return m_subItems.insert(path, Node::instantiate(shared_from_this(), path)).value();
233 return std::shared_ptr<Node>(
new Node(*
this));
A value type that references any element of the Dom.
DomItem container() const
Path canonicalPath() const
DomItem subMapItem(const Map &map) const
DomItem owner() const
The owner of an element, for an qmlObject this is the containing qml file.
Path pathFromOwner() const
Represents a Node of FileLocations tree.
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override
std::shared_ptr< OwningItem > doCopy(const DomItem &) const override
Ptr insertOrReturnChildAt(const Path &path)
std::shared_ptr< Node > Ptr
static Ptr instantiate(const Ptr &parent=nullptr, const Path &p=Path())
A DomItem that owns other DomItems and is managed through a shared pointer.
Path withPath(const Path &toAdd, bool avoidToAddAsBase=false) const
Returns a copy of this with toAdd appended to it.
Path dropFront(int n=1) const
Provides entities to maintain mappings between elements and their location in a file.
void addRegion(const Tree &fLoc, FileLocationRegion region, SourceLocation loc)
Tree treeOf(const DomItem &)
Tree createTree(const Path &basePath)
QString canonicalPathForTesting(const Tree &base)
QQmlJS::SourceLocation region(const Tree &fLoc, FileLocationRegion region)
bool visitTree(const Tree &base, function_ref< bool(const Path &, const Tree &)> visitor, const Path &basePath=Path())
Tree ensure(const Tree &base, const Path &basePath)
static void updateFullLocation(const Tree &fLoc, SourceLocation loc)
Tree find(const Tree &self, const Path &p)
std::shared_ptr< Node > Tree
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const