4#ifndef QMLDOMATTACHEDINFO_P_H
5#define QMLDOMATTACHEDINFO_P_H
34template<
typename TreePtr>
42 AttachedInfoLookupResult<std::shared_ptr<T>>
as()
const
44 AttachedInfoLookupResult<std::shared_ptr<T>>
res;
45 res.AttachedInfoLookupResultBase::operator=(*this);
63 DomType kind()
const override {
return kindValue; }
69 return std::static_pointer_cast<AttachedInfo>(doCopy(self));
77 : m_path(
p), m_parent(parent)
82 static Ptr ensure(
const Ptr &self,
const Path &
path, PathType pType = PathType::Relative);
83 static Ptr find(
const Ptr &self,
const Path &
p, PathType pType = PathType::Relative);
84 static AttachedInfoLookupResult<Ptr> findAttachedInfo(
const DomItem &
item,
88 return findAttachedInfo(
item, fieldName).foundTree;
94 const Path relative = (pType == PathType::Canonical) ?
p.
mid(m_path.length()) :
p;
95 Path resPath = self.canonicalPath();
96 for (
const Path &pEl : relative) {
97 resPath = resPath.field(Fields::subItems).key(pEl.toString());
99 return self.copy(resPtr, resPath);
106 return itemAtPath(self,
p, pType).
field(Fields::infoItem);
110 PathType pType = PathType::Relative)
113 const Path relative = (pType == PathType::Canonical) ?
p.
mid(m_path.length()) :
p;
114 Path resPath = self.canonicalPath();
115 for (
const Path &pEl : relative) {
116 resPath = resPath.field(Fields::subItems).key(pEl.toString());
124 PathType pType = PathType::Relative)
126 return ensureItemAtPath(self,
p, pType).
field(Fields::infoItem);
144template<
typename Info>
148 constexpr static DomType kindValue = DomType::AttachedInfo;
149 using Ptr = std::shared_ptr<AttachedInfoT>;
157 auto end =
o.m_subItems.end();
158 auto i =
o.m_subItems.begin();
160 m_subItems.insert(
i.key(),
Ptr(
161 new AttachedInfoT(*std::static_pointer_cast<AttachedInfoT>(
i.value()).get())));
171 return std::static_pointer_cast<AttachedInfoT>(AttachedInfo::ensure(self,
path, pType));
176 return std::static_pointer_cast<AttachedInfoT>(AttachedInfo::find(self,
p, pType));
182 return AttachedInfo::findAttachedInfo(
item, fieldName).template as<AttachedInfoT>();
186 return std::static_pointer_cast<AttachedInfoT>(AttachedInfo::treePtr(
item, fieldName));
193 if (visitor(pNow,
base)) {
194 auto it =
base->m_subItems.cbegin();
195 auto end =
base->m_subItems.cend();
197 if (!visitTree(std::static_pointer_cast<AttachedInfoT>(
it.value()), visitor, pNow))
211 return Ptr(
new AttachedInfoT(std::static_pointer_cast<AttachedInfoT>(parent),
p));
218 return std::static_pointer_cast<AttachedInfoT>(doCopy(self));
221 Ptr parent()
const {
return std::static_pointer_cast<AttachedInfoT>(AttachedInfo::parent()); }
229 for (
auto *
it =
this;
it;
it =
it->parent().
get()) {
247 using Tree = std::shared_ptr<AttachedInfoT<FileLocations>>;
248 constexpr static DomType kindValue = DomType::FileLocations;
252 static Tree createTree(
const Path &basePath);
253 static Tree ensure(
const Tree &
base,
const Path &basePath,
262 static AttachedInfoLookupResult<Tree> findAttachedInfo(
const DomItem &
item);
266 static void updateFullLocation(
const Tree &fLoc,
SourceLocation loc);
275 QMap<FileLocationRegion, SourceLocation>
regions;
284 using Tree = std::shared_ptr<AttachedInfoT<UpdatedScriptExpression>>;
285 constexpr static DomType kindValue = DomType::UpdatedScriptExpression;
289 static Tree createTree(
const Path &basePath);
293 static AttachedInfoLookupResult<Tree>
296 static Tree treePtr(
const DomItem &);
300 static bool visitTree(
304 std::shared_ptr<ScriptExpression>
expr;
AttachedInfoLookupResult< std::shared_ptr< T > > as() const
static Ptr createTree(const Path &p=Path())
AttachedInfo::Ptr instantiate(const AttachedInfo::Ptr &parent, const Path &p=Path()) const override
static bool visitTree(const Ptr &base, function_ref< bool(const Path &, const Ptr &)> visitor, const Path &basePath=Path())
static Ptr find(const Ptr &self, const Path &p, PathType pType=PathType::Relative)
std::shared_ptr< AttachedInfoT > Ptr
Ptr makeCopy(const DomItem &self) const
DomItem infoItem(const DomItem &self) const override
static Ptr ensure(const Ptr &self, const Path &path, PathType pType=PathType::Relative)
const Info & info() const
AttachedInfoT(const Ptr &parent=nullptr, const Path &p=Path())
std::shared_ptr< OwningItem > doCopy(const DomItem &) const override
static AttachedInfoLookupResult< Ptr > findAttachedInfo(const DomItem &item, QStringView fieldName)
QString canonicalPathForTesting() const
static Ptr treePtr(const DomItem &item, QStringView fieldName)
AttachedInfoT(const AttachedInfoT &o)
Attached info creates a tree to attach extra info to DomItems.
Path canonicalPath(const DomItem &self) const override
static Ptr treePtr(const DomItem &item, QStringView fieldName)
virtual DomItem infoItem(const DomItem &self) const =0
void setSubItems(QMap< Path, Ptr > v)
void setPath(const Path &p)
AttachedInfo::Ptr makeCopy(const DomItem &self) const
DomItem infoAtPath(const DomItem &self, const Path &p, PathType pType=PathType::Relative) const
virtual AttachedInfo::Ptr instantiate(const AttachedInfo::Ptr &parent, const Path &p=Path()) const =0
QMap< Path, Ptr > m_subItems
MutableDomItem ensureItemAtPath(MutableDomItem &self, const Path &p, PathType pType=PathType::Relative)
MutableDomItem ensureInfoAtPath(MutableDomItem &self, const Path &p, PathType pType=PathType::Relative)
DomItem itemAtPath(const DomItem &self, const Path &p, PathType pType=PathType::Relative) const
std::shared_ptr< AttachedInfo > Ptr
std::weak_ptr< AttachedInfo > m_parent
QMap< Path, Ptr > subItems() const
AttachedInfo(const Ptr &parent=nullptr, const Path &p=Path())
DomItem field(QStringView name) const
Represents and maintains a mapping between elements and their location in a file.
QMap< FileLocationRegion, QList< SourceLocation > > preCommentLocations
static Tree find(const Tree &self, const Path &p, AttachedInfo::PathType pType=AttachedInfo::PathType::Relative)
QMap< FileLocationRegion, SourceLocation > regions
SourceLocation fullRegion
std::shared_ptr< AttachedInfoT< FileLocations > > Tree
QMap< FileLocationRegion, QList< SourceLocation > > postCommentLocations
MutableDomItem field(QStringView name)
Path path(const Path &toAdd, bool avoidToAddAsBase=false) const
Path mid(int offset, int length) const
std::shared_ptr< AttachedInfoT< UpdatedScriptExpression > > Tree
std::shared_ptr< ScriptExpression > expr
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & prepend(QChar c)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static QDBusError::ErrorType get(const char *name)
GLsizei const GLfloat * v
[13]
GLsizei const GLchar *const * path
QQmlJS::Dom::DomItem DomItem