File indexing completed on 2024-04-14 04:31:10
0001 /* This file is part of KDevelop 0002 * 0003 * Copyright (C) 2011-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef RUBY_USE_BUILDER_H 0020 #define RUBY_USE_BUILDER_H 0021 0022 #include <language/duchain/builders/abstractusebuilder.h> 0023 0024 #include <duchain/builders/contextbuilder.h> 0025 #include <duchain/duchainexport.h> 0026 0027 namespace ruby { 0028 0029 using UseBuilderBase = 0030 KDevelop::AbstractUseBuilder<Ast, NameAst, ContextBuilder>; 0031 0032 /** 0033 * @class UseBuilder 0034 * 0035 * A class which iterates the AST to extract uses of definitions. 0036 */ 0037 class KDEVRUBYDUCHAIN_EXPORT UseBuilder : public UseBuilderBase 0038 { 0039 public: 0040 explicit UseBuilder(EditorIntegrator *editor); 0041 0042 protected: 0043 /// Methods re-implemented from AstVisitor. 0044 0045 bool declaredInContext(const QByteArray &name) const override; 0046 0047 void visitName(Ast *node) override; 0048 void visitClassName(Ast *node) override; 0049 void visitMixin(Ast *node, bool include) override; 0050 void visitMethodCall(Ast *node) override; 0051 void visitRequire(Ast *node, bool relative = false) override; 0052 0053 private: 0054 /// @internal Visit the method call members from the given @p node. 0055 void visitMethodCallMembers(Ast *node); 0056 0057 private: 0058 /// Used at the method call visitor to keep track of the last context. 0059 KDevelop::DUContext *m_lastCtx; 0060 0061 /** 0062 * The method call visitor uses this to track the depth of 0063 * the recursion level. 0064 */ 0065 int m_depth; 0066 0067 /** 0068 * Used in the method call to tell if the previous recursion level 0069 * consisted of a class/module. 0070 */ 0071 bool m_classMethod; 0072 }; 0073 0074 } 0075 0076 #endif // RUBY_USE_BUILDER_H