Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQmlSA::ElementPass Class Referenceabstract

\inmodule QtQmlCompiler More...

#include <qqmlsa.h>

+ Inheritance diagram for QQmlSA::ElementPass:
+ Collaboration diagram for QQmlSA::ElementPass:

Public Member Functions

 ElementPass (PassManager *manager)
 
virtual bool shouldRun (const Element &element)
 Controls whether the run() function should be executed on the given element.
 
virtual void run (const Element &element)=0
 Executes if shouldRun() returns true.
 
- Public Member Functions inherited from QQmlSA::GenericPass
 GenericPass (PassManager *manager)
 Creates a generic pass.
 
virtual ~GenericPass ()
 
void emitWarning (QAnyStringView diagnostic, LoggerWarningId id)
 Emits a warning message diagnostic about an issue of type id.
 
void emitWarning (QAnyStringView diagnostic, LoggerWarningId id, QQmlSA::SourceLocation srcLocation)
 Emits warning message diagnostic about an issue of type id located at srcLocation.
 
void emitWarning (QAnyStringView diagnostic, LoggerWarningId id, QQmlSA::SourceLocation srcLocation, const QQmlSA::FixSuggestion &fix)
 Emits a warning message diagnostic about an issue of type id located at srcLocation and with suggested fix fix.
 
Element resolveTypeInFileScope (QAnyStringView typeName)
 Returns the type corresponding to typeName inside the currently analysed file.
 
Element resolveAttachedInFileScope (QAnyStringView typeName)
 Returns the attached type corresponding to typeName used inside the currently analysed file.
 
Element resolveType (QAnyStringView moduleName, QAnyStringView typeName)
 Returns the type of typeName defined in module moduleName.
 
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.
 
Element resolveLiteralType (const Binding &binding)
 Returns the element representing the type of literal in binding.
 
Element resolveIdToElement (QAnyStringView id, const Element &context)
 Returns the element in context that has id id.
 
QString resolveElementToId (const Element &element, const Element &context)
 Returns the id of element in a given context.
 
QString sourceCode (QQmlSA::SourceLocation location)
 Returns the source code located within location.
 

Detailed Description

\inmodule QtQmlCompiler

Base class for all static analysis passes on elements.

ElementPass is the simpler of the two analysis passes. It will consider every element in a file. The \l shouldRun() method can be used to filter out irrelevant elements, and the \l run() method is doing the initial work.

Common tasks suitable for an ElementPass are \list

  • checking that properties of an Element are not combined in a nonsensical way
  • validating property values (e.g. that a property takes only certain enum values)
  • checking behavior dependent on an Element's parent (e.g. not using \l {Item::width} when the parent element is a Layout). \endlist

As shown in the snippet below, it is recommended to do necessary type resolution in the constructor of the ElementPass and cache it in local members, and to implement some filtering via \l shouldRun() to keep the static analysis performant.

using namespace QQmlSA;
class MyElementPass : public ElementPass
{
Element myType;
public:
MyElementPass(QQmlSA::PassManager *manager)
: myType(resolveType("MyModule", "MyType")) {}
bool shouldRun(const Element &element) override
{
return element.inherits(myType);
}
void run(const Element &element) override
{
// actual pass logic
}
}
\inmodule QtQmlCompiler
Definition qqmlsa.h:357
\inmodule QtQmlCompiler
Definition qqmlsa.h:193
bool inherits(const Element &) const
Returns whether this Element inherits from element.
Definition qqmlsa.cpp:615
\inmodule QtQmlCompiler
Definition qqmlsa.h:303
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
\inmodule QtQmlCompiler
QNetworkAccessManager manager

ElementPasses have limited insight into how an element's properties are used. If you need that information, consider using a \l PropertyPass instead.

Note
ElementPass will only ever consider instantiable types. Therefore, it is unsuitable to analyze attached types and singletons. Those need to be handled via a PropertyPass.

Definition at line 356 of file qqmlsa.h.

Constructor & Destructor Documentation

◆ ElementPass()

QQmlSA::ElementPass::ElementPass ( PassManager * manager)
inline

Definition at line 359 of file qqmlsa.h.

Member Function Documentation

◆ run()

void QQmlSA::ElementPass::run ( const Element & element)
pure virtual

Executes if shouldRun() returns true.

Performs the real computation of the pass on element. This method is meant to be overridden. Calling the base method is not necessary.

Implemented in QQmlSA::DebugElementPass, ForbiddenChildrenPropertyValidatorPass, ControlsNativeValidatorPass, AnchorsValidatorPass, ControlsSwipeDelegateValidatorPass, and PropertyChangesValidatorPass.

◆ shouldRun()

bool QQmlSA::ElementPass::shouldRun ( const Element & element)
virtual

Controls whether the run() function should be executed on the given element.

Subclasses can override this method to improve performance of the analysis by filtering out elements which are not relevant.

The default implementation unconditionally returns true.

Reimplemented in ForbiddenChildrenPropertyValidatorPass, ControlsNativeValidatorPass, AnchorsValidatorPass, ControlsSwipeDelegateValidatorPass, and PropertyChangesValidatorPass.

Definition at line 1421 of file qqmlsa.cpp.

References void.


The documentation for this class was generated from the following files: