MCPcopy Create free account
hub / github.com/KDE/kdevelop / declareComponentSubclass

Method declareComponentSubclass

plugins/qmljs/duchain/declarationbuilder.cpp:791–876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

789}
790
791void DeclarationBuilder::declareComponentSubclass(QmlJS::AST::UiObjectInitializer* node,
792 const KDevelop::RangeInRevision& range,
793 const QString& baseclass,
794 QmlJS::AST::UiQualifiedId* qualifiedId)
795{
796 Identifier name(
797 QmlJS::getQMLAttributeValue(node->members, QStringLiteral("name")).value.section(QLatin1Char('/'), -1, -1)
798 );
799 DUContext::ContextType contextType = DUContext::Class;
800
801 if (baseclass == QLatin1String("Component")) {
802 // QML component, equivalent to a QML class
803 declareComponent(node, range, name);
804 } else if (baseclass == QLatin1String("Method") ||
805 baseclass == QLatin1String("Signal") ||
806 baseclass == QLatin1String("Slot")) {
807 // Method (that can also be a signal or a slot)
808 declareMethod(node, range, name, baseclass == QLatin1String("Slot"), baseclass == QLatin1String("Signal"));
809 contextType = DUContext::Function;
810 } else if (baseclass == QLatin1String("Property")) {
811 // A property
812 declareProperty(node, range, name);
813 } else if (baseclass == QLatin1String("Parameter") && currentType<QmlJS::FunctionType>()) {
814 // One parameter of a signal/slot/method
815 declareParameter(node, range, name);
816 } else if (baseclass == QLatin1String("Enum")) {
817 // Enumeration. The "values" key contains a dictionary of name -> number entries.
818 declareEnum(range, name);
819 contextType = DUContext::Enum;
820 name = Identifier(); // Enum contexts should have no name so that their members have the correct scope
821 } else {
822 // Define an anonymous subclass of the baseclass. This subclass will
823 // be instantiated when "id:" is encountered
824 name = Identifier();
825
826 // Use ExpressionVisitor to find the declaration of the base class
827 DeclarationPointer baseClass = findType(qualifiedId).declaration;
828 StructureType::Ptr type(new StructureType);
829
830 {
831 DUChainWriteLocker lock;
832 auto* decl = openDeclaration<ClassDeclaration>(
833 currentContext()->type() == DUContext::Global ?
834 Identifier(m_session->moduleName()) :
835 name,
836 QmlJS::emptyRangeOnLine(node->lbraceToken)
837 );
838
839 decl->clearBaseClasses();
840 decl->setKind(Declaration::Type);
841 decl->setType(type); // The class needs to know its type early because it contains definitions that depend on that type
842 type->setDeclaration(decl);
843
844 if (baseClass) {
845 addBaseClass(decl, baseClass->indexedType());
846 }
847 }
848 openType(type);

Callers

nothing calls this directly

Calls 15

getQMLAttributeValueFunction · 0.85
emptyRangeOnLineFunction · 0.85
currentDeclarationFunction · 0.85
sectionMethod · 0.80
clearBaseClassesMethod · 0.80
indexedTypeMethod · 0.80
locationsToInnerRangeMethod · 0.80
setInternalContextMethod · 0.80
IdentifierFunction · 0.50
QualifiedIdentifierClass · 0.50
typeMethod · 0.45

Tested by

no test coverage detected