Commit 03bd2c4a authored by Denis Steckelmacher's avatar Denis Steckelmacher

Subclass DUContext, NavigationWidget and DeclarationNavigationContext in order...

Subclass DUContext, NavigationWidget and DeclarationNavigationContext in order to display human-friendly QML component class names

In "Foo { id: foo }", foo is displayed as having type "Foo" (with a link to the
declaration of Foo in its module) instead of "<class>".
parent e186124e
...@@ -6,6 +6,10 @@ kde4_add_library(kdevqmljsduchain SHARED ...@@ -6,6 +6,10 @@ kde4_add_library(kdevqmljsduchain SHARED
declarationbuilder.cpp declarationbuilder.cpp
expressionvisitor.cpp expressionvisitor.cpp
usebuilder.cpp usebuilder.cpp
qmljsducontext.cpp
navigation/declarationnavigationcontext.cpp
navigation/navigationwidget.cpp
) )
target_link_libraries(kdevqmljsduchain LINK_PRIVATE target_link_libraries(kdevqmljsduchain LINK_PRIVATE
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "contextbuilder.h" #include "contextbuilder.h"
#include "expressionvisitor.h" #include "expressionvisitor.h"
#include "parsesession.h" #include "parsesession.h"
#include "qmljsducontext.h"
using namespace KDevelop; using namespace KDevelop;
...@@ -85,7 +86,13 @@ TopDUContext* ContextBuilder::newTopContext(const RangeInRevision& range, Parsin ...@@ -85,7 +86,13 @@ TopDUContext* ContextBuilder::newTopContext(const RangeInRevision& range, Parsin
/// identify environment files from this language plugin /// identify environment files from this language plugin
file->setLanguage(m_session->languageString()); file->setLanguage(m_session->languageString());
} }
return ContextBuilderBase::newTopContext(range, file);
return new QmlJS::QmlJSTopDUContext(m_session->url(), range, file);
}
DUContext* ContextBuilder::newContext(const RangeInRevision& range)
{
return new QmlJS::QmlJSNormalDUContext(range, currentContext());
} }
void ContextBuilder::setParseSession(ParseSession* session) void ContextBuilder::setParseSession(ParseSession* session)
......
...@@ -70,6 +70,7 @@ public: ...@@ -70,6 +70,7 @@ public:
virtual KDevelop::TopDUContext* newTopContext(const KDevelop::RangeInRevision& range, virtual KDevelop::TopDUContext* newTopContext(const KDevelop::RangeInRevision& range,
KDevelop::ParsingEnvironmentFile* file = 0); KDevelop::ParsingEnvironmentFile* file = 0);
virtual KDevelop::DUContext* newContext(const KDevelop::RangeInRevision& range);
ExpressionType findType(QmlJS::AST::Node* node); ExpressionType findType(QmlJS::AST::Node* node);
void setParseSession(ParseSession* session); void setParseSession(ParseSession* session);
......
/*
* This file is part of qmljs, the QML/JS language support plugin for KDevelop
* Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "declarationnavigationcontext.h"
#include <language/duchain/classdeclaration.h>
#include <language/duchain/types/structuretype.h>
using namespace KDevelop;
namespace QmlJS {
DeclarationNavigationContext::DeclarationNavigationContext(DeclarationPointer decl,
KDevelop::TopDUContextPointer topContext,
AbstractNavigationContext* previousContext)
: AbstractDeclarationNavigationContext(decl, topContext, previousContext)
{
}
void DeclarationNavigationContext::htmlIdentifiedType(AbstractType::Ptr type, const IdentifiedType* idType)
{
ClassDeclaration* classDecl;
Declaration* decl;
if ((decl = idType->declaration(m_topContext.data())) &&
(classDecl = dynamic_cast<ClassDeclaration*>(decl)) &&
classDecl->qualifiedIdentifier().isEmpty() &&
classDecl->baseClassesSize() > 0) {
// If a class declaration has no identifier, display the name of its base
// class instead of nothing
BaseClassInstance baseClass = classDecl->baseClasses()[0];
type = baseClass.baseClass.abstractType();
idType = TypePtr<StructureType>::dynamicCast(type).constData();
}
KDevelop::AbstractDeclarationNavigationContext::htmlIdentifiedType(type, idType);
}
}
/*
* This file is part of qmljs, the QML/JS language support plugin for KDevelop
* Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __DECLARATIONNAVIGATIONCONTEXT_H__
#define __DECLARATIONNAVIGATIONCONTEXT_H__
#include <language/duchain/navigation/abstractdeclarationnavigationcontext.h>
#include <language/duchain/types/identifiedtype.h>
namespace QmlJS {
class DeclarationNavigationContext : public KDevelop::AbstractDeclarationNavigationContext
{
public:
DeclarationNavigationContext(KDevelop::DeclarationPointer decl,
KDevelop::TopDUContextPointer topContext,
KDevelop::AbstractNavigationContext* previousContext = 0);
protected:
virtual void htmlIdentifiedType(KDevelop::AbstractType::Ptr type, const KDevelop::IdentifiedType* idType);
};
}
#endif
\ No newline at end of file
/*
* This file is part of qmljs, the QML/JS language support plugin for KDevelop
* Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "navigationwidget.h"
#include "declarationnavigationcontext.h"
#include <language/duchain/topducontext.h>
using namespace KDevelop;
namespace QmlJS {
NavigationWidget::NavigationWidget(KDevelop::Declaration* decl,
KDevelop::TopDUContext* topContext,
const QString& htmlPrefix,
const QString& htmlSuffix)
{
m_topContext = TopDUContextPointer(topContext);
m_startContext = NavigationContextPointer(new DeclarationNavigationContext(
DeclarationPointer(decl),
m_topContext,
nullptr
));
m_startContext->setPrefixSuffix(htmlPrefix, htmlSuffix);
setContext(m_startContext);
}
}
/*
* This file is part of qmljs, the QML/JS language support plugin for KDevelop
* Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __NAVIGATIONWIDGET_H__
#define __NAVIGATIONWIDGET_H__
#include <language/duchain/navigation/abstractnavigationwidget.h>
#include "../duchainexport.h"
namespace QmlJS {
class KDEVQMLJSDUCHAIN_EXPORT NavigationWidget : public KDevelop::AbstractNavigationWidget
{
public:
NavigationWidget(KDevelop::Declaration* decl,
KDevelop::TopDUContext* topContext,
const QString& htmlPrefix,
const QString& htmlSuffix);
};
}
#endif
\ No newline at end of file
/*
* This file is part of qmljs, the QML/JS language support plugin for KDevelop
* Copyright (c) 2013 Sven Brauch <svenbrauch@googlemail.com>
* Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "qmljsducontext.h"
#include <language/duchain/topducontext.h>
#include <language/duchain/topducontextdata.h>
#include <language/duchain/duchainregister.h>
#include <language/duchain/duchainpointer.h>
#include "navigation/navigationwidget.h"
using namespace KDevelop;
namespace QmlJS {
REGISTER_DUCHAIN_ITEM_WITH_DATA(QmlJSTopDUContext, TopDUContextData);
REGISTER_DUCHAIN_ITEM_WITH_DATA(QmlJSNormalDUContext, DUContextData);
template<>
QWidget* QmlJSTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, const QString& htmlPrefix, const QString& htmlSuffix) const {
if (!decl) {
kDebug() << "no declaration, not returning navigationwidget";
return 0;
}
return new NavigationWidget(decl, topContext, htmlPrefix, htmlSuffix);
}
template<>
QWidget* QmlJSNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, const QString& htmlPrefix, const QString& htmlSuffix) const {
if (!decl) {
kDebug() << "no declaration, not returning navigationwidget";
return 0;
}
return new NavigationWidget(decl, topContext, htmlPrefix, htmlSuffix);
}
}
/*
* This file is part of qmljs, the QML/JS language support plugin for KDevelop
* Copyright (c) 2013 Sven Brauch <svenbrauch@googlemail.com>
* Copyright (c) 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __QMLJSDUCONTEXT_H__
#define __QMLJSDUCONTEXT_H__
#include <language/duchain/ducontext.h>
class QWidget;
namespace KDevelop
{
class Declaration;
class TopDUContext;
}
namespace QmlJS
{
template<class BaseContext, int IdentityT>
class QmlJSDUContext : public BaseContext
{
public:
template<class Data>
QmlJSDUContext(Data& data) : BaseContext(data) {
}
///Parameters will be reached to the base-class
template<class Param1, class Param2>
QmlJSDUContext(const Param1& p1, const Param2& p2, bool isInstantiationContext) : BaseContext(p1, p2, isInstantiationContext) {
static_cast<KDevelop::DUChainBase*>(this)->d_func_dynamic()->setClassId(this);
}
///Both parameters will be reached to the base-class. This fits TopDUContext.
template<class Param1, class Param2, class Param3>
QmlJSDUContext(const Param1& p1, const Param2& p2, const Param3& p3) : BaseContext(p1, p2, p3) {
static_cast<KDevelop::DUChainBase*>(this)->d_func_dynamic()->setClassId(this);
}
template<class Param1, class Param2>
QmlJSDUContext(const Param1& p1, const Param2& p2) : BaseContext(p1, p2) {
static_cast<KDevelop::DUChainBase*>(this)->d_func_dynamic()->setClassId(this);
}
virtual QWidget* createNavigationWidget(KDevelop::Declaration* decl,
KDevelop::TopDUContext* topContext,
const QString& htmlPrefix,
const QString& htmlSuffix) const;
enum {
Identity = IdentityT
};
};
typedef QmlJSDUContext<KDevelop::TopDUContext, 110> QmlJSTopDUContext;
typedef QmlJSDUContext<KDevelop::DUContext, 111> QmlJSNormalDUContext;
}
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment