14
15
16
17
18
19
20
24
26
27
28
29
30
31
32
33
34
38 cont = cont && self.invokeVisitorOnLazyField(visitor,
Fields::fullRegion, [
this]() {
39 return sourceLocationToQCborValue(fullRegion);
41 cont = cont && visitor(
Fields::regions, [
this, &self]() ->
DomItem {
43 auto map = Map::fromFileRegionMap(pathFromOwner, regions);
56 Path relative = basePath;
58 for (
const auto &p : std::as_const(relative)) {
59 res = res->insertOrReturnChildAt(p);
67 for (
const Path &component : p) {
70 res = res->subItems().value(component);
75bool visitTree(
const Tree &base, function_ref<
bool(
const Path &,
const Tree &)> visitor,
80 if (!visitor(pNow, base)) {
83 for (
const auto &childNode : base->subItems()) {
84 if (!visitTree(childNode, visitor, pNow))
94 for (
auto *it = base.get(); it; it = it->parent().get()) {
95 result.prepend(it->path().toString());
101
102
103
121 if (Node::Ptr fLocPtr = fLoc.ownerAs<Node>())
122 return find(fLocPtr, p);
129 if (loc != SourceLocation()) {
132 SourceLocation &l = p->info().fullRegion;
133 if (loc.begin() < l.begin() || loc.end() > l.end()) {
135 p->info().regions[MainRegion] = l;
148void addRegion(
const Tree &fLoc, FileLocationRegion region, SourceLocation loc)
151 fLoc->info().regions[region] = loc;
152 updateFullLocation(fLoc, loc);
158 const auto ®ions = fLoc->info().regions;
159 if (
auto it = regions.constFind(region); it != regions.constEnd() && it->isValid()) {
163 if (region == MainRegion)
164 return fLoc->info().fullRegion;
166 return SourceLocation{};
170
171
172
173
174
175
176
177
178
179
180
181
182
186 return std::shared_ptr<Node>(
new Node(parent, p));
192 if (
const Ptr p = parent()) {
193 cont = cont && visitor(
Fields::parent, [&self, &p]() {
194 return self.copy(p, self.m_ownerPath.dropTail(2), p.get());
197 cont = cont && self.invokeVisitorOnLazyField(visitor,
Fields::path, [
this]() {
198 return path().toString();
200 cont = cont && visitor(
Fields::subItems, [
this, &self]() {
202 QMap<QString, Path> byName;
203 for (
auto it = m_subItems.keyBegin(), end = m_subItems.keyEnd(); it != end; ++it)
204 byName.insert(it->toString(), *it);
205 return self.subMapItem(Map(
206 Path::fromField(Fields::subItems),
207 [
this, byName](
const DomItem &map,
const QString &name) {
208 auto it = byName.find(name);
209 if (it == byName.end())
211 return map.copy(m_subItems.value(*it),
212 map.canonicalPath().withKey(name));
214 [byName](
const DomItem &) {
215 return QSet<QString>(byName.keyBegin(), byName.keyEnd());
217 QLatin1String(
"Node")));
219 cont = cont && visitor(
Fields::infoItem, [&self,
this]() {
220 return self.wrap(Fields::infoItem, m_info);
227 if (Node::Ptr subEl = m_subItems.value(path)) {
230 return m_subItems.insert(path, Node::instantiate(shared_from_this(), path)).value();
235 return std::shared_ptr<Node>(
new Node(*
this));
A value type that references any element of the Dom.
DomItem container() const
DomItem field(FieldName name) 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.
Represents an immutable JsonPath like path in the Qml code model (from a DomItem to another DomItem).
Path withField(FieldName name) const
Path withPath(const Path &toAdd) const
Returns a copy of this with toAdd appended to it.
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
Combined button and popup list for selecting options.
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor) const