File indexing completed on 2024-04-21 04:35:54
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_DUCHAIN_HELPERS_H 0020 #define RUBY_DUCHAIN_HELPERS_H 0021 0022 // KDevelop 0023 #include <language/duchain/declaration.h> 0024 0025 // Ruby 0026 #include <duchain/duchainexport.h> 0027 #include <parser/ast.h> 0028 0029 0030 namespace ruby { 0031 0032 class MethodDeclaration; 0033 class EditorIntegrator; 0034 0035 /** 0036 * The kind for the declaration to be fetched in the getDeclaration 0037 * and the getDeclarationFromPST methods. 0038 */ 0039 enum class DeclarationKind { 0040 Unknown = 0, /// We don't care about the declaration kind. 0041 ClassMethod = 1, /// It has to be a class method. 0042 InstanceMethod = 2, /// It has to be an instance method. 0043 Module = 3, /// It has to be a module. 0044 Class = 4, /// It has to be a class. 0045 Local = 5, /// Anything that is local (imported included). 0046 }; 0047 0048 /** 0049 * @returns the language string. 0050 */ 0051 KDEVRUBYDUCHAIN_EXPORT const KDevelop::IndexedString & languageString(); 0052 0053 /** 0054 * Get the url of the Ruby builtins file. 0055 * 0056 * @return A KDevelop::IndexedString that contains the url of the Ruby 0057 * builtins file. 0058 */ 0059 KDEVRUBYDUCHAIN_EXPORT const KDevelop::IndexedString & builtinsFile(); 0060 0061 /** 0062 * Given a Ast, return its name. 0063 * 0064 * @param ast The given Ast. 0065 * @return A QString containing the name of the given Ast. 0066 */ 0067 KDEVRUBYDUCHAIN_EXPORT const QString getName(Ast *ast); 0068 0069 /** 0070 * Given a Ast, return the documentation comment. 0071 * 0072 * @param ast The given Ast. 0073 * @return a QByteArray containing the documentation comment for a 0074 * class/module/method definition if it's available. It will return 0075 * an empty QByteArray otherwise, or if the AST does not represent 0076 * the situations described above. 0077 */ 0078 KDEVRUBYDUCHAIN_EXPORT const QByteArray getComment(Ast *ast); 0079 0080 /** 0081 * Find a specified declaration. 0082 * 0083 * @param id The qualified identifier of the declaration. 0084 * @param range The range of the declaration. 0085 * @param context The current context. 0086 * @param kind The kind of the declaration. 0087 * @note The given context has to be valid. 0088 * @note This method already acquires a read lock for the DUChain. 0089 */ 0090 KDEVRUBYDUCHAIN_EXPORT KDevelop::DeclarationPointer getDeclaration(const KDevelop::QualifiedIdentifier &id, 0091 const KDevelop::RangeInRevision &range, 0092 const KDevelop::DUContextPointer &context, 0093 DeclarationKind kind = DeclarationKind::Unknown); 0094 0095 /** 0096 * Get the required builtin type. 0097 * 0098 * @param desc The name of the builtin type. 0099 * @param ctx The context where this type is available. 0100 * @returns a TypePtr< AbstractType > containing the required type or null 0101 * if it was not found. 0102 * @note The given context has to be valid. 0103 * @note This method already acquires a read lock for the DUChain. 0104 */ 0105 KDEVRUBYDUCHAIN_EXPORT KDevelop::TypePtr<KDevelop::AbstractType> getBuiltinsType(const QString &desc, 0106 const KDevelop::DUContext *ctx); 0107 0108 /** 0109 * Get the context of the Class class. 0110 * 0111 * @param ctx The current context. 0112 * @returns a KDevelop::DUContext containing the Class class. 0113 * @note The given context has to be valid. 0114 * @note This method already acquires a read lock for the DUChain. 0115 */ 0116 KDEVRUBYDUCHAIN_EXPORT KDevelop::DUContext * getClassContext(const KDevelop::DUContext *ctx); 0117 0118 /** 0119 * @returns a new type which is a merge of the two given types @p type 0120 * and @p newType. 0121 */ 0122 KDEVRUBYDUCHAIN_EXPORT KDevelop::AbstractType::Ptr mergeTypes(KDevelop::AbstractType::Ptr type, 0123 KDevelop::AbstractType::Ptr newType); 0124 0125 /** 0126 * @returns the number of nodes that are next to the given @p node.o 0127 * @note Try to avoid this function since it iterates over all the list. 0128 */ 0129 KDEVRUBYDUCHAIN_EXPORT int nodeListSize(Node *node); 0130 0131 /// @returns the QualifiedIdentifier of the given @p ast. 0132 KDEVRUBYDUCHAIN_EXPORT const KDevelop::QualifiedIdentifier getIdentifier(const Ast *ast); 0133 0134 /** 0135 * @returns true if the given name belongs to a variable that has been 0136 * declared in the given DUContext. 0137 */ 0138 KDEVRUBYDUCHAIN_EXPORT bool declaredIn(const QByteArray &name, 0139 KDevelop::DUContextPointer context); 0140 } 0141 0142 #endif // RUBY_DUCHAIN_HELPERS_H