diff --git a/duchain/navigation/declarationnavigationcontext.cpp b/duchain/navigation/declarationnavigationcontext.cpp index a3f453d..fdee187 100644 --- a/duchain/navigation/declarationnavigationcontext.cpp +++ b/duchain/navigation/declarationnavigationcontext.cpp @@ -1,178 +1,178 @@ /* Copyright 2007 David Nolden Copyright 2008 Niko Sams This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "declarationnavigationcontext.h" #include #include #include #include #include #include #include #include "../declarations/classdeclaration.h" #include #include #include #include "helper.h" namespace Php { using namespace KDevelop; DeclarationNavigationContext::DeclarationNavigationContext(DeclarationPointer decl, KDevelop::TopDUContextPointer topContext, AbstractNavigationContext* previousContext) : AbstractDeclarationNavigationContext(decl, topContext, previousContext) { } NavigationContextPointer DeclarationNavigationContext::registerChild(DeclarationPointer declaration) { - return AbstractDeclarationNavigationContext::registerChild(new DeclarationNavigationContext(declaration, m_topContext, this)); + return AbstractDeclarationNavigationContext::registerChild(new DeclarationNavigationContext(declaration, topContext(), this)); } void DeclarationNavigationContext::htmlClass() { - StructureType::Ptr klass = m_declaration->abstractType().cast(); + StructureType::Ptr klass = declaration()->abstractType().cast(); Q_ASSERT(klass); - ClassDeclaration* classDecl = dynamic_cast(klass->declaration(m_topContext.data())); + ClassDeclaration* classDecl = dynamic_cast(klass->declaration(topContext().data())); if (classDecl) { // write class modifier switch (classDecl->classModifier()) { case ClassDeclarationData::Abstract: modifyHtml() += QStringLiteral("abstract "); break; case ClassDeclarationData::Final: modifyHtml() += QStringLiteral("final "); break; default: //nothing break; } // write class type if (classDecl->classType() == ClassDeclarationData::Interface) { modifyHtml() += QStringLiteral("interface "); } else if (classDecl->classType() == ClassDeclarationData::Trait) { modifyHtml() += QStringLiteral("trait "); } else { modifyHtml() += QStringLiteral("class "); } // write class identifier - eventuallyMakeTypeLinks(m_declaration->abstractType()); + eventuallyMakeTypeLinks(declaration()->abstractType()); // write inheritance if (classDecl->baseClassesSize() > 0) { AbstractType::Ptr extends; QList implements; FOREACH_FUNCTION(const BaseClassInstance& base, classDecl->baseClasses) { StructureType::Ptr stype = base.baseClass.type(); if (stype) { - ClassDeclaration *classDecl = dynamic_cast(stype->declaration(m_topContext.data())); + ClassDeclaration *classDecl = dynamic_cast(stype->declaration(topContext().data())); if (classDecl) { if (classDecl->classType() == ClassDeclarationData::Interface) { implements.append(base.baseClass.abstractType()); } else { extends = base.baseClass.abstractType(); } } } } // write parent class if (extends) { modifyHtml() += QStringLiteral(" extends "); eventuallyMakeTypeLinks(extends); } // write implemented interfaces if (!implements.isEmpty()) { modifyHtml() += QStringLiteral(" implements "); for (QList::iterator i = implements.begin(); ;) { eventuallyMakeTypeLinks(*i); ++i; if (i != implements.end()) { modifyHtml() += QStringLiteral(", "); } else { break; } } } } modifyHtml() += QStringLiteral(" "); } } void DeclarationNavigationContext::htmlAdditionalNavigation() { - if (auto member = dynamic_cast(m_declaration.data())) { + if (auto member = dynamic_cast(declaration().data())) { Declaration *dec = member->aliasedDeclaration().data(); if (dec && dec->context() && dec->context()->owner()) { modifyHtml() += i18n("Use of %1 from %2
") .arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec)).toString(), QStringLiteral("jump_to_used"), NavigationAction(DeclarationPointer(dec), KDevelop::NavigationAction::NavigateDeclaration))) .arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec->context()->owner())).toString(), QStringLiteral("jump_to_used_container"), NavigationAction(DeclarationPointer(dec->context()->owner()), KDevelop::NavigationAction::NavigateDeclaration))); } - } else if (auto member = dynamic_cast(m_declaration.data())) { + } else if (auto member = dynamic_cast(declaration().data())) { Declaration *dec = member->aliasedDeclaration().data(); if (dec && dec->context() && dec->context()->owner()) { modifyHtml() += i18n("Use of %1 from %2
") .arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec)).toString(), QStringLiteral("jump_to_used"), NavigationAction(DeclarationPointer(dec), KDevelop::NavigationAction::NavigateDeclaration))) .arg(createLink(prettyQualifiedIdentifier(DeclarationPointer(dec->context()->owner())).toString(), QStringLiteral("jump_to_used_container"), NavigationAction(DeclarationPointer(dec->context()->owner()), KDevelop::NavigationAction::NavigateDeclaration))); } else { modifyHtml() += i18n("Broken member alias trait."); } } KDevelop::AbstractDeclarationNavigationContext::htmlAdditionalNavigation(); } QualifiedIdentifier DeclarationNavigationContext::prettyQualifiedIdentifier( DeclarationPointer decl ) const { return QualifiedIdentifier(prettyName(decl.data())); } void DeclarationNavigationContext::makeLink(const QString& name, DeclarationPointer declaration, NavigationAction::Type actionType) { if ( actionType == NavigationAction::JumpToSource && declaration->url() == internalFunctionFile() ) { modifyHtml() += i18n("PHP internal"); return; } AbstractDeclarationNavigationContext::makeLink(name, declaration, actionType); } QString DeclarationNavigationContext::declarationKind(DeclarationPointer decl) { if ( decl->kind() == Declaration::Instance && decl->abstractType() && decl->abstractType()->modifiers() & AbstractType::ConstModifier ) { return i18nc("kind of a php-constant, as shown in the declaration tooltip", "Constant"); } return AbstractDeclarationNavigationContext::declarationKind(decl); } } diff --git a/duchain/navigation/magicconstantnavigationcontext.cpp b/duchain/navigation/magicconstantnavigationcontext.cpp index aa665bd..4489e26 100644 --- a/duchain/navigation/magicconstantnavigationcontext.cpp +++ b/duchain/navigation/magicconstantnavigationcontext.cpp @@ -1,124 +1,124 @@ /* Copyright 2009 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "magicconstantnavigationcontext.h" #include #include #include #include #include using namespace KDevelop; namespace Php { MagicConstantNavigationContext::MagicConstantNavigationContext(TopDUContextPointer topContext, const KTextEditor::Cursor& position, const QString& constant) : AbstractNavigationContext(topContext, nullptr), m_position(position.line(), position.column()), m_constant(constant) { } QString MagicConstantNavigationContext::name() const { return m_constant; } DUContext* findContext(TopDUContextPointer topCtx, const CursorInRevision& pos, DUContext::ContextType type) { DUContext* ctx = topCtx->findContextAt(pos); while ( ctx && ctx->type() != type ) { ctx = ctx->parentContext(); } if ( !ctx || ctx->type() != type ) { return nullptr; } else { return ctx; } } QString MagicConstantNavigationContext::html(bool /*shorten*/) { QString html = QStringLiteral("

"); html += typeHighlight(i18n("magic constant")); html += ' '; html += nameHighlight(m_constant.toHtmlEscaped()); html += QLatin1String("
\n"); QString value; ///TODO: php 5.3: __DIR__, __NAMESPACE__ if ( m_constant == QLatin1String("__FILE__") ) { - value = m_topContext->url().str().toHtmlEscaped(); + value = topContext()->url().str().toHtmlEscaped(); } else if ( m_constant == QLatin1String("__LINE__") ) { value.setNum(m_position.line + 1); } else if ( m_constant == QLatin1String("__CLASS__") ) { - if ( DUContext* ctx = findContext(m_topContext, m_position, DUContext::Class) ) { + if ( DUContext* ctx = findContext(topContext(), m_position, DUContext::Class) ) { value = codeHighlight(ctx->localScopeIdentifier().toString().toHtmlEscaped()); } else { value = commentHighlight(i18n("empty (not inside a class)")); } } else if ( m_constant == QLatin1String("__METHOD__") ) { CursorInRevision pos = m_position; - while ( DUContext* ctx = findContext(m_topContext, pos, DUContext::Other) ) { + while ( DUContext* ctx = findContext(topContext(), pos, DUContext::Other) ) { if ( !ctx->parentContext() ) { break; } if ( ctx->parentContext()->type() == DUContext::Class ) { value = codeHighlight(QString( ctx->parentContext()->localScopeIdentifier().toString() + "::" + ctx->localScopeIdentifier().toString() ).toHtmlEscaped()); break; } // might be a "normal" function inside a method... pos = ctx->range().start; } if ( value.isEmpty() ) { value = commentHighlight(i18n("empty (not inside a method)")); } } else if ( m_constant == QLatin1String("__FUNCTION__") ) { CursorInRevision pos = m_position; - if ( DUContext* ctx = findContext(m_topContext, pos, DUContext::Other) ) { + if ( DUContext* ctx = findContext(topContext(), pos, DUContext::Other) ) { if ( ctx->owner() && ctx->owner()->type() ) { value = codeHighlight(ctx->localScopeIdentifier().toString().toHtmlEscaped()); } } if ( value.isEmpty() ) { value = commentHighlight(i18n("empty (not inside a function)")); } } else if ( m_constant == QLatin1String("__NAMESPACE__") ) { - if ( DUContext* ctx = findContext(m_topContext, m_position, DUContext::Namespace) ) { + if ( DUContext* ctx = findContext(topContext(), m_position, DUContext::Namespace) ) { if ( ctx->owner() && ctx->owner()->kind() == Declaration::Namespace ) { value = codeHighlight(ctx->localScopeIdentifier().toString().toHtmlEscaped()); } } if ( value.isEmpty() ) { value = commentHighlight(i18n("empty (not inside a namespace)")); } } html += i18n("current value: %1", value); html += QLatin1String("

"); return html; } } diff --git a/duchain/navigation/navigationwidget.cpp b/duchain/navigation/navigationwidget.cpp index 600d0f2..9c80e4e 100644 --- a/duchain/navigation/navigationwidget.cpp +++ b/duchain/navigation/navigationwidget.cpp @@ -1,87 +1,83 @@ /* Copyright 2007 David Nolden Copyright 2008 Niko Sams This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "navigationwidget.h" #include "declarationnavigationcontext.h" #include "includenavigationcontext.h" #include "magicconstantnavigationcontext.h" namespace Php { using namespace KDevelop; NavigationWidget::NavigationWidget(KDevelop::DeclarationPointer declaration, KDevelop::TopDUContextPointer topContext, const QString& htmlPrefix, const QString& htmlSuffix, KDevelop::AbstractNavigationWidget::DisplayHints hints) : AbstractNavigationWidget() - , m_declaration(declaration) { - m_topContext = topContext; setDisplayHints(hints); initBrowser(400); //The first context is registered so it is kept alive by the shared-pointer mechanism - m_startContext = NavigationContextPointer(new DeclarationNavigationContext(declaration, m_topContext)); - m_startContext->setPrefixSuffix(htmlPrefix, htmlSuffix); - setContext(m_startContext); + auto context = NavigationContextPointer(new DeclarationNavigationContext(declaration, topContext)); + context->setPrefixSuffix(htmlPrefix, htmlSuffix); + setContext(context); } NavigationWidget::NavigationWidget(const IncludeItem& includeItem, KDevelop::TopDUContextPointer topContext, const QString& htmlPrefix, const QString& htmlSuffix, KDevelop::AbstractNavigationWidget::DisplayHints hints) : AbstractNavigationWidget() { - m_topContext = topContext; setDisplayHints(hints); initBrowser(200); //The first context is registered so it is kept alive by the shared-pointer mechanism - m_startContext = NavigationContextPointer(new IncludeNavigationContext(includeItem, m_topContext)); - m_startContext->setPrefixSuffix( htmlPrefix, htmlSuffix ); - setContext( m_startContext ); + auto context = NavigationContextPointer(new IncludeNavigationContext(includeItem, topContext)); + context->setPrefixSuffix(htmlPrefix, htmlSuffix); + setContext(context); } NavigationWidget::NavigationWidget(TopDUContextPointer topContext, KTextEditor::Cursor position, const QString& constant, KDevelop::AbstractNavigationWidget::DisplayHints hints) : AbstractNavigationWidget() { - m_topContext = topContext; setDisplayHints(hints); initBrowser(200); //The first context is registered so it is kept alive by the shared-pointer mechanism - m_startContext = NavigationContextPointer(new MagicConstantNavigationContext(topContext, position, constant)); - setContext( m_startContext ); + auto context = NavigationContextPointer(new MagicConstantNavigationContext(topContext, position, constant)); + setContext(context); } QString NavigationWidget::shortDescription(KDevelop::Declaration* declaration) { NavigationContextPointer ctx(new DeclarationNavigationContext(DeclarationPointer(declaration), TopDUContextPointer())); ///@todo give correct top-context return ctx->html(true); } QString NavigationWidget::shortDescription(const IncludeItem& includeItem) { NavigationContextPointer ctx(new IncludeNavigationContext(includeItem, TopDUContextPointer())); ///@todo give correct top-context return ctx->html(true); } }