diff --git a/language/interfaces/codecontext.cpp b/language/interfaces/codecontext.cpp index 2693ad02d..bb45064d8 100644 --- a/language/interfaces/codecontext.cpp +++ b/language/interfaces/codecontext.cpp @@ -1,143 +1,142 @@ /* This file is part of KDevelop Copyright 2001-2002 Matthias Hoelzer-Kluepfel Copyright 2001-2002 Bernd Gehrmann Copyright 2001 Sandy Meier Copyright 2002 Daniel Engelschalt Copyright 2002 Simon Hausmann Copyright 2002-2003 Roberto Raggi Copyright 2003 Mario Scalas Copyright 2003 Harald Fernengel Copyright 2003,2006,2008 Hamish Rodda Copyright 2004 Alexander Dymo Copyright 2006 Adam Treat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 "codecontext.h" #include #include #include #include #include #include #include #include namespace KDevelop { class DUContextContext::Private { public: Private( const IndexedDUContext& item ) : m_item( item ) {} IndexedDUContext m_item; }; DUContextContext::DUContextContext( const IndexedDUContext& item ) : Context(), d( new Private( item ) ) {} DUContextContext::~DUContextContext() { delete d; } int DUContextContext::type() const { return Context::CodeContext; } QList DUContextContext::urls() const { DUChainReadLocker lock; if (auto context = d->m_item.context()) { return {context->url().toUrl()}; } return {}; } IndexedDUContext DUContextContext::context() const { return d->m_item; } void DUContextContext::setContext(IndexedDUContext context) { d->m_item = context; } class DeclarationContext::Private { public: Private( const IndexedDeclaration& declaration, const DocumentRange& use ) : m_declaration( declaration ), m_use(use) {} IndexedDeclaration m_declaration; DocumentRange m_use; }; DeclarationContext::DeclarationContext( const IndexedDeclaration& declaration, const DocumentRange& use, const IndexedDUContext& context ) : DUContextContext(context), d( new Private( declaration, use ) ) {} -DeclarationContext::DeclarationContext(KTextEditor::View* view, KTextEditor::Cursor position) : DUContextContext(IndexedDUContext()) +DeclarationContext::DeclarationContext(KTextEditor::View* view, const KTextEditor::Cursor& position) : DUContextContext(IndexedDUContext()) { const QUrl& url = view->document()->url(); - const KTextEditor::Cursor pos = KTextEditor::Cursor(position); DUChainReadLocker lock; - DocumentRange useRange = DocumentRange(IndexedString(url), DUChainUtils::itemRangeUnderCursor(url, pos)); - Declaration* declaration = DUChainUtils::itemUnderCursor(url, pos); + DocumentRange useRange = DocumentRange(IndexedString(url), DUChainUtils::itemRangeUnderCursor(url, position)); + Declaration* declaration = DUChainUtils::itemUnderCursor(url, position); IndexedDeclaration indexed; if ( declaration ) { indexed = IndexedDeclaration(declaration); } IndexedDUContext context; TopDUContext* topContext = DUChainUtils::standardContextForUrl(view->document()->url()); if(topContext) { - DUContext* specific = topContext->findContextAt(CursorInRevision(pos.line(), pos.column())); + DUContext* specific = topContext->findContextAt(CursorInRevision(position.line(), position.column())); if(specific) context = IndexedDUContext(specific); } d = new Private(declaration, useRange); setContext(context); } DeclarationContext::~DeclarationContext() { delete d; } int DeclarationContext::type() const { return Context::CodeContext; } IndexedDeclaration DeclarationContext::declaration() const { return d->m_declaration; } DocumentRange DeclarationContext::use() const { return d->m_use; } } diff --git a/language/interfaces/codecontext.h b/language/interfaces/codecontext.h index 1279b523e..91776dbe8 100644 --- a/language/interfaces/codecontext.h +++ b/language/interfaces/codecontext.h @@ -1,114 +1,114 @@ /* This file is part of KDevelop Copyright 2001-2002 Matthias Hoelzer-Kluepfel Copyright 2001-2002 Bernd Gehrmann Copyright 2001 Sandy Meier Copyright 2002 Daniel Engelschalt Copyright 2002 Simon Hausmann Copyright 2002-2003 Roberto Raggi Copyright 2003 Mario Scalas Copyright 2003 Harald Fernengel Copyright 2003,2006-2007 Hamish Rodda Copyright 2004 Alexander Dymo Copyright 2006 Adam Treat Copyright 2007 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. */ #ifndef KDEVPLATFORM_CODECONTEXT_H #define KDEVPLATFORM_CODECONTEXT_H #include #include #include #include namespace KTextEditor { class View; } namespace KDevelop { class IndexedDeclaration; class IndexedDUContext; /** * A context that represents DUContexts. Before using this, first try casting to DeclarationContext, and use that if possible. */ class KDEVPLATFORMLANGUAGE_EXPORT DUContextContext : public Context { public: explicit DUContextContext(const IndexedDUContext& context); virtual ~DUContextContext(); ///Returns the represented DUContext IndexedDUContext context() const; int type() const override; virtual QList urls() const override; protected: void setContext(IndexedDUContext context); private: class Private; Private *d; Q_DISABLE_COPY(DUContextContext) }; /** A context for definition-use chain objects. */ class KDEVPLATFORMLANGUAGE_EXPORT DeclarationContext: public DUContextContext { public: /**Builds the context. * @param declaration The represented declaration. * @param use If this context represents the use of a declaration, this should contain the exact use range. * @param context If this represents a use, then this should be the context * surrounding the use. Else it should be the context surrounding the declaration. */ explicit DeclarationContext(const IndexedDeclaration& declaration, const DocumentRange& use = DocumentRange::invalid(), const IndexedDUContext& context = IndexedDUContext()); ///Computes the items under the cursor - DeclarationContext(KTextEditor::View* view, KTextEditor::Cursor position); + DeclarationContext(KTextEditor::View* view, const KTextEditor::Cursor& position); /**Destructor.*/ virtual ~DeclarationContext(); /// Returns the type of this context. virtual int type() const override; ///The referenced declaration IndexedDeclaration declaration() const; ///If this code-context represents the use of a declaration, then this contains the exact position+range ///of that use. declaration() returnes the used declaration, and context() the context ///that surrounds the use. DocumentRange use() const; private: class Private; Private *d; Q_DISABLE_COPY(DeclarationContext) }; } #endif diff --git a/language/interfaces/editorcontext.cpp b/language/interfaces/editorcontext.cpp index c72acaf4a..819c019bf 100644 --- a/language/interfaces/editorcontext.cpp +++ b/language/interfaces/editorcontext.cpp @@ -1,91 +1,91 @@ /* This file is part of KDevelop Copyright 2006 Adam Treat Copyright 2007 Andreas Pakulat Copyright 2008 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 "editorcontext.h" #include #include #include namespace KDevelop { class EditorContextPrivate { public: - EditorContextPrivate( KTextEditor::View* view, KTextEditor::Cursor position ) - : m_view( view ) + EditorContextPrivate( KTextEditor::View* view, const KTextEditor::Cursor& position ) + : m_view( view ) { m_url = view->document()->url(); m_position = position; m_currentLine = view->document()->line(m_position.line()); int wordStart = m_position.column(); int wordEnd = m_position.column(); while(wordStart > 0 && wordStart < m_currentLine.length() && (m_currentLine[wordStart-1].isLetterOrNumber() || m_currentLine[wordStart-1] == '_')) --wordStart; while(wordEnd >= 0 && wordEnd < m_currentLine.length() && (m_currentLine[wordEnd].isLetterOrNumber() || m_currentLine[wordEnd] == '_')) ++wordEnd; } QUrl m_url; KTextEditor::Cursor m_position; QString m_currentLine, m_currentWord; KTextEditor::View* m_view; }; -EditorContext::EditorContext( KTextEditor::View* view, KTextEditor::Cursor position ) +EditorContext::EditorContext( KTextEditor::View* view, const KTextEditor::Cursor& position ) : DeclarationContext( view, position ), d( new EditorContextPrivate( view, position ) ) {} EditorContext::~EditorContext() { delete d; } int EditorContext::type() const { return Context::EditorContext; } QUrl EditorContext::url() const { return d->m_url; } KTextEditor::Cursor EditorContext::position() const { return d->m_position; } QString EditorContext::currentLine() const { return d->m_currentLine; } QString EditorContext::currentWord() const { return d->m_currentWord; } KTextEditor::View* EditorContext::view() const { return d->m_view; } } diff --git a/language/interfaces/editorcontext.h b/language/interfaces/editorcontext.h index c4a7e32f2..91c4bfb62 100644 --- a/language/interfaces/editorcontext.h +++ b/language/interfaces/editorcontext.h @@ -1,78 +1,81 @@ /* This file is part of KDevelop Copyright 2006 Adam Treat Copyright 2007 Andreas Pakulat Copyright 2008 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. */ #ifndef KDEVPLATFORM_EDITORCONTEXT_H #define KDEVPLATFORM_EDITORCONTEXT_H #include "codecontext.h" namespace KTextEditor { class View; class Cursor; } class QUrl; namespace KDevelop { /**A context for the KTextEditor.*/ class KDEVPLATFORMLANGUAGE_EXPORT EditorContext: public DeclarationContext { public: - /**Builds a context for a KTextEditor part. - @param url The url of a file in the editor. - @param position The position where the cursor is. - @param linestr The content of the line where the cursor is. - @param wordstr The current word under the cursor.*/ - EditorContext( KTextEditor::View*, KTextEditor::Cursor position ); + /** + * Builds a context for a KTextEditor part. + * @param view The view for the editor context. + * @param position The cursor position. + */ + EditorContext( KTextEditor::View* view, const KTextEditor::Cursor& position ); /**Destructor.*/ virtual ~EditorContext(); virtual int type() const override; /**@return The url for the file which this context was invoked for.*/ QUrl url() const; /**@return The cursor position.*/ KTextEditor::Cursor position() const; /**@return A QString with the content of the line which this context was invoked for.*/ QString currentLine() const; /**@return A QString containing the word near to the cursor when this context object was created.*/ QString currentWord() const; + /** + * Returns the associated view. + */ KTextEditor::View* view() const; private: class EditorContextPrivate* const d; EditorContext( const EditorContext & ); EditorContext &operator=( const EditorContext & ); }; } #endif