File indexing completed on 2024-05-12 04:39:11

0001 /*
0002     SPDX-FileCopyrightText: 2014 Kevin Funk <kfunk@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "clangducontext.h"
0008 
0009 #include "duchain/navigationwidget.h"
0010 #include "../util/clangdebug.h"
0011 
0012 #include <language/duchain/topducontextdata.h>
0013 #include <language/util/includeitem.h>
0014 
0015 using namespace KDevelop;
0016 
0017 template <>
0018 KDevelop::AbstractNavigationWidget*
0019 ClangTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext,
0020                                           KDevelop::AbstractNavigationWidget::DisplayHints hints) const
0021 {
0022     if (!decl) {
0023         const QUrl u = url().toUrl();
0024         IncludeItem item;
0025         item.pathNumber = -1;
0026         item.name = u.fileName();
0027         item.isDirectory = false;
0028         item.basePath = u.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash);
0029 
0030         return new ClangNavigationWidget(item, TopDUContextPointer(topContext ? topContext : this->topContext()), hints);
0031     }
0032     return new ClangNavigationWidget(DeclarationPointer(decl), hints);
0033 }
0034 
0035 template <>
0036 KDevelop::AbstractNavigationWidget*
0037 ClangNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* /*topContext*/,
0038                                              KDevelop::AbstractNavigationWidget::DisplayHints hints) const
0039 {
0040     if (!decl) {
0041         clangDebug() << "no declaration, not returning navigationwidget";
0042         return nullptr;
0043     }
0044     return new ClangNavigationWidget(DeclarationPointer(decl), hints);
0045 }
0046 
0047 DUCHAIN_DEFINE_TYPE_WITH_DATA(ClangNormalDUContext, DUContextData)
0048 DUCHAIN_DEFINE_TYPE_WITH_DATA(ClangTopDUContext, TopDUContextData)