File indexing completed on 2024-04-28 04:35:52

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 
0020 #ifndef DECLARATIONNAVIGATIONWIDGET_H
0021 #define DECLARATIONNAVIGATIONWIDGET_H
0022 
0023 
0024 #include <duchain/duchainexport.h>
0025 #include <language/duchain/navigation/abstractdeclarationnavigationcontext.h>
0026 
0027 
0028 namespace ruby {
0029 
0030 class ModuleDeclaration;
0031 
0032 /**
0033  * @class DeclarationNavigationContext
0034  *
0035  * This class extends KDevelop::AbstractDeclarationNavigationContext so we
0036  * can also show to the user some extra information.
0037  */
0038 class KDEVRUBYDUCHAIN_EXPORT DeclarationNavigationContext
0039     : public KDevelop::AbstractDeclarationNavigationContext
0040 {
0041 public:
0042     /**
0043      * Constructor.
0044      *
0045      * @param decl The declaration pointer.
0046      * @param topContext The top context where this declaration is.
0047      * @param prevContext A pointer to the previous context.
0048      */
0049     explicit DeclarationNavigationContext(KDevelop::DeclarationPointer decl,
0050                                           KDevelop::TopDUContextPointer topContext,
0051                                           KDevelop::AbstractNavigationContext *prevContext = nullptr);
0052 
0053 protected:
0054     /**
0055      * Re-implemented from KDevelop::AbstractDeclarationNavigationContext
0056      * because the default implementation is just to "C++ centric".
0057      */
0058     QString html(bool shorten = false) override;
0059 
0060     /**
0061      * Re-implemented from KDevelop::AbstractDeclarationNavigationContext
0062      * because the default implementation assumes that default arguments
0063      * are always at the end, and in Ruby this is not true.
0064      */
0065     void htmlFunction() override;
0066 
0067     /**
0068      * Re-implemented from KDevelop::AbstractDeclarationNavigationContext so
0069      * we can improve the html to be rendered with Ruby-specific stuff.
0070      */
0071     void htmlClass() override;
0072 
0073     /**
0074      * Re-implemented from KDevelop::AbstractNavigationContext so we can also
0075      * show to the user if he's looking at an internal (kernel) structure.
0076      *
0077      * @param name The given name.
0078      * @param declaration The involved declaration.
0079      * @param actionType Important if this is a JumpToSource action.
0080      */
0081     void makeLink(const QString &name,
0082                   const KDevelop::DeclarationPointer& declaration,
0083                   KDevelop::NavigationAction::Type actionType) override;
0084 
0085 private:
0086     /**
0087      * Add to the html all the info about module mixins that can be extracted
0088      * from the given declaration @p decl.
0089      */
0090     void addModuleMixins(ModuleDeclaration *decl);
0091 
0092     /**
0093      * Add to the html all the modules/classes that extend/include the
0094      * given module declaration @p decl.
0095      */
0096     void addMixers(ModuleDeclaration *decl);
0097 };
0098 
0099 }
0100 
0101 
0102 #endif /* DECLARATIONNAVIGATIONWIDGET_H */