forked from qt-creator/qt-creator
CppEditor: Move two functions to cpptoolsreuse.{h,cpp}
They do not really depend on CppEditorWidget and will be re-used in a
follow-up change.
CppEditorWidget::identifierUnderCursor()
CppEditorWidget::findCanonicalMacro()
Change-Id: I553bb68694fb4b5f1baa331debf33ae234e3dedf
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
a87fa1e223
commit
fa4e839bbe
@@ -30,16 +30,16 @@
|
||||
#include "cpptoolsreuse.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <texteditor/convenience.h>
|
||||
|
||||
#include <cplusplus/Overview.h>
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QSet>
|
||||
#include <QTextDocument>
|
||||
#include <QTextCursor>
|
||||
#include <QStringRef>
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
@@ -200,4 +200,30 @@ void switchHeaderSource()
|
||||
Core::EditorManager::openEditor(otherFile);
|
||||
}
|
||||
|
||||
QString identifierUnderCursor(QTextCursor *cursor)
|
||||
{
|
||||
cursor->movePosition(QTextCursor::StartOfWord);
|
||||
cursor->movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||
return cursor->selectedText();
|
||||
}
|
||||
|
||||
const Macro *findCanonicalMacro(const QTextCursor &cursor, Document::Ptr document)
|
||||
{
|
||||
QTC_ASSERT(document, return 0);
|
||||
|
||||
int line, column;
|
||||
TextEditor::Convenience::convertPosition(cursor.document(), cursor.position(), &line, &column);
|
||||
|
||||
if (const Macro *macro = document->findMacroDefinitionAt(line)) {
|
||||
QTextCursor macroCursor = cursor;
|
||||
const QByteArray name = CppTools::identifierUnderCursor(¯oCursor).toUtf8();
|
||||
if (macro->name() == name)
|
||||
return macro;
|
||||
} else if (const Document::MacroUse *use = document->findMacroUseAt(cursor.position())) {
|
||||
return &use->macro();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // CppTools
|
||||
|
||||
@@ -32,11 +32,16 @@
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QChar)
|
||||
QT_FORWARD_DECLARE_CLASS(QTextCursor)
|
||||
QT_FORWARD_DECLARE_CLASS(QStringRef)
|
||||
#include <cplusplus/CppDocument.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QChar;
|
||||
class QStringRef;
|
||||
class QTextCursor;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace CPlusPlus {
|
||||
class Macro;
|
||||
class Symbol;
|
||||
class LookupContext;
|
||||
} // namespace CPlusPlus
|
||||
@@ -46,15 +51,20 @@ namespace CppTools {
|
||||
void CPPTOOLS_EXPORT moveCursorToEndOfIdentifier(QTextCursor *tc);
|
||||
void CPPTOOLS_EXPORT moveCursorToStartOfIdentifier(QTextCursor *tc);
|
||||
|
||||
bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol,
|
||||
const CPlusPlus::LookupContext &context);
|
||||
bool CPPTOOLS_EXPORT isQtKeyword(const QStringRef &text);
|
||||
|
||||
bool CPPTOOLS_EXPORT isValidAsciiIdentifierChar(const QChar &ch);
|
||||
bool CPPTOOLS_EXPORT isValidFirstIdentifierChar(const QChar &ch);
|
||||
bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch);
|
||||
bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s);
|
||||
|
||||
bool CPPTOOLS_EXPORT isQtKeyword(const QStringRef &text);
|
||||
QString CPPTOOLS_EXPORT identifierUnderCursor(QTextCursor *cursor);
|
||||
|
||||
bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol,
|
||||
const CPlusPlus::LookupContext &context);
|
||||
|
||||
const CPlusPlus::Macro CPPTOOLS_EXPORT *findCanonicalMacro(const QTextCursor &cursor,
|
||||
CPlusPlus::Document::Ptr document);
|
||||
|
||||
QString CPPTOOLS_EXPORT correspondingHeaderOrSource(const QString &fileName, bool *wasHeader = 0);
|
||||
void CPPTOOLS_EXPORT switchHeaderSource();
|
||||
|
||||
Reference in New Issue
Block a user