forked from qt-creator/qt-creator
Clang: Use LineColumn instead of explicit integers for line and column
With OptionalLineColumn we don't need any bool return parameter any more. Change-Id: I6f57f221c1bfdf08a92a87a7d71ea0eecf83dbcf Reviewed-by: Tobias Hunger <tobias.hunger@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "optional.h"
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
class LineColumn
|
class LineColumn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -34,11 +38,10 @@ public:
|
|||||||
column(column)
|
column(column)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool isValid() const
|
|
||||||
{
|
|
||||||
return line >= 0 && column >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int line = -1;
|
int line = -1;
|
||||||
int column = -1;
|
int column = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using OptionalLineColumn = optional<LineColumn>;
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
|||||||
@@ -46,6 +46,18 @@ bool convertPosition(const QTextDocument *document, int pos, int *line, int *col
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::OptionalLineColumn convertPosition(const QTextDocument *document, int pos)
|
||||||
|
{
|
||||||
|
Utils::OptionalLineColumn optional;
|
||||||
|
|
||||||
|
QTextBlock block = document->findBlock(pos);
|
||||||
|
|
||||||
|
if (block.isValid())
|
||||||
|
optional.emplace(block.blockNumber() + 1, pos - block.position());
|
||||||
|
|
||||||
|
return optional;
|
||||||
|
}
|
||||||
|
|
||||||
QString textAt(QTextCursor tc, int pos, int length)
|
QString textAt(QTextCursor tc, int pos, int length)
|
||||||
{
|
{
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "linecolumn.h"
|
||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -39,6 +40,8 @@ namespace Text {
|
|||||||
QTCREATOR_UTILS_EXPORT bool convertPosition(const QTextDocument *document,
|
QTCREATOR_UTILS_EXPORT bool convertPosition(const QTextDocument *document,
|
||||||
int pos,
|
int pos,
|
||||||
int *line, int *column);
|
int *line, int *column);
|
||||||
|
QTCREATOR_UTILS_EXPORT
|
||||||
|
Utils::OptionalLineColumn convertPosition(const QTextDocument *document, int pos);
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT QString textAt(QTextCursor tc, int pos, int length);
|
QTCREATOR_UTILS_EXPORT QString textAt(QTextCursor tc, int pos, int length);
|
||||||
|
|
||||||
|
|||||||
@@ -94,13 +94,20 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
|||||||
|
|
||||||
CppTools::Usages RefactoringEngine::locationsAt(const CppTools::CursorInEditor &data) const
|
CppTools::Usages RefactoringEngine::locationsAt(const CppTools::CursorInEditor &data) const
|
||||||
{
|
{
|
||||||
int line = 0, column = 0;
|
CppTools::Usages usages;
|
||||||
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
|
||||||
Utils::Text::convertPosition(cursor.document(), cursor.position(), &line, &column);
|
|
||||||
|
|
||||||
|
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||||
|
Utils::OptionalLineColumn lineColumn = Utils::Text::convertPosition(cursor.document(),
|
||||||
|
cursor.position());
|
||||||
|
|
||||||
|
if (lineColumn) {
|
||||||
const QByteArray filePath = data.filePath().toString().toUtf8();
|
const QByteArray filePath = data.filePath().toString().toUtf8();
|
||||||
const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(ClangBackEnd::FilePathView(filePath));
|
const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(ClangBackEnd::FilePathView(filePath));
|
||||||
return m_symbolQuery.sourceUsagesAt(filePathId, line, column + 1);
|
|
||||||
|
usages = m_symbolQuery.sourceUsagesAt(filePathId, lineColumn->line, lineColumn->column + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return usages;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefactoringEngine::globalRename(const CppTools::CursorInEditor &data,
|
void RefactoringEngine::globalRename(const CppTools::CursorInEditor &data,
|
||||||
|
|||||||
Reference in New Issue
Block a user