15#include <QtQmlCompiler/private/qqmlsasourcelocation_p.h>
69 return d->constBegin();
74 return m_bindings.constBegin();
88 return m_bindings.constEnd();
112 d_func()->m_binding =
other.d_func()->m_binding;
113 d_func()->q_ptr =
this;
122 d_func()->m_binding = std::move(
other.d_func()->m_binding);
123 d_func()->q_ptr =
this;
129bool Binding::operatorEqualsImpl(
const Binding &lhs,
const Binding &rhs)
131 return lhs.d_func()->m_binding == rhs.d_func()->m_binding;
142 saBinding.d_func()->m_binding =
binding;
148 return binding.d_func()->m_binding;
153 return binding.d_func()->m_binding;
254 return QQmlJSMetaPropertyBinding::isLiteralBinding(bindingType);
272 return d->constBegin();
277 return m_methods.constBegin();
286 return d->constEnd();
290 return m_methods.constEnd();
348 d_func()->m_method =
other.d_func()->m_method;
349 d_func()->q_ptr =
this;
358 d_func()->m_method = std::move(
other.d_func()->m_method);
359 d_func()->q_ptr =
this;
371 return d->methodName();
381 return d->methodType();
390 return d->sourceLocation();
393bool Method::operatorEqualsImpl(
const Method &lhs,
const Method &rhs)
395 return lhs.d_func()->m_method == rhs.d_func()->m_method;
401 auto &wrappedMethod = saMethod.d_func()->m_method;
402 wrappedMethod = jsMethod;
409 QMultiHash<QString, QQmlSA::Method> saMethods;
410 for (
const auto &[
key,
value] :
hash.asKeyValueRange()) {
415 methods.d_func()->m_methods = std::move(saMethods);
421 return method.d_func()->m_method;
466 return property.d_func()->m_property;
472 auto &wrappedProperty = saProperty.d_func()->m_property;
499 d_func()->m_property =
other.d_func()->m_property;
500 d_func()->q_ptr =
this;
509 d_func()->m_property = std::move(
other.d_func()->m_property);
510 d_func()->q_ptr =
this;
522 return d->typeName();
534 return d->isReadonly();
546 return lhs.d_func()->m_property == rhs.d_func()->m_property;
620bool Element::isNull()
const
653bool Element::hasProperty(
const QString &propertyName)
const
662bool Element::hasOwnProperty(
const QString &propertyName)
const
680bool Element::isPropertyRequired(
const QString &propertyName)
const
747bool Element::hasOwnPropertyBindings(
const QString &propertyName)
const
774QList<Binding> Element::propertyBindings(
const QString &propertyName)
const
778 QList<Binding> saBindings;
779 for (
const auto &jsBinding : bindings) {
788 QMultiHash<QString, QQmlSA::Binding> saBindings;
789 for (
const auto &[
key,
value] :
hash.asKeyValueRange()) {
794 bindings.d_func()->m_bindings = std::move(saBindings);
802 QMultiHash<QString, QQmlSA::Binding> saBindings;
803 for (
auto it = iterators.first;
it != iterators.second; ++
it) {
808 bindings.d_func()->m_bindings = std::move(saBindings);
812Element::operator bool()
const
817bool Element::operator!()
const
832bool Element::operatorEqualsImpl(
const Element &lhs,
const Element &rhs)
896 ->log(diagnostic.toString(),
id,
910 ->log(diagnostic.toString(),
id,
953 const auto module = typeImporter->importModule(moduleName.toString());
954 const auto scope =
module.type(typeName.toString()).scope;
969 auto typeNameString =
typeName.toString();
971 auto scope = typeImporter->builtinInternalNames().type(typeNameString).scope;
974 auto builtins = typeImporter->importBuiltins();
975 scope = builtins.type(typeNameString).scope;
1008 ->addressableScopes()
1020 ->addressableScopes()
1044PassManager::PassManager() =
default;
1045PassManager::~PassManager() =
default;
1053 d->registerElementPass(std::move(pass));
1075 return u
"$INVALID$"_s;
1085 name += u
'@' + filePath;
1124 return d->registerPropertyPass(pass, moduleName,
typeName, propertyName, allowInheritance);
1132 qWarning() <<
"Both the moduleName and the typeName must be specified "
1133 "for the pass to be registered for a specific element.";
1139 auto module = typeImporter->importModule(moduleName.toString());
1142 if (element.isNull())
1150 std::move(pass), allowInheritance };
1157 const QString prefix,
bool isAttached)
1159 const Element ¤tScope = scope.
isNull() ? element : scope;
1161 for (
const auto &binding : ownBindings) {
1162 switch (binding.bindingType()) {
1165 prefix + binding.propertyName() + u
'.');
1169 prefix + binding.propertyName() + u
'.',
true);
1173 BindingInfo{ prefix + binding.propertyName(), binding,
1174 currentScope, isAttached } });
1203 QList<Element> runStack;
1204 runStack.push_back(root);
1205 while (!runStack.isEmpty()) {
1206 auto element = runStack.takeLast();
1209 if (elementPass->shouldRun(element))
1210 elementPass->run(element);
1224 pass->onWrite(element, propertyName,
value, writeScope,
location);
1231 pass->onRead(element, propertyName, readScope,
location);
1246 const QString &propertyName =
info->second.fullPropertyName;
1249 pass->onBinding(element, propertyName, binding, bindingScope,
value);
1255 pass->onBinding(element, propertyName, binding, bindingScope,
value);
1289 return manager.d_func()->m_visitor;
1294 return manager.d_func()->m_typeResolver;
1310 QSet<PropertyPass *> passes;
1315 if (pass.first == pass.second)
1318 for (
auto it = pass.first;
it != pass.second;
it++) {
1319 if (
typeName != typeNames.constFirst() && !
it->second.allowInheritance)
1322 ||
it->second.properties.
contains(propertyName)) {
1323 passes.insert(
it->second.pass.get());
1333 if (
auto bindings = element.
propertyBindings(u
"objectName"_s); !bindings.isEmpty()) {
1338 + u
" elements to property "_s + defPropName,
1512 + u
"' property: '"_s + propertyName + u
"' value: '"_s
1513 + (
value.isNull() ? u
"NULL"_s
1515 ?
value.baseTypeName()
1517 + u
"' binding_scope: '"_s
1544 return d->m_elementPasses;
1553 return d->m_propertyPasses;
1562 return d->m_bindingsByLocation;
1619 return m_fixSuggestion.
hint();
1634 return saFixSuggestion.d_func()->m_fixSuggestion;
1639 return saFixSuggestion.d_func()->m_fixSuggestion;
1671 d_func()->m_fixSuggestion =
other.d_func()->m_fixSuggestion;
1680 d_func()->m_fixSuggestion = std::move(
other.d_func()->m_fixSuggestion);
1762 return lhs.d_func()->m_fixSuggestion == rhs.d_func()->m_fixSuggestion;
static JNINativeMethod methods[]
QString toString() const
Returns a deep copy of this string view's data as a QString.
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
QVariant property(const char *name) const
Returns the value of the object's name property.
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
void setFilename(const QString &filename)
QQmlJS::SourceLocation location() const
bool isAutoApplicable() const
QString replacement() const
QString fixDescription() const
void setHint(const QString &hint)
void setAutoApplicable(bool autoApply=true)
QQmlJSImporter * importer()
static QQmlSA::Element createQQmlSAElement(const ConstPtr &)
static const QQmlJSScope::ConstPtr & scope(const QQmlSA::Element &)
static QString prettyName(QAnyStringView name)
static constexpr qsizetype sizeofQQmlSAElement()
static QQmlJSMetaPropertyBinding binding(QQmlSA::Binding &binding)
static QQmlSA::Binding createBinding(const QQmlJSMetaPropertyBinding &)
BindingPrivate(Binding *)
QMultiHash< QString, Binding >::const_iterator constBegin() const
Returns an iterator to the beginning of the bindings.
QMultiHash< QString, Binding >::const_iterator constEnd() const
Returns an iterator to the end of the bindings.
BindingType bindingType() const
bool hasUndefinedScriptValue() const
Binding & operator=(const Binding &)
bool hasObject() const
Returns true if this binding has an objects, otherwise returns false.
Element attachingType() const
Returns the attached type if the content type of this binding is AttachedProperty,...
static bool isLiteralBinding(BindingType)
Returns true if bindingType is a literal type, and false otherwise.
QString propertyName() const
Returns the name of the property bound with this binding.
QString stringValue() const
Returns the associated string literal if the content type of this binding is StringLiteral,...
Element objectType() const
Returns the type of the associated object if the content type of this binding is Object,...
QQmlSA::SourceLocation sourceLocation() const
Returns the location in the QML code where this binding is defined.
ScriptBindingKind scriptKind() const
Returns the kind of the associated script if the content type of this binding is Script,...
double numberValue() const
Returns the associated number if the content type of this binding is NumberLiteral,...
Element groupType() const
Returns the type of the property of this binding if it is a group property, otherwise returns an inva...
BindingsPrivate(QQmlSA::Binding::Bindings *)
QMultiHash< QString, Binding >::const_iterator constBegin() const
static QQmlSA::Binding::Bindings createBindings(const QMultiHash< QString, QQmlJSMetaPropertyBinding > &)
QMultiHash< QString, Binding >::const_iterator constEnd() const
void run(const Element &element) override
Executes if shouldRun() returns true.
void onWrite(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &value, const QQmlSA::Element &writeScope, QQmlSA::SourceLocation location) override
Executes whenever a property is written to.
void onBinding(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope, const QQmlSA::Element &value) override
Executes whenever a property gets bound to a value.
DebugPropertyPass(QQmlSA::PassManager *manager)
void onRead(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &readScope, QQmlSA::SourceLocation location) override
Executes whenever a property is read.
virtual bool shouldRun(const Element &element)
Controls whether the run() function should be executed on the given element.
Element baseType() const
Returns the Element this Element derives from.
QString defaultPropertyName() const
Returns the name of the default property of this Element.
QQmlSA::SourceLocation sourceLocation() const
Returns the location in the QML code where this Element is defined.
Binding::Bindings ownPropertyBindings() const
Returns this Element's property bindings which are not defined on its base or extension objects.
QList< Binding > propertyBindings(const QString &propertyName) const
Returns this Element's property bindings that have the name propertyName.
bool isComposite() const
Returns true for objects defined from Qml, and false for objects declared from C++.
QString baseTypeName() const
Returns the name of the Element this Element derives from.
QQmlSA::SourceLocation location() const
void setHint(const QString &)
void setFileName(const QString &)
QString fixDescription() const
FixSuggestionPrivate(FixSuggestion *)
bool isAutoApplicable() const
void setAutoApplicable(bool autoApplicable=true)
QString replacement() const
static QQmlJSFixSuggestion & fixSuggestion(QQmlSA::FixSuggestion &)
FixSuggestion(const QString &fixDescription, const QQmlSA::SourceLocation &location, const QString &replacement=QString())
void setHint(const QString &)
Sets hint as the hint for this fix suggestion.
QString fileName() const
Returns the name of the file where this fix suggestion applies.
FixSuggestion & operator=(const FixSuggestion &)
void setFileName(const QString &)
Sets fileName as the name of the file where this fix suggestion applies.
QString hint() const
Returns the hint for this fix suggestion.
QString replacement() const
Returns the fix that will replace the problematic source code.
QString fixDescription() const
Returns the description of the fix.
QQmlSA::SourceLocation location() const
Returns the location where the fix would be applied.
bool isAutoApplicable() const
Returns whether this suggested fix can be applied automatically.
void setAutoApplicable(bool autoApplicable=true)
Sets autoApplicable to determine whether this suggested fix can be applied automatically.
GenericPassPrivate(GenericPass *interface, PassManager *manager)
void emitWarning(QAnyStringView diagnostic, LoggerWarningId id)
Emits a warning message diagnostic about an issue of type id.
Element resolveLiteralType(const Binding &binding)
Returns the element representing the type of literal in binding.
Element resolveBuiltinType(QAnyStringView typeName) const
Returns the type of the built-in type identified by typeName.
Element resolveAttached(QAnyStringView moduleName, QAnyStringView typeName)
Returns the attached type of typeName defined in module moduleName.
QString resolveElementToId(const Element &element, const Element &context)
Returns the id of element in a given context.
Element resolveTypeInFileScope(QAnyStringView typeName)
Returns the type corresponding to typeName inside the currently analysed file.
QString sourceCode(QQmlSA::SourceLocation location)
Returns the source code located within location.
Element resolveAttachedInFileScope(QAnyStringView typeName)
Returns the attached type corresponding to typeName used inside the currently analysed file.
Element resolveIdToElement(QAnyStringView id, const Element &context)
Returns the element in context that has id id.
GenericPass(PassManager *manager)
Creates a generic pass.
Element resolveType(QAnyStringView moduleName, QAnyStringView typeName)
Returns the type of typeName defined in module moduleName.
QQmlSA::SourceLocation sourceLocation() const
static QQmlSA::Method createMethod(const QQmlJSMetaMethod &)
MethodType methodType() const
static QQmlJSMetaMethod method(const QQmlSA::Method &)
QString methodName() const
QMultiHash< QString, Method >::const_iterator constBegin() const
Returns an iterator to the beginning of the methods.
QMultiHash< QString, Method >::const_iterator constEnd() const
Returns an iterator to the end of the methods.
MethodType methodType() const
Returns the type of this method.
QQmlSA::SourceLocation sourceLocation() const
Returns the location in the QML code where this method is defined.
Method & operator=(const Method &)
QString methodName() const
Returns the name of the this method.
static QQmlSA::Method::Methods createMethods(const QMultiHash< QString, QQmlJSMetaMethod > &)
QMultiHash< QString, Method >::const_iterator constEnd() const
MethodsPrivate(QQmlSA::Method::Methods *)
QMultiHash< QString, Method >::const_iterator constBegin() const
void analyze(const Element &root)
void registerElementPass(std::unique_ptr< ElementPass > pass)
PassManager::registerElementPass registers ElementPass with the pass manager.
void addBindingSourceLocations(const QQmlSA::Element &element, const QQmlSA::Element &scope=QQmlSA::Element(), const QString prefix=QString(), bool isAttached=false)
QQmlJSImportVisitor * m_visitor
static QQmlJSTypeResolver * resolver(const QQmlSA::PassManager &)
void analyzeRead(const QQmlSA::Element &element, QString propertyName, const QQmlSA::Element &readScope, QQmlSA::SourceLocation location)
QSet< PropertyPass * > findPropertyUsePasses(const QQmlSA::Element &element, const QString &propertyName)
std::multimap< QString, PropertyPassInfo > m_propertyPasses
void analyzeBinding(const QQmlSA::Element &element, const QQmlSA::Element &value, QQmlSA::SourceLocation location)
std::vector< std::shared_ptr< ElementPass > > m_elementPasses
void analyzeWrite(const QQmlSA::Element &element, QString propertyName, const QQmlSA::Element &value, const QQmlSA::Element &writeScope, QQmlSA::SourceLocation location)
std::unordered_map< quint32, BindingInfo > m_bindingsByLocation
static QQmlJSImportVisitor * visitor(const QQmlSA::PassManager &)
bool registerPropertyPass(std::shared_ptr< PropertyPass > pass, QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName=QAnyStringView(), bool allowInheritance=true)
void analyze(const Element &root)
Runs the element passes over root and all its children.
std::multimap< QString, PropertyPassInfo > propertyPasses() const
Returns the list of property passes.
bool isCategoryEnabled(LoggerWarningId category) const
Returns true if warnings of category are enabled, false otherwise.
bool registerPropertyPass(std::shared_ptr< PropertyPass > pass, QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName=QAnyStringView(), bool allowInheritance=true)
Registers a static analysis pass for properties.
void registerElementPass(std::unique_ptr< ElementPass > pass)
Registers a static analysis pass to be run on all elements.
std::unordered_map< quint32, BindingInfo > bindingsByLocation() const
Returns bindings by their source location.
std::vector< std::shared_ptr< ElementPass > > elementPasses() const
Returns the list of element passes.
bool hasImportedModule(QAnyStringView name) const
Returns true if the module named module has been imported by the QML to be analyzed,...
PropertyPass(PassManager *manager)
virtual void onWrite(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &value, const QQmlSA::Element &writeScope, QQmlSA::SourceLocation location)
Executes whenever a property is written to.
virtual void onRead(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &readScope, QQmlSA::SourceLocation location)
Executes whenever a property is read.
virtual void onBinding(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope, const QQmlSA::Element &value)
Executes whenever a property gets bound to a value.
static QQmlSA::Property createProperty(const QQmlJSMetaProperty &)
static QQmlJSMetaProperty property(const QQmlSA::Property &property)
QQmlSA::Element type() const
Returns the type that this property was defined with.
PropertyPrivate(Property *)
bool isReadonly() const
Returns whether this property is readonly.
QString typeName() const
Returns the name of the type of this property.
QQmlSA::Element type() const
Property & operator=(const Property &)
static const QQmlJS::SourceLocation & sourceLocation(const QQmlSA::SourceLocation &sourceLocation)
static QQmlSA::SourceLocation createQQmlSASourceLocation(const QQmlJS::SourceLocation &jsLocation)
bool contains(const T &value) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
QString & insert(qsizetype i, QChar c)
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const QLoggingCategory & category()
[1]
QHash< int, QWidget * > hash
[35multi]
QSet< QString >::iterator it
static QQmlJS::ConstPtrWrapperIterator childScopesBegin(const Element &element)
static QQmlJS::ConstPtrWrapperIterator childScopesEnd(const Element &element)
static QString lookupName(const QQmlSA::Element &element, LookupMode mode=Lookup)
Combined button and popup list for selecting options.
std::pair< T1, T2 > QPair
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char * interface
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
static QString methodName(const QDBusIntrospection::Method &method)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
GLenum GLuint GLintptr offset
static QString internalName(const QQmlJSScope::ConstPtr &scope)
const QQmlSA::LoggerWarningId qmlPlugin
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QNetworkAccessManager manager
char * toString(const MyType &t)
[31]
static bool searchBaseAndExtensionTypes(QQmlJSScopePtr type, const Action &check)