File indexing completed on 2024-05-19 04:42:01

0001 /*
0002     SPDX-FileCopyrightText: 2013 Sven Brauch <svenbrauch@googlemail.com>
0003     SPDX-FileCopyrightText: 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #include "qmljsducontext.h"
0009 #include "debug.h"
0010 
0011 #include <language/duchain/topducontext.h>
0012 #include <language/duchain/topducontextdata.h>
0013 #include <language/duchain/duchainregister.h>
0014 #include <language/duchain/duchainpointer.h>
0015 #include <language/util/includeitem.h>
0016 
0017 #include "navigation/navigationwidget.h"
0018 
0019 using namespace KDevelop;
0020 
0021 namespace QmlJS {
0022 
0023 template <>
0024 AbstractNavigationWidget* QmlJSTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext,
0025                                                                     AbstractNavigationWidget::DisplayHints hints) const
0026 {
0027     if (!decl) {
0028         const QUrl u = url().toUrl();
0029         IncludeItem item;
0030         item.pathNumber = -1;
0031         item.name = u.fileName();
0032         item.isDirectory = false;
0033         item.basePath = u.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash);
0034 
0035         return new NavigationWidget(item, TopDUContextPointer(topContext ? topContext : this->topContext()), hints);
0036     }
0037     return new NavigationWidget(decl, topContext, hints);
0038 }
0039 
0040 template <>
0041 AbstractNavigationWidget*
0042 QmlJSNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext,
0043                                              AbstractNavigationWidget::DisplayHints hints) const
0044 {
0045     if (!decl) {
0046         qCDebug(KDEV_QMLJS_DUCHAIN) << "no declaration, not returning navigationwidget";
0047         return nullptr;
0048     }
0049     return new NavigationWidget(decl, topContext, hints);
0050 }
0051 }
0052 
0053 DUCHAIN_DEFINE_TYPE_WITH_DATA(QmlJS::QmlJSNormalDUContext, DUContextData)
0054 DUCHAIN_DEFINE_TYPE_WITH_DATA(QmlJS::QmlJSTopDUContext, TopDUContextData)