File indexing completed on 2024-05-05 16:41:08

0001 /*
0002     SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef USEBUILDER_H
0008 #define USEBUILDER_H
0009 
0010 #include <language/duchain/builders/abstractusebuilder.h>
0011 
0012 #include "helper.h"
0013 #include "contextbuilder.h"
0014 #include "phpduchainexport.h"
0015 
0016 namespace Php
0017 {
0018 
0019 class ParseSession;
0020 
0021 typedef KDevelop::AbstractUseBuilder<AstNode, IdentifierAst, ContextBuilder> UseBuilderBase;
0022 
0023 /**
0024  * A class which iterates the AST to extract uses of definitions.
0025  */
0026 class KDEVPHPDUCHAIN_EXPORT UseBuilder: public UseBuilderBase
0027 {
0028 public:
0029     UseBuilder(EditorIntegrator* editor);
0030 
0031     /**
0032      * Reports a problem if the use'd declaration is deprecated.
0033      * Also reports an error if @p reportNotFound is true and @p declaration is null.
0034      */
0035     void newCheckedUse(Php::AstNode* node, const KDevelop::DeclarationPointer& declaration, bool reportNotFound = false);
0036 
0037     KDevelop::ReferencedTopDUContext build(const KDevelop::IndexedString& url, AstNode* node,
0038         const KDevelop::ReferencedTopDUContext& updateContext
0039         = KDevelop::ReferencedTopDUContext()) override;
0040 
0041 protected:
0042     void visitParameter(ParameterAst *node) override;
0043     void visitClassImplements(ClassImplementsAst *node) override;
0044     void visitClassExtends(ClassExtendsAst *node) override;
0045     void visitClassStatement(ClassStatementAst *node) override;
0046     void visitTraitAliasStatement(TraitAliasStatementAst *node) override;
0047     void visitTraitAliasIdentifier(TraitAliasIdentifierAst *node) override;
0048     void visitExpr(ExprAst* node) override;
0049     void visitGlobalVar(GlobalVarAst* node) override;
0050     void visitStaticScalar(StaticScalarAst* node) override;
0051     void visitStatement(StatementAst* node) override;
0052     void visitCatchItem(CatchItemAst* node) override;
0053     void visitUnaryExpression( UnaryExpressionAst* node ) override;
0054     void visitUseNamespaceOrUseGroupedNamespace(UseNamespaceOrUseGroupedNamespaceAst* node) override;
0055     void visitInnerUseNamespace(InnerUseNamespaceAst* node) override;
0056     void openNamespace(NamespaceDeclarationStatementAst* parent, IdentifierAst* node, const IdentifierPair& identifier, const KDevelop::RangeInRevision& range) override;
0057     void visitGenericTypeHint(GenericTypeHintAst* node) override;
0058 
0059 private:
0060     void buildNamespaceUses(
0061         Php::NamespacedIdentifierAst* node,
0062         Php::DeclarationType lastType = Php::ClassDeclarationType);
0063     void buildNamespaceUses(
0064         Php::NamespacedIdentifierBeforeGroupedNamespaceAst* node,
0065         Php::UseImportType useImportType);
0066     void buildNamespaceUses(
0067         KDevelop::QualifiedIdentifier identifier,
0068         const KDevPG::ListNode<IdentifierAst *>* prefixNamespaceNameSequence,
0069         const KDevPG::ListNode<IdentifierAst *>* namespaceNameSequence,
0070         Php::DeclarationType lastType);
0071 
0072     void visitNodeWithExprVisitor(AstNode* node);
0073 
0074     /// Prefix in front of grouped namespace
0075     NamespacedIdentifierBeforeGroupedNamespaceAst *m_compoundNamespacePrefix;
0076 };
0077 
0078 }
0079 
0080 #endif // USEBUILDER_H
0081